The idea is simple - create layers with an extra layer for each with initial positions and velocity and move them. On each frame, after updating the camera of your main layer, grab its position and apply a scaled version of it as the position of each of your other layers cameras positions (each layer should have a camera position scale parameter).įor each layer, first apply its cameras combined matrix to the sprite batchs projection matrix before adding that layers sprites. One of the layers would be your main layer where the games physics takes place. In the same way, movement of yellow object is greater than red object movement. The thing is that the relative movement of the green rectangle is greater than the movement of the yellow. In the viewport to the right the camera has been moved to the right so all the objects disappear to the left. The green one is near the player, the red ellipse is far and the yellow one is in the middle. We need to achieve a parallax effect taking in consideration the distance of the elements. With this in consideration, we cannot set fixed positions for elements and move only the camera.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |