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 / Programming ideals for side scroller, help?

Author
Message
Dragon Knight
17
Years of Service
User Offline
Joined: 10th Jan 2007
Location: Newcastle
Posted: 14th Jun 2009 22:46 Edited at: 14th Jun 2009 22:51
It's a simplistic question, i've created my own engine for now that handles windows API and i have my own structs for sprites etc.., and to keep this in the rules.., I'll be implementing gdk.. later >.>.

Anyway my question is in a 2D engine, how would you go about making a scrolling world?

here's a list of what i think may work but haven't tested:
a.)
make tiles everywhere in the screen, then every time the player moves, the tiles move left for example then once they've reached over the screen position them to the other side, and apply the next in line texture.
b.)
Setup the entire level to draw ALL sprites off that piece of level, then only draw what's within screen borders. Then when the player moves it's simply positioning the level at it's current position +/- players movement

Perhaps b may be the best bet?

Next collision, i know it's simple enough to do box collision, but saying a simple oldx#=x# and oldy#=y# wouldn't do this time as they'd stop dead on the spot if they hit ANY box. My solution may be to create a function to check each side of the box to see where the collision has happened up /down / left/ right. Or can you guys think of a better way?

Last but not least, any other help or suggestions are welcomed. I've been doing c++ for a year now, so i should be able to handle most things, I'm just a bit un-experienced when it comes to how to handle a 2D engine. Surprising since i know if it was in 3D i'd simply just make the level and move the camera. (And no i do not wish to do this game in 3D)

Oh yea.. and jump code, I'm guessing to use a sin wave, to make it look fluent?

Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 15th Jun 2009 00:07
Quote: "b.)
Setup the entire level to draw ALL sprites off that piece of level, then only draw what's within screen borders. Then when the player moves it's simply positioning the level at it's current position +/- players movement"


This is the route I'd go first but I'd have to be concerned about a number of things, most of them involving how much memory I'm using at one time. If you create code that has sprites outside the viewport you'd best tell the system to hide the non-visible sprites in order to cut down on unnecessary CPU cycles. Place all the sprites where they belong and use the dbOffsetSprite function to move the offset of all of them to the position of the column that should align with the left side of the screen.

Alternately shut off all sprites and use the position of the column that should be leftmost to determine which sprites need to be displayed there.

column/spritewidth should tell you what ordered tile should be positioned there

and

column%spritewidth should tell you how much you need to offset all the sprites to move them over to the left just enough to produce the scrolling.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Dragon Knight
17
Years of Service
User Offline
Joined: 10th Jan 2007
Location: Newcastle
Posted: 15th Jun 2009 00:29
Ah, thanks Lilith, just what i wanted to hear

Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 15th Jun 2009 20:48
Quote: "and jump code, I'm guessing to use a sin wave, to make it look fluent?"


In my opinion, in 2D you can use the same method as in 3D: give the sprite a starting upward velocity, then deduct gravity each frame. But you can try a different approach of course.
jezza
16
Years of Service
User Offline
Joined: 8th Mar 2008
Location: Bham, UK
Posted: 15th Jun 2009 21:56
Have a variable called vertical velocity.
Every frame the guy is touching the ground, this is zero, Every frame it is not, take the graivty (presumably 9.8) from this variable, even if it becomes negative.
Every frame add this velocity to the character's y position.
To jump, just add a value onto the vertical velocity. This value will be the initial upwards acceleration. Then , as it moves up it is no longer touching the gorund, so graivty is deducted, so it will slow down and then speed up downwards.

AndrewT
17
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 15th Jun 2009 22:51
Are you using Direct3D for your sprites? If so then you can simply move your camera the same way you would in 3D by changing the values in your view matrix, and this will create a scrolling effect. Sprites that are positioned farther away will move less, creating a cool parallax effect as well.

i like orange
Dragon Knight
17
Years of Service
User Offline
Joined: 10th Jan 2007
Location: Newcastle
Posted: 16th Jun 2009 00:23 Edited at: 16th Jun 2009 05:07
--HUGE EDIT-
Current Engine
http://www.hybridwolves.co.uk/Okrio.rar

So far so good, but i've come up with another problem, to do with the texturing of tiles. I believe there may be something wrong with the way i textured the background tiles.

I set it to 32 x 32 but it's actually going by something like 20x20, anyone have any idea why?

*Hmm i should really start putting dark gdk into it.., but i really want to learn to be efficient in c++ and know the in's and out before advancing to using other tools.*

Attachments

Login to view attachments
kklouzal
15
Years of Service
User Offline
Joined: 15th May 2009
Location: Arizona
Posted: 16th Jun 2009 11:40
GDK takes the "advanced" out of programming with directx, so using it would take a load off your learning process.

Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 16th Jun 2009 17:39
Quote: "I set it to 32 x 32 but it's actually going by something like 20x20, anyone have any idea why?"


Are you sure that you're not reading figures in hex? 32 is 0x20 hex.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office

Login to post a reply

Server time is: 2024-10-01 03:33:54
Your offset time is: 2024-10-01 03:33:54