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.

Newcomers DBPro Corner / Sprite moving problem

Author
Message
Travis Gatlin
15
Years of Service
User Offline
Joined: 14th May 2009
Location: Oxford, Alabama
Posted: 9th Jun 2010 22:41
i have a 2D Game that i am making and i cannot figure out how to make my little figure have a gravity effect, the sprite section of the help document doesnt say a thing about moving down so how do i do that?

The Object of war is not to die for your country but make the other guy die for his
luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 9th Jun 2010 23:56
You need to write it!Because nobody can say what you want to do with the sprite you use in your game.You can use it for making a hud, or menu, in your case this is your character.

Anyway i think you need some collision system.When you jump your guy inc it`s y position with some value then hiting the max it goes down until it hit the floor or fall somwhere, that`s where the collision comes in.

Something like that...

Where there is a will, there is a way.
I often edit my posts, that`s who i am
Travis Gatlin
15
Years of Service
User Offline
Joined: 14th May 2009
Location: Oxford, Alabama
Posted: 10th Jun 2010 00:31
im talking about adding gravity to my game... not anything to do with colision...

The Object of war is not to die for your country but make the other guy die for his
tomaszavenger
15
Years of Service
User Offline
Joined: 24th Jun 2009
Location:
Posted: 10th Jun 2010 01:00 Edited at: 10th Jun 2010 11:11
Okay, you see the y position of your sprite, that needs to go down. So basically, if you wanted gravity as a downwards movement per time (since speed is measured in ms^-1), you set a timer, and every few seconds, decrement the sprite's y position, and redraw it.

You will also need to set a rule when it collides with the floor, to stay up and counteract the effect. To do this, whenever a collision occurs, simply increment the sprite's y position to counteract it, and the object will stick to the floor.

If you want an idea, try this code (slow to demonstrate effect):



Make sure you insert an image into the load image section of this code.

(Note, this is a very simple example. In reality, the object falls faster with gravity as time passes, if you want me to demonstrate a better way of showing gravity, please leave a comment).
Travis Gatlin
15
Years of Service
User Offline
Joined: 14th May 2009
Location: Oxford, Alabama
Posted: 10th Jun 2010 03:11
thanks tom, that will work, the gravity dont need to be realistic, just working, i also have a problem with your collision system, it works and stuff like that but when i land it wont let me move, what went wrong?

The Object of war is not to die for your country but make the other guy die for his
tomaszavenger
15
Years of Service
User Offline
Joined: 24th Jun 2009
Location:
Posted: 10th Jun 2010 10:01 Edited at: 10th Jun 2010 11:10
Post your code, that will be helpful.

I've provided an example platform that handles collisions without getting stuck:



This system only works for platforms which are boxes in nature, if you have sphere drawings, it gets trickier!
Travis Gatlin
15
Years of Service
User Offline
Joined: 14th May 2009
Location: Oxford, Alabama
Posted: 10th Jun 2010 17:06 Edited at: 10th Jun 2010 17:08
Thanks tom, that is useful!, i do have some code but it does have external media,


The Object of war is not to die for your country but make the other guy die for his
tomaszavenger
15
Years of Service
User Offline
Joined: 24th Jun 2009
Location:
Posted: 10th Jun 2010 18:06 Edited at: 10th Jun 2010 18:23
I found the error, you see, move sprite doesn't have a function, since its redrawn with xpos. Instead of move sprite 0.2 and move sprite 0.2, change this to xpos = xpos + 2 or something similar.
Also, initialise xpos and ypos at the top as 0 or whatever number you need, and remove the sprite 1 section at the top, it's not needed, and by that I mean the line:

sprite 1,300,250,1

Your fixed code:

Travis Gatlin
15
Years of Service
User Offline
Joined: 14th May 2009
Location: Oxford, Alabama
Posted: 10th Jun 2010 19:50
oh, ok thanks for you help, i really need it.

The Object of war is not to die for your country but make the other guy die for his
tomaszavenger
15
Years of Service
User Offline
Joined: 24th Jun 2009
Location:
Posted: 10th Jun 2010 22:41
BTW, tell me if my fixed code works, because I didn't test it. And you're welcome.
Travis Gatlin
15
Years of Service
User Offline
Joined: 14th May 2009
Location: Oxford, Alabama
Posted: 12th Jun 2010 05:12
hey, you forgot the sprite command for the first image

The Object of war is not to die for your country but make the other guy die for his
tomaszavenger
15
Years of Service
User Offline
Joined: 24th Jun 2009
Location:
Posted: 14th Jun 2010 21:46
No, it updates automatically when needed. I should have initialized it though for the reason that the selection structures screw up if in that order. If you move the update to the beginning, you'd see that it works perfectly. Sorry about that! XD
Travis Gatlin
15
Years of Service
User Offline
Joined: 14th May 2009
Location: Oxford, Alabama
Posted: 16th Jun 2010 22:45
i believe i got it!, thank god i got that out of the way! thanks alot for your help,i really need it, i will reference this thread when i need it

The Object of war is not to die for your country but make the other guy die for his

Login to post a reply

Server time is: 2024-11-23 14:03:15
Your offset time is: 2024-11-23 14:03:15