Get the latest Education e-news
 

Go Back   Game Career Guide Forums > Programming
Forum Home Register Members List Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 08-14-2011, 08:46 AM   #1
rojan_neo
Junior Member

Activity Longevity
0/20 9/20
Today Posts
0/11 sssssss13
Location: Kathmandu, Nepal
Default help in making a 2D side scrolling game

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???
rojan_neo is offline   Reply With Quote
Old 08-14-2011, 01:17 PM   #2
Mitar
Junior Member

Activity Longevity
0/20 9/20
Today Posts
0/11 ssssssss6
Default

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.
Mitar is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Powered by vBulletin® Version 3.6.9
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
All times are GMT -8. The time now is 02:33 PM.






UBM Tech