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 / Moving 2-D objects

Author
Message
Zorkonian12
14
Years of Service
User Offline
Joined: 28th Jul 2010
Location: Why would I tell you?
Posted: 11th Aug 2010 01:32
Hi everyone,
I have a quick question on how to get 2-D objects (like a basic circle) move across the screen using arrowkeys. I think I have an idea on how to do it but I'm not sure. If you could be give me a code and an explanation that would be AWESOME.

Thanks!

Bursar
16
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 11th Aug 2010 11:37
If you have an idea, post it up.

Much better to say how you think you would do it and have it corrected than to just get people to give you the answer straight away.
CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 11th Aug 2010 11:40 Edited at: 11th Aug 2010 11:46
well maybe this will work if you put it in your game



Put that in your do,loop command, change "spritenumber" with your sprites number.

Here's kind of how it works


that is defining a variable (x and y) that it is the same thing as your sprites position x and y. (it's just a shorter way of doing things)


this is saying if you press one of the arrow keys then...


for an example of that lets only do x=x+1
that is saying that object position x is equal to object position x but your adding one to move the sprite


That is simply moving your sprite to the new position.

I want coke, not Pepsi!
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 20th Aug 2010 21:04
The simplest way I know is this.

Obviously you need to set up x and y unless you want 0,0 as the first point. Put the code in a subroutine or function and call it from your main loop.

http://s6.bitefight.org/c.php?uid=103081

Login to post a reply

Server time is: 2024-09-28 20:36:09
Your offset time is: 2024-09-28 20:36:09