TNT Basic Forums > Programming Q&A
Newbie question
< Last Thread     Next Thread >
Thread        Post A Reply

01-05-2003 15:09

Posted by:
Ashlin Aronin

Click Here to Email Ashlin Aronin   Find more posts by Ashlin Aronin

I have a two sprites. I want one's image to change every time it goes over the other. How can I do this?

01-06-2003 09:15

Posted by:


Click Here to Email mark_667   Find more posts by mark_667


This can be done fairly easily in TNT by using the collision detection function, and then an if statement. This could go something like...

HitOtherSprite=true then
x=Sprite (x) 'returns current sprite position of whatever value is put in the brackets, this will make sure it is put in the same place.
y=Sprite (x)
Sprite off 'Turns old one off
Sprite 'Replaces it
end if

Try one of the downloadable tutorials for collision detection coding examples and just past in the bits you need. Hope this helps,

01-06-2003 15:39

Posted by:
Ashlin Aronin

Click Here to Email Ashlin Aronin   Find more posts by Ashlin Aronin

Thanks for the help, though I guess I should have been more specific...what I meant was I want to change the image of the sprite every time it passes over the other sprite. I want it to get hurt more every time it touches the other sprite. Thanks!

01-06-2003 16:44

Posted by:

Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

you should define one variable such as energy that measures the health of the sprite you want to get hurt,
then a variable "image" that determines the sprite graphics you want to use:

in the big loop:

sprite 0,x,y,image 'here is the sprite to be damaged, it is drawn with the graphics specified by the number "image". (Look in your graphics section, the pictures on the right have a number: the picture "image" will be used.)

if sprite col 0,theothersprite>-1 then energy=energy-1

if energy=10 then image=0 (this is the picture you want to use)
if energy>=6 and energy<=9 then image=1
and so on.

when sprite 0,x,y,image is called, it will be drawn with the "image" image.

Note that this loop takes away energy at every frame, so it goes down very quick. You can put a variable that stops the energy loss if you have already been hit in the last second or so, or you can put much energy

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.