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 / Scrolling in 2d games

Author
Message
Hayer
18
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Norway
Posted: 22nd Nov 2008 16:03
Hi!

So after a day of work I got Box2D working and all my other libs working(well, Box2D took only 5mins of that time :p )
So after creating some basic physics and collisions test I relaised that I need to implent scrolling.. Well, a quick search at TGC-forums gave an answer to that. Converted and renewed some old DBPro code I found..

After testing it I got some problems.


What do I do about gravity?

Lets say the player is falling down.

Box2D will return some results
example :
Box2D Returns
x = 300
y = 200

I do
dbSprite( 1 , x , y , 1 )


That screws-up my camera function totally cause my camera functions scrolls the world and all the enemyes, not the player.

Any tips/advice/help?


A simpler version cause I suck at explaining things:
How would I go about implenting a map scrolling function in a 2D game using Box2D for physics and collision?

Slayer93
20
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 23rd Nov 2008 06:44
First, if Box2D is returning values such as 300 and 200 you are probably working in pixels and you shouldn't. Box2D works in meters so you will probably have to change that if you want it to work correctly.

For your scrolling problem you could always modify it to scroll with the player too, that might be the easiest way unless there is something up with your scrolling code that doesn't let you do that (never shown us any code so can't tell).

Hayer
18
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Norway
Posted: 24th Nov 2008 23:14
But what is the theory behind scrolling?

Like; How do I scroll the world with physics?

Slayer93
20
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 25th Nov 2008 03:16
Quote: "But what is the theory behind scrolling?"


Lets see if I can explain this well. The point of scrolling is to only draw what you need to on the screen but have a world as big as you would like as it would be pointless to draw everything probably could crush the fps. An easy way to handle this is tile based, usually used with maps broken into tiles to form a unique map.

For tile based scrolling, you would have a grid system. All the tiles would be put into the grid and you would loop through the grid to draw the tiles. You would only go as far as how many tiles the screen can fit and move along the grid.

So if you started at (0,0) on the grid and can only draw 32 tiles horizontally and 24 tiles vertically. You would loop through the grid to find what to draw and everything outside wouldn't be drawn. So the tile at (10,1) would be draw but tile (32,26) wouldn't. But if you moved the starting position to (0,5) then (10,1) wouldn't be drawn and something like (32,26) would be.

Now if you didn't use a tile based system and use a grid you would just see if a sprite was in the range of the camera to draw it. Using an offset position to move around and the screen size and sprite size to check if it is in range.

For physics, the box2D world is completely separate to the visual representation of it so you would check the box2D world for positions and if it is in range then draw it at the relative position.

Hope that helped a little or made some sense, but that's really a general explanation. I would try and google some stuff on scrolling or tilebased maps. That might help more as there is a lot more to be said to cover everything

Login to post a reply

Server time is: 2024-09-30 11:30:09
Your offset time is: 2024-09-30 11:30:09