forums

TNT Basic Forums > Programming Q&A
Im new and I am having trouble moving sprites
< Last Thread     Next Thread >
Author
Thread        Post A Reply

06-06-2006 21:02

Posted by:
Harry-combs

Click Here to Email Harry-combs   Find more posts by Harry-combs

Im trying to make a sprite move to the left when I hit the left arrow key. The sprite appears on the screen but I cant move it.Here is my code so far:

graphics mode 640,480
activate input
hide mouse
load images 128
set image bank 000,128
sprite 000,5,200,000
draw frame
int x=0
if pressed (124) then x=x+10
Sprite 000,x,0,000
Draw Frame

wait mouse click


PLease help me.

06-06-2006 23:17

Posted by:
Jacob

Location:
San Francisco, CA

Click Here to Email Jacob   Find more posts by Jacob

Here is the simplest way to do it:

Fade Down 'fades screen to black
Graphics Mode 640, 480
Load Images 128
Int x=320, y=240
Fade Up
While not mouse button 'if you click then rhe game quits
if up then y=y-5
if down then y=y+5
if left then x=x-5
if right then x=x+5
Sprite 0, x, y, 0
Draw Frame
Wend

There, now that will make you be able to move the sprite in any direction.
Be sure to indent you code for easy reading.

If you need any help on anything just post here!

06-06-2006 23:31

Posted by:
Jacob

Location:
San Francisco, CA

Click Here to Email Jacob   Find more posts by Jacob

Oops!

I forgot to tell you why your code didn't work (also how to simplify your code).

graphics mode 640,480
activate input'you don't need inputs
hide mouse
load images 128
set image bank 000,128'this you don't need, because it uses the latest loaded images(unless you set the default one)
sprite 000,5,200,000'did you want this to place the sprite? You would need to have variables
draw frame
int x=0
Here is where you need a loop. Without a loop your code only runs once. The "while" and "repeat...until" loops are good ones for this.
if pressed (124) then x=x+10'just write "left"
Sprite 000,x,0,000
Draw Frame
End the loop (wend/until)
wait mouse click

The reason your sprite wasn't moving was because 'wait mouse click' pauses everything until you click the mouse.
So, you want to use either of these:
1)
While not mouse button
...Your code...
Wend
2)
Repeat
...Your code...
Until mouse button

06-07-2006 00:16

Posted by:
Harry-combs

Click Here to Email Harry-combs   Find more posts by Harry-combs

Thanks!

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.