forums

TNT Basic Forums > Programming Q&A
I need help with sprites.
< Last Thread     Next Thread >
Author
Thread        Post A Reply

06-15-2006 21:32

Posted by:
Harry-combs

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

I am trying to make a sprite look and move left if I hit the left arrow key, and look right if I hit the right arrow key. This is my code:

graphics mode 640,480
int x=300, y=240
int image=0
hide mouse
load images 128

draw frame

sprite 000,x,y,image

while not mouse button
draw frame
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 000,x,y,000
Draw Frame

wend

while not mouse button

if right then image=000
draw frame


if left then image=001
draw frame


wend
The reason I have: if left then image=001: again is because when I tried: if left then x=x-5 and image=001: if I moved left the sprite would jump left across the screen and he wouldnt move left or right any more.

06-15-2006 22:09

Posted by:
Jacob

Location:
San Francisco, CA

Click Here to Email Jacob   Find more posts by Jacob


graphics mode 640,480
int x=300, y=240
int image=0
hide mouse
load images 128

'draw frame : No need to do this here

'sprite 000,x,y,image : No need to do this here

while not mouse button
'draw frame : No need for TWO 'draw frame' commands, as this slows the speed of the game
if up then y=y-5
if down then y=y+5

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

if right
x=x+5
image=0
end if

Sprite 000,x,y,image'000 : you need to beable to change the picture
Draw Frame
wend

'while not mouse button : two while loops cannot run at the same time.
'
'if right then image=000
'draw frame
'
'
'if left then image=001
'draw frame
'
'
'wend

All you have to do is copy and paste the code into your game.

The main problem (and a minor one that didn't let the image change, you needed to make the sprite image image not 0) was that you had two different loops. Thus your code ran as follows:
Initialize
Loop, you can move the sprite around
Click mouse button
Loop, you can change the image
End

If you don't fully understand this please post what you don't understand. Figuring out what you did wrog is the best way to learn.

06-15-2006 23:17

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

we should really write a tutorial about making a character move

i realise there is verry little TNT tutorials available for people that aren't experiences enough to manage with the command reference

06-16-2006 00:15

Posted by:
Harry-combs

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

Thanks!

06-16-2006 00:28

Posted by:
Jacob

Location:
San Francisco, CA

Click Here to Email Jacob   Find more posts by Jacob

Check this out

I just made a quick tutorial.
Does it need anything else? Goodies? Baddies? Tiles? Score?
Or do you think it's a great starter?

Getting Started.sit

06-16-2006 12:28

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

there's already a good tutroial about tiles so i think it's okay

but i meant a tutorial rather than an example

i no one wants to make one, i volunteer to try

06-20-2006 10:35

Posted by:
kemalyun

Location:
Frankfurt/Germany

Find more posts by kemalyun

I think

It seems what Harry doesn't understand yet is the concept of how the code is being run by the computer, i.e. from top to bottom, loops and such. It's not a problem of how to use tiles or sprites, it's the basic-concept of how a program-code is interpreted.

Tip for Harry:
Think about a little man inside the computer reading your code. The moment he reads a single command, he also does what it says. Then he proceeds with the next command. Some commands tell him to go back to somewhere else and continue reading at that position, which is what he does at that moment. There is only one little man there, so only one command can be executed at a time. The little man can not do two things at the same time. However, he can do things very fast so at the end it seems to be at the same time - sometimes. When checking your code imagine to be the little man and go through the code command by command, do like the little man does.

In your example: A repeat-until loop tells the little man to go back to the beginning of the loop, until the final condition is met. Only then he continues to read the next code-lines and execute them:

repeat
bla
bla
bla
until a=0
(at this point he goes back to the "repeat". only if a equals 0 then he continues)

if a=0
(here he checks if a=0. If yes, then he continues. if not, he goes to the end if and continues there)
bla
bla
bla
bla
end if

Try to understand this basic concept, then you'll be able to understand the rest much more easily and get your programs done without bugs much faster.

06-20-2006 16:21

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

kemalyun, you should write a tutorial :D these explaination can certainly make things clearer for lots of beginners

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.