forums

TNT Basic Forums > Programming Q&A
Code is good but don't work..need your help..
< Last Thread     Next Thread >
Author
Thread        Post A Reply

10-13-2002 07:24

Posted by:
bg2

Click Here to Email bg2   Find more posts by bg2

Hello

i m under macos9.2 and i have done a little project to test TNT..but it don't work.. :/
There is no error, but the sprite don't appear at screen... :/
Here is the code:

Graphics Mode 640,480
Set Pen Colour Make Colour (0,0,0)
frame rect 0,0 to 640,480
hide mouse
Fade Up

int key
int xPlayer = 0
int yPlayer = 0
int keyUp = 1
int keyDown = 2
int keyRight = 3
int keyLeft = 4
'relatif au joueur
Load images 128
int xPlayer =25
int yPlayer =25
int playerSpriteID = 0

while not mouse button
if Up
key = keyUp
end if
if Down
key = keyDown
end if
if Right
key = keyRight
end if
if left
key = keyLeft
end if

if key = keyUp
yPlayer = yPlayer + 1
Sprite playerSpriteID, xPlayer ,Yplayer ,0
end if
if key = keyDown
yPlayer = yPlayer - 1
Sprite playerSpriteID, xPlayer ,Yplayer ,0
end if
if key = keyRight
xPlayer = xPlayer + 1
Sprite playerSpriteID, xPlayer ,Yplayer ,0
end if
if key = keyLeft
xPlayer = xPlayer - 1
Sprite playerSpriteID, xPlayer ,Yplayer ,0
end if
Draw frame
wend

10-13-2002 18:05

Posted by:
Mark Tully

Find more posts by Mark Tully

Sprites

Copy of my email reply

Hi there,

I had a quick look at your code and I think I can see the problem.

You want to move the 'sprite' statement to be just before the 'draw frame' command, they don't need to be inside the 'if' statements. The reason you're not seeing the sprite is because all the commands to draw the sprite are only executed when you're pressing either up down left or right. Once the sprite is set with the sprite command it will remain on screen until you use the 'sprite off' command. You can use a sprite command every frame to reposition or change the image of the sprite.

Your example could be done as follows:

int x=100,y=100

graphics mode 640,480
load images 128

while not mouse button
if left then x=x-1
if right then x=x+1
if up then y=y-1
if down then y=y+1

sprite 0,x,y,0
draw frame
wend


If you have any more questions on TNT Basic, the best place to go is to our website community forums, there you can discuss the questions with other TNT Basic users who are also learning the language, this has the benefit that everyone can learn from each other.

Please see http://www.tntbasic.com/community/forums/index.php

Thanks and enjoy TNT Basic!

Mark

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.