How to remove a sprite from the screen?

Previous topic - Next topic

Ungre

Hi.

Sorry for my bad english I do my best.

I'm new to GLBasic and I would like to know,how it possible to remove a sprite form the screen?

For example,I load and draw 2 sprites int the same position on the screen.

LOADSPRITE "sprite1.jpg",1
LOADSPRITE "sprite2.jpg",2

DRAWSPRITE 1,100,100
DRAWSPRITE 2,100,100

And let say after 10 sec,I want to remove the sprite with ID 2 from the screen and keep only the sprite with ID 1.

I have been tried to load a new "empty" sprite to the place of sprite2 (LOADSPRITE "nosprite",2),but the result is a white box.Looks weird

Is there any command or technics how to remove a drawn sprite form the screen?

Thanks.



CptnRoughnight

You habe to clear the screen and draw the sprites in a loop.
So you can choose wich one is visible by drawing this Sprite.

p.s. my english isn't the best too :)


matchy

To wait 10 seconds:
Code (glbasic) Select

SLEEP 1000

Ian Price

Use a basic timer for the sprites

Code (glbasic) Select

LOCAL timer=0

WHILE TRUE

INC timer

DRAWSPRITE 1,100,100

IF timer<6000 THEN DRAWSPRITE 2,100,100 // Change the timer value to slow down/speed up delay.

SHOWSCREEN

WEND


Something like that?
I came. I saw. I played.

Ungre

Thanks for the replays.

Dr.Damn Fist:

I'm not sure that to clear the screen is the way I'm looking for.
If I'm creating let say a platform shooter and I want the enemy sprite to disappear when it dies,it sound a bit complicated for me to clear the screen and redraw everything because only 1 sprite.
Mainly if I don't know which enemy going to die or going to die any at all.
But maybe I misunderstand what you say  :D

matchy:
I know how to wait 10 sec,my problem is that,I don't know how to remove a sprite  :P

Ian Price:
The Timer works great.Thanks  :good:
But I'm not sure how well it going to work in different situations.

I used Game Editor before,and I can remove a sprite by using a simple DESTROYACTOR command.I'm looking for a similar easy way to do it in GLBasic,but as far I can see,ther is no similar command in GLBasic  ;/
But a timer will be good for now  :)

Thanks again.

Ian Price

I think you misunderstand the way GLB works.

GLB doesn't just draw an image and hold it on the screen until it changes - every single image you draw is redrawn every single frame. You can turn off screen clearing so everything stays on the screen, but then you'll have copies of every images and trails where it moved to.

What you need to do is just not draw whatever it is you don't want to draw whenever you don;t want it drawn.

To do something similar to your GameEditor you need to create the sprites as TYPEs. Each TYPE is independent of everything else and you can make them disappear (or perform other tasks) when certain timers or situations occur.

TYPEs are an invaluable asset to many programming languages nowadays and to understand them is to hold real power over the language you are using.
I came. I saw. I played.

hardyx

#6
Videogames are like the cinema, they are composed of hundreds of frames drawed at 30 or 60 frames/second. You will have a loop in your program where you'll draw all the screen in each frame. Check the GLBasic tutorials in the help manual and example projects to understand better.

matchy

Quote from: Ungre on 2012-Sep-19
matchy:
I know how to wait 10 sec,my problem is that,I don't know how to remove a sprite  :P

It seem you should be learning how to DRAWRECT and DRAWLINE first.

hardyx

#8
Quote from: Ungre on 2012-Sep-19
Ian Price:
The Timer works great.Thanks  :good:
But I'm not sure how well it going to work in different situations.
Change the condition in the Ian code for what you want to do, for example showing the enemy sprite when he is alive, and not show when he dies. Check the state in every loop and put to 0 if you want the sprite disappears. You can clear the screen with the orders CLEARSCREEN or DRAWRECT at the beggining of your drawing code.

Code (glbasic) Select
IF enemy_alive = 1 THEN DRAWSPRITE 2,100,100

Ungre

Thanks all the replies.I'm very thankful.
Great community indeed.
Yes I need to learn a lot about GLBasic to understand how it works and to know how to use it effectively.But it should not be a problem with such a super community  ;)

Falstaff

I think I'll take notes on what to teach to my upcoming class.. :)