|
|||||||
| Forum Home | Register | Members List | Mark Forums Read |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | ||||||||
|
Junior Member
Location: Kathmandu, Nepal |
I am trying to make a side scrolling game (like mario) using SFML in c++. I have already implemented the side scrolling mechanism and now the screen's background gets scrolled perfectly. I also have made my character(move along the screen). Now the problem is : How do I get other sprites (such as the walls in mario) which are not currently visible; to scroll along with the background while player presses a key???
|
||||||||
|
|
|
|
|
#2 | ||||||||
|
Junior Member
|
You'd want to have a global offset. That offset is used with all other elements that are drawn on screen. So once you character moves right the offset in the X direction becomes smaller, and when for example a box is about to be drawn the offset is added to the box.
So lets say the screen is 640x480 and the box is in the location 1000x400. When the player moves right and the offset becomes smaller. When the player moves 500 pixel to the right the offset will become -500 pixels. When drawing the box you take the box positions and add the offset: xDrawingPosition = 1000 + (-500) The box will now be drawn on the position 500 which is within the screen bounds. You should add offset to every element you want to draw onscreen in the drawing process. Alternatively you can make a camera that offsets its-self and therefore follows the character. |
||||||||
|
|
|
![]() |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
Powered by vBulletin® Version 3.6.9
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
All times are GMT -8. The time now is 12:12 AM.

















Linear Mode

