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.

2D All the way! / Scrolling the screen when you get to the edge

Author
Message
Nilrem
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 2nd Jun 2003 14:51
Ok, this is a hurdle I need to jump, once I have my character walk to the edge of the visible screen how can I make it scroll along to show the rest of the map?
I hear and I forget. I see and I remember. I do and I understand.
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 2nd Jun 2003 16:35
What map? Can you give us an idea of how you have done your map so far?

I'm sure that between us we can work out what you have in mind
ReD_eYe
21
Years of Service
User Offline
Joined: 9th Mar 2003
Location: United Kingdom
Posted: 2nd Jun 2003 19:52
i tried this last night, what i did was put the whole map on a 3d plain and then the character(also a plain) is followed by the camera round the map. i've yet to try implementing collision and other things but i'll try

ARE YOU A 3D MODELER??? IF SO WE NEED YOU!!!
EMAIL mynameisnoneofyourbuisness@hotmail.com to work on the new Star Strike project!!!
David T
Retired Moderator
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 3rd Jun 2003 00:29
You can use the object screen x() anda object screen y() command to get an object's screen position, and if it's greater / bigger than a certain amount then scroll the screen:

top is Y < ~50
bottom is Y > ~height-50
left is X < ~50
right is X > ~width-50

You are the th person to view this signature.
Programmers don't die, they just Gosub without return....
Nilrem
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 3rd Jun 2003 03:00 Edited at: 3rd Jun 2003 03:00
Basically the map, well that part of it is simply a 2D image that is larger then the screen it is been displayed on, when the character walks to the visible edge I would like it to scroll along, I hope I making sense?

An example would be greatly appreciated along with a piece of sample media? I learn best from working hands on. "I do and I understand."

I hear and I forget. I see and I remember. I do and I understand.
EightYearRecoil
20
Years of Service
User Offline
Joined: 7th Apr 2003
Location: United States
Posted: 4th Jun 2003 04:25
When I did that I set up another bitmap with the background picture. I'd get the image from the background bitmap and paste it to the screen, and as the character walked to the edge, I would just grab a different x position on the background bitmap and paste it to the screen. I hope that helps. I can send more later if you want, like sample code or something.

Eight Year Recoil
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 4th Jun 2003 09:56
That seems like a good method. You could also just load the bitmap directly into the image and paste it onto bitmap 0. When your character reaches the right hand side of the screen, just start to paste the image further to the left (negative coordinates are allowed).
SelethD
20
Years of Service
User Offline
Joined: 1st Jun 2003
Location:
Posted: 4th Jun 2003 17:39
Remember when the character reaches the boundry line where you want the screen to scroll, make sure you subtract the ammount of screen scroll x,y from the characters in viewport coordinates.
Say screen is at 0,0 character map coords at 100,50 character view coors at 100,50. He moves right 5 pixels past scroll point... so now map is displayed at 5,0 character map coords are at 105,50 and character view coors will need to be 100,50 again(you subtract the 5 pixels right he moved)

By the way does your map consisnt of one giant image, or is it kinda tiled like several small images? Tiled maps are more versatile in you can have a really large map, but probably include more math to get scrolling, because you have to deal with knowing when to add another row or column to the edge of the existing scene.

Happy Coding

Nilrem
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 5th Jun 2003 02:59
SelethD, one big map.

Thanks to everyone for the feedback, and yes some example code would be terrific.

I hear and I forget. I see and I remember. I do and I understand.
David T
Retired Moderator
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 5th Jun 2003 21:34
The method I posted above would be fine for scrolling a 2D image:



CX and CY are the character positions. XP and YP is the position to paste the map image. A negative (-) position means you have moved SE in the map (0,0 on your screen is the top left corner).

You are the th person to view this signature.
Programmers don't die, they just Gosub without return....
Nilrem
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 8th Jun 2003 14:48
What I'm aiming to do is, hmm well the best way for me to describe this is through another game, take Ultima Online for example; in UO, when you start to move the map moves, like the whole map file is probably loaded into memory, then once you get nearer the edge then that part is scrolled down/left/right/up etc, what I'm wondering is how to approach this method? I learn best from examples of code with media etc.

How did they actually create one big map?

I hear and I forget. I see and I remember. I do and I understand.
adr
20
Years of Service
User Offline
Joined: 21st May 2003
Location: Job Centre
Posted: 8th Jun 2003 15:06
I suppose one huge world map would be a little silly..

You could make a 2D array of image IDs:



Then you just keep try of your x,y grid coordinate and then you know which image your character is sat on, which one is above, below, left and right. You can put in control codes like 0 to mean there is no map or it's an unwalkable area.

As for the actual drawing of the background, It looks like people have been suggesting a sliding window type idea, whereby as soon as your character nears a threshold of the screen (like, gets to the right hand third) you scroll the image.

Have a "virtual screen" bitmap - This bitmap will be the one blitted to the screen. I've not touched 2D in darkbasic, but in SDL, you'd copy parts of your source bitmap(s) into a destination bitmap. This way, using the grid method, you can stitch together the background....

Nilrem
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 8th Jun 2003 18:26
It says the variable aGrid does not exist Adrian?

I hear and I forget. I see and I remember. I do and I understand.
ReD_eYe
21
Years of Service
User Offline
Joined: 9th Mar 2003
Location: United Kingdom
Posted: 8th Jun 2003 20:07
agrid looks like a function to me

ARE YOU A 3D MODELER??? IF SO WE NEED YOU!!!
EMAIL mynameisnoneofyourbuisness@hotmail.com to work on the new Star Strike project!!!
Evil Noodle
20
Years of Service
User Offline
Joined: 28th Apr 2003
Location:
Posted: 10th Jun 2003 13:11 Edited at: 10th Jun 2003 13:12
you will need to declare the array

DIM aGrid(4,3)

I Think

T.A.F.K.A.C.M.O.T.D
The Artist Formally Known As Cut_Me_Own_Throat_Dibbler
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 10th Jun 2003 14:45
Here's some code I put together a month or so ago for someone who wanted a basic tiling system with scrolling.

Have a play, take your time understanding it, and get back with any questions

Oh, it might help if I tell you that the coordinates used are where to draw the map, not where the sprite is on the map. So when you scroll right, you are decreasing the x coordinate of the map, not increasing coordinates of the sprite.
Nilrem
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 10th Jun 2003 23:20
Cheers Ian.

I hear and I forget. I see and I remember. I do and I understand.
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 11th Jun 2003 01:07
No probs

Login to post a reply

Server time is: 2024-03-28 11:02:31
Your offset time is: 2024-03-28 11:02:31