public static void updateCameraOffset(Hero p_hero) { Point l_cameraOffset = new Point(); l_cameraOffset.X = (int) (p_hero.getXCenter() - m_gd.Viewport.Width / m_scaleFactor / 2); l_cameraOffset.Y = (int) (p_hero.getYCenter() - m_gd.Viewport.Height / m_scaleFactor / 2); int l_maxCameraX = (int) (m_currentRoom.background.Width * m_currentRoom.background.TileWidth - m_gd.Viewport.Width / m_scaleFactor); int l_maxCameraY = (int) (m_currentRoom.background.Height * m_currentRoom.background.TileHeight - m_gd.Viewport.Height / m_scaleFactor); if (l_cameraOffset.X < 0) { l_cameraOffset.X = 0; } if (l_cameraOffset.Y < 0) { l_cameraOffset.Y = 0; } if (l_cameraOffset.X > l_maxCameraX) { l_cameraOffset.X = l_maxCameraX; } if (l_cameraOffset.Y > l_maxCameraY) { l_cameraOffset.Y = l_maxCameraY; } Point l_previousCameraOffset; l_previousCameraOffset.X = m_currentCameraOffset.X; l_previousCameraOffset.Y = m_currentCameraOffset.Y; int l_dx_offset = l_cameraOffset.X - l_previousCameraOffset.X; int l_dy_offset = l_cameraOffset.Y - l_previousCameraOffset.Y; //update m_currentCameraOffset = l_cameraOffset; if (!(l_dx_offset == 0 && l_dy_offset == 0)) { CameraOffsetEventArgs args = new CameraOffsetEventArgs(); args.dx_offset = l_dx_offset; args.dy_offset = l_dy_offset; if (OffsetChanged != null) { OffsetChanged(null, args); //call all registered listeners } } }
public void update(Hero h, float elapsed) { //set initial positions arrow.setXCenter(h.getXCenter()); arrow.setYCenter(h.getYCenter() + ARROW_Y_OFFSET); negativeBar.setXCenter(h.getXCenter()); negativeBar.setYCenter(h.getYCenter() + BAR_Y_OFFSET); positiveBar.setXCenter(h.getXCenter()); positiveBar.setYCenter(h.getYCenter() + BAR_Y_OFFSET); //update moving arrow //moves sinusoidally arrowTimer += elapsed; displacement = (int)(NEGATIVE_WIDTH / 2 * Math.Sin(arrowTimer * speedFactor + randomOffset)); arrow.setX(arrow.getX() + displacement); }