@Override public void render() { camera.update(); // Step the physics simulation forward at a rate of 60hz world.step(1f / 60f, 6, 2); sprite.setPosition( (body.getPosition().x * PIXELS_TO_METERS) - sprite.getWidth() / 2, (body.getPosition().y * PIXELS_TO_METERS) - sprite.getHeight() / 2); sprite.setRotation((float) Math.toDegrees(body2.getAngle())); sprite2.setPosition( (body2.getPosition().x * PIXELS_TO_METERS) - sprite2.getWidth() / 2, (body2.getPosition().y * PIXELS_TO_METERS) - sprite2.getHeight() / 2); sprite2.setRotation((float) Math.toDegrees(body.getAngle())); Gdx.gl.glClearColor(1, 1, 1, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.setProjectionMatrix(camera.combined); batch.begin(); batch.draw( sprite, sprite.getX(), sprite.getY(), sprite.getOriginX(), sprite.getOriginY(), sprite.getWidth(), sprite.getHeight(), sprite.getScaleX(), sprite.getScaleY(), sprite.getRotation()); batch.draw( sprite2, sprite2.getX(), sprite2.getY(), sprite2.getOriginX(), sprite2.getOriginY(), sprite2.getWidth(), sprite2.getHeight(), sprite2.getScaleX(), sprite2.getScaleY(), sprite2.getRotation()); batch.end(); }
@Override public void onGraphicRender(GdxGraphics g) { /* Update the world physics */ PhysicsWorld.updatePhysics(); /* Sync signal emulation using system time */ boolean sync_signal = new TimeFloat().second % 60.0 == 0.0; /* * Second hand logic * * Stop when vertical, start when sync_sygnal */ if (sync_signal) { motor_seconds.setMotorSpeed(MOTOR_SPEED_SECOND); } else { double angle = -hand_second.getBody().getAngle() % (2 * Math.PI); if (angle > 2 * Math.PI * 0.995 && motor_seconds.getSpeed() != 0.0) { motor_seconds.setMotorSpeed(0.0f); } } /* * Minute hand logic * * Move from 1 minute when sync_signal */ if (sync_signal) { motor_minutes.setMotorSpeed(MOTOR_SPEED_MINUTE); } else { motor_minutes.setMotorSpeed(0.0f); } /* Get the size of the window */ final int w = getWindowWidth(); final int h = getWindowHeight(); /* Clear the graphic to draw the new image */ g.clear(); if (debug_rendering) { debugRenderer.render(world, g.getCamera().combined); g.setColor(Color.WHITE); } else { /* Create a nice grey gradient for the background */ for (int i = 0; i <= h; i++) { float c = 255 - i * 0.3f; g.setColor(new Color(c / 255, c / 255, c / 255, 1.0f)); g.drawLine(0, h - i, w, h - i); } /* Draw the clock frame */ g.drawPicture(CLOCK_CENTER.x, CLOCK_CENTER.y, bitmapClock); /* Draw the hands */ g.drawTransformedPicture( CLOCK_CENTER.x, CLOCK_CENTER.y, (float) (Math.toDegrees(hand_hour.getBody().getAngle())), 1.0f, bitmapHour); g.drawTransformedPicture( CLOCK_CENTER.x, CLOCK_CENTER.y, (float) (Math.toDegrees(hand_minute.getBody().getAngle())), 1.0f, bitmapMinute); g.drawTransformedPicture( CLOCK_CENTER.x, CLOCK_CENTER.y, (float) (Math.toDegrees(hand_second.getBody().getAngle())), 1.0f, bitmapSecond); g.setColor(Color.BLACK); } /* Display time in text */ g.drawString(w - 200, h - 10, "Famous clock from\r\n" + "the Swiss Railways."); g.drawString(w - 200, h - 80, displayTime()); g.drawSchoolLogo(); }