Hello,
I would like to move an object from point A to B. I don't know how, but sure something with sin and cos...
TYPE TObject
x = 0
y = 0
speed = 0
direction = 0
ENDTYPE
LOCAL obj AS TObject
GETSCREENSIZE sx, sy
obj.x = sx/2
obj.y = sy/2
obj.speed = 5 //Five pixels per loop
obj.direction = 0 // 0 degree, right direction
LIMITFPS 10
destinationX = obj.x + RND(50)
destinationY = obj.x + RND(50)
WHILE TRUE
INC tick, 1
PRINT "Tick:" + tick, 10, 1
// Big guess:
// How can I move the obj to destinationX AND destinationY with a 5 pixel speed every tick
// ??????????????????????????????
IF obj.x = destinationX THEN CONTINUE
IF obj.y = destinationY THEN CONTINUE
SETPIXEL(obj.x, obj.y, RGB(255, 0, 0))
SHOWSCREEN
WEND
Can anybody help?
Take a look at : http://www.glbasic.com/forum/index.php?topic=1389.msg9091#msg9091 (http://www.glbasic.com/forum/index.php?topic=1389.msg9091#msg9091)
Argh, you beat me to it :-)
Think thats not the answer, as far as I understand:
QuoteNow we have an "X" moving from X=100 to X=300 at constant speed. Great!
However, most of the times you need the speed non-constant. When you
push your game logo into view, you might want it starting fast and slow
down to a halt.
He is talking about game logos and accleration - not really moving an object from A(startX, startX) to B(endX, endY)
Logo's are just an example. An alternative is at http://www.miscthings.co.uk/LineMove.gbas (http://www.miscthings.co.uk/LineMove.gbas)
Hmm,
without comments I am not able to understand that code. :/
Anyway I found a proper solution - taken from source code from a java game engine.
MrTAToad - what about putting a few line description of what the code does at the top of it with an example of how to call it for everyone's benefit?
Also, have you thought about changing it to allow for accelleration / decelleration rather than constant speed? Just a thought! :D