forums

TNT Basic Forums > Programming Q&A
sprite movement problem
< Last Thread     Next Thread >
Author
Thread        Post A Reply

11-09-2005 00:55

Posted by:
marty samuels

Click Here to Email marty samuels   Find more posts by marty samuels

Hello

I have 8 sprites on the screen and I am
using an array for the xpos and that all
works ok. I can't seem to make the sprites
move. I am overlooking something
simple here, can someone tell me what
I am doing wrong here?

Thanks

hide mouse
graphics mode 800,600
draw picture 129
load images 128

int n,x[8],y = 50

while pressed(12) = false


for n = 0 to 7

x[n] = n * 40

sprite n, x[n],y,0 'everything ok here, 8 sprites

next n

for n = 0 to 7 'here is the problem
x[n] = x[n] +1 'nothing is moving
next n

draw frame

wend

11-09-2005 03:44

Posted by:
Jae Rune

Location:
Cheyenne, WY

Find more posts by Jae Rune

You've got the right idea, but the code's not pieced right. You're repeating everything from scratch (including creating the sprites) each frame update. Also, none of your code actually tells the sprites themselves to move... it only tells x to update.

You have it as:

while somethingIsntHappening

for
create sprites
next

for
update x position
next

update

wend


Which is going to destroy and recreate those sprites over and over again. What you want to do is:

for
create sprites

while somethingIsntHappening

for
update x position
move sprites
next

update

wend


Make sense? Here's how your code SHOULD look:

hide mouse
graphics mode 800,600
'draw picture 129
load images 128

int n,x[8],y = 50

for n = 0 to 7
x[n] = n * 40
sprite n, x[n],y,0 'everything ok here, 8 sprites
next n

while pressed(12) = false

for n = 0 to 7 'here is the problem
x[n] = x[n] + 1 'nothing is moving
sprite n,x[n],y,0 'missing code segment
next n

draw frame

wend

Hope that helps!

11-10-2005 01:09

Posted by:
marty samuels

Click Here to Email marty samuels   Find more posts by marty samuels

Thanks for the help.
I knew it was something simple.

11-10-2005 03:59

Posted by:
Jae Rune

Location:
Cheyenne, WY

Find more posts by Jae Rune

No trouble. Hope the shoddy formatting on the post didn't confuse you too much. I slopped this together in a test engine and had to comment out draw picture 129 because I didn't feel like hunting down or making a resource just to test something.

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.