Jump to content
  • Advertisement
Sign in to follow this  
raptorstrike

scrolling in sdl

This topic is 5001 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

is there a way to scroll images in sdl WITHOUT having to move everything but the "moving" item(to give the illusion of movement) so that you can get sort of a camera effect?

Share this post


Link to post
Share on other sites
Advertisement
Yes it is Possible to do so. since each object has their own x and y coord, all you have to do is change the x and y coord of the objects you want to move that's it.

Share this post


Link to post
Share on other sites
One idea that springs to mind is to create a huge image (much, much larger than the screen) of all the items that are not part of the moving item. This is done once at the start of the program (or as an image through some art package). Then blit to the screen only the area you want, and place your 'moving' item at the same spot on the screen everytime.

This assumes you don't need to place any objects in front of the moving item.

HTH.

Share this post


Link to post
Share on other sites
this COULD work but since alot of my items move around and the sceen is constantintly changing its just not practical.
if all else fails ill just make a seprate map for every section i just wanted to know if there was a way to scroll without moving everything behind it

Share this post


Link to post
Share on other sites
here is a reply i posted to someone who had this question before. you can read the thread here.

if you want the screen to scroll, your going to need scrolling offsets.

this is going to be hard to explain, but ill try my best. in order to have a scrolling screen, you need to start thinking in WORLD coordinates. throw screen coordinates out the window, THERE IS NO MORE SCREEN COORDINATES! understand? only WORLD coordinates.

from now on, ALL of your characters and objects will store WORLD positions. this means their x/y position could be (20,30), or (2102,24320), the point is, their position is no longer limited to the screen. it is only limited by the world. IE, your position can be (9000,9000), as long as the world your in is that big, IE, the map you are on is bigger then (9000,9000).

now, your going to have to define 2 varialbes - Screen_Offset_X and Screen_Offset_Y. make them integers. this represents the offset that the screen is into the world. this is the position of the screen / camera in the world. lets pretend your screen is 800x600 resolution, and lets also pretend your on a map which is 2000x2000 pixels big. heres an image:



Take a look. this is your world. the top left corner of your world is 0,0 and the bottom right corner is 2000,2000. right now, your player is somewhere towards the top left portion of the world.

each frame, simply have the "camera", or the screen, follow the player. to do this, each frame, do this:

Screen_Offset_X = player.xPosition - (400);
Screen_Offset_Y = player.yPosition - (300);

do you see what i mean? you LOCK the screen position to follow the player - make it he players position Minus half the screens dimensions - bingo, the screen now follows the player around, keeping the player in the center of the screen at all times. you can factor in the players dimensions in that equation too, to make it more centered, but that is the gist of it.

now, theres one thing to note. You cant draw your objects at their position anymore. Why? well, the player or object no longer has a screen position, a world position, remember? something that could be huge, like (5000,2000), or (3423,3090). try drawing something at those positions, and what will happen? well, it wont show up, since you can only draw within the bounds of the screen, in our case, only on the x plane of (0,800) and the y plane of (0,600).

so, how do you draw everything then, if you cant draw them at their world position? the answer is simple. you just "cast" the world position into the screen coordinates... but how you ask? easy! just subtract the current screens offset from the objects position! the world position is now converted to a screen position.

Draw_Image(player,player.xPos - Screen_Offset_X,player.yPos - Screen_Offset_Y);

see what happends? your "casting" from world coordinates back to screen coordinates...

theres 2 important things to always remember:

1) YOU MUST ALWAYS STORE EVERYTHING IN WORLD COORDINATES!!!
2) YOU MUST ALWAYS DRAW EVERYTHING IN SCREEN COORDINATES!

remember, to convert from World to Screen, just do Position - Offset

to convert from Screen to World, just do Position + Offset. You will probably need to convert from screen to world in certain situations, like when using the mouse and stuff.

i hope some of this made sence.

[Edited by - graveyard filla on December 5, 2004 12:13:33 AM]

Share this post


Link to post
Share on other sites
re-read my post. this is exactly what i explain... if your still having trouble, read through the thread i posted. also, the API has no effect on this type of stuff. this will work using any graphics API.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!