forums

TNT Basic Forums > Programming Q&A
How to use arrows to move sprites?
< Last Thread     Next Thread >
Author
Thread        Post A Reply

07-11-2003 05:16

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

I got a sprite, and I want to move it with the left arrow key , but it doesn't seem to work unless I press it before the program launches, how do you do it?
this is my code:

Graphics mode 640,480
Load images 128
integer x
x=0
sprite 128,1,1,000 ' put the sprite on the screen
if pressed (124) then x = x + 50

if pressed (124) then move sprite 128,x,0,2

while not mouse button
draw frame
wend

07-11-2003 05:54

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

Here's your problem..again

DOH! I clicked the "clear fields" button instead of the "submit reply" button!

Ahh...anyway...your problem is that your "if pressed" lines aren't included in the while loop, so it only checks in the beginning. Just put them in the loop like this:

Graphics mode 640,480
Load images 128
integer x
x=0
sprite 128,1,1,000 ' put the sprite on the screen

while not mouse button

if pressed (124) then x = x + 50
if pressed (124) then move sprite 128,x,0,2

draw frame
wend

However, I think this will do something you don't expect. You are trying to get the sprite to move 50 every time you push left, right? What this will do is move it 50 more than the last time every time. The "move sprite" command moves it x amount, and if you increase x, it moves it more every time. Instead, just type

if pressed(124) then move sprite 128,50,0,2\

eekaydee

07-11-2003 06:03

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

Thanks

07-11-2003 06:16

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

Then, hoe do you replace the sprite when you press another arrow key?

07-11-2003 06:39

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

here's my codeGraphics mode 640,480
Load images 128
int image=000
int id=128
' put the sprites on the screen
while not mouse button
if pressed(124) then sprite id,1,380,image
if pressed(124) then id=id
if pressed(124) then image=image
if pressed(124) then move sprite id,5,0,image 'left

''
if pressed(123) then sprite id,1,380,image
if pressed(123) then id=id+1
if pressed(123) then image=image+1
if pressed(123) then move sprite id,-5,0,image'right

''
if pressed(126) then sprite id,1,380,image
if pressed(126) then id=id+2
if pressed(126) then image=image+2
if pressed(126) then move sprite id,0,-5,image'up

''
if pressed(125) then sprite id,1,380,image
if pressed(125) then id=id+2
if pressed(125) then image=image+2
if pressed(125) then move sprite id,0,5,image 'down

''
draw frame
wend
int image=0


but it doesn't work

07-11-2003 07:48

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

My mistake

Sorry, I misunderstood you. I think I know what you're trying to do. The "move sprite" command is used to tell a sprite to move a certain distance at a certain speed. For example, you can type

move sprite ID,50,0,pixelDist

and then you can leave it alone; everytime you call draw frame, it will move it pixelDist until it has moved 50 pixels to the right. In your code, you wrote

if pressed(123) then move sprite id,-5,0,image 'right

This is incorrect syntax, check the TNT help file. The last parameter you pass to the move sprite command is the speed of movement, not the image. If you want to simply move a sprite around, try this:


Graphics mode 640,480
Load images 128
int x=100,y=100
int ID=1,image=0

while not mouse button

if up
y=y-1
image=0
end if

if down
y=y+1
image=1
end if

if left
x=x-1
image=2
end if

if right
x=x+1
image=3
end if

sprite ID,x,y,image
draw frame
wend

Sorry if my prevous posts confused you

07-11-2003 08:08

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

It works quite well this time thanks

07-11-2003 21:37

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

>>
if pressed(125) then sprite id,1,380,image
if pressed(125) then id=id+2
if pressed(125) then image=image+2
if pressed(125) then move sprite id,0,5,image 'down
>>

Horrible syntax!!! Try this:

if pressed(125)
sprite id,1,380,image
id=id+2
image=image+2
move sprite id,0,5,image 'down
end if

it'll be better if you have 150 lines to execute under the same condition ;)

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.