Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / How to do side scrolling

Author
Message
Pog Mo Hone
14
Years of Service
User Offline
Joined: 21st May 2010
Location:
Posted: 6th Jul 2010 22:45
Ive always wondered how to create a background that will scroll with a background of different objects in it. Instead of scrolling a background that fits the screen, I want the background to change as the level progresses. Anyone know how I can go about this? Any tutorials examples?

"Wisemen say: Forgiveness is divine, but never pay full price for late pizza." - Michaelangelo
Nightshade
14
Years of Service
User Offline
Joined: 1st Jul 2010
Location:
Posted: 9th Jul 2010 02:36
ok, not sure if this will help but the solution i came up with for a scrolling graphic was to put all the graphics data in to a graphics class that held the variables needed by dbPasteSprite and dbPlaySprite then i used a 2d vector (std::vector<std::vector<graphics> > ) (that syntax may not be right, im still kind of a beginner) then you tell the screen to start drawing with x and y values in a given range such as x > 30 and x < 90 along with y > 10 and y < 70 or something like that then you simply alter the range when you want it to "scroll". (such as : if(dbUpKey == 1){rangeY = rangeY +1;})Id send you my code as it does the job but not well (currently it eventually crashes) i just got it to work for the first time yesterday. if your intersted to see the code let me know and ill send it to you, but ill warn you im not very good. also it may take me a few days to replay as i dont have internet at home atm. Hope this helps!!!
Pog Mo Hone
14
Years of Service
User Offline
Joined: 21st May 2010
Location:
Posted: 9th Jul 2010 21:51
This is very helpful. I would definitely love to see the code. I always learn better getting an idea of how its layed out. Dont worry about it not being good. Im not the best either so no judgement here.

"Wisemen say: Forgiveness is divine, but never pay full price for late pizza." - Michaelangelo
helpfull programmer
14
Years of Service
User Offline
Joined: 30th Jul 2009
Location:
Posted: 10th Jul 2010 00:42
Very good way of going about it I must look into this aswell

from helpfullprogrammer @ youtube
Pog Mo Hone
14
Years of Service
User Offline
Joined: 21st May 2010
Location:
Posted: 10th Jul 2010 07:06
Ha, nice to see you hear helpfullprogrammer. Ive actually watched a few of your tutorials to get me started on some predefined functions. You are quite....helpful! Greatly Appreciated. Feel free to do more.

"Wisemen say: Forgiveness is divine, but never pay full price for late pizza." - Michaelangelo
helpfull programmer
14
Years of Service
User Offline
Joined: 30th Jul 2009
Location:
Posted: 10th Jul 2010 13:56
Sure, just finishing the pong series and then I will move onto things like sound etc etc...
Nightshade
14
Years of Service
User Offline
Joined: 1st Jul 2010
Location:
Posted: 17th Jul 2010 03:07
ok sorry it took me so long to get back to you guys, but here is my solution.


Thats the whole of the graphics class. The Frame size varible is static cause you only need one copy of it. It represents the size of each location in the vector (the vector represents the whole of the "world".) Because the games dbScreenWidth and dbScreenHeight functions count in pixals this serves as a way to measure the map in pixals rather then points in the vector. For me i wanted all my points to be square so i only needed one variable to serve as both height and width, if you want to use rectagles just make a framesize height and framesize width. I also created a map class to hold this, and some other custom data, most of that classes isnt important to the scrolling but a few variables and functions are, and here they are;

these 3 variables control what part of the universe is being drawn and how fast the screen scrolls. (they are also static cause all you need is one of each of those. This is the loop for drawing, its not that good cause you need to set up a loop for it to work right and i meant to make that into a fuction too i just havent yet so here is the draw function:


this is the loop which draws to the screen:

youll notice a varible in there called Ignore (or more specifically the function call .getIgnore) this is because some of my graphics are larger then framesize and i didnt want any overlapping so i made sure not to put graphics data in the coordinates covered by other graphics.
The real "magic" here is the nested loops which supply the x and y values for drawing the vector coordinates on to the screen and that the coordinates drawn coorispond to BeginX and BeginY, so when you want to scroll you just change BeginX and/or BeginY, this will alter the part of the vector that is being drawn to the screen.Further, the limits placed on the loop are governed by the width and height of the screen so that a) you wont draw past the edge of the screen and b)the scrolling will work just fine regardless of resolution. you need to be careful when scrolling that you dont over run the vector, here are my scrolling functions:

these functions scroll the screen. it also checks to ensure that you dont over run or under run the vector, as this will cause your program to crash with a "fatal error" error. The scrolling left and right functions are virtually identical to the above but with dbScreenWidth instead of dbScreenHeight and they use x instead of y.

ok so that is pretty much the meat and potatoes of a scrolling screen, if this is to complicated let me know and ill send you all the code with my notes that should make it easier to understand, it was hard to fit everything into this tiny box, hope this helps!!!

Login to post a reply

Server time is: 2024-07-04 09:21:54
Your offset time is: 2024-07-04 09:21:54