how can i make the sprites dissapear?

Blitz3D Forums/Blitz3D Programming/how can i make the sprites dissapear?

Gurra(Posted 2007) [#1]
hi, i'm making a very simple FPS. and i have made a sprite appear where you shoot(like dirt or somthing), but i want it to dissapear after like 0.2 seconds or something like that, but
i don't know how to do that :/

the code i use:

If MouseHit(1)

CameraPick (camera1,siktx+15,sikty+15)
hitx=PickedX#()
hity=PickedY#()
hitz=PickedZ#()

EndIf

dirt=LoadSprite("dirt.bmp",4)
ScaleSprite dirt,0.5,1
PositionEntity dirt,PickedX#(),PickedY#()+f1,PickedZ#()


semar(Posted 2007) [#2]
Hi Gurra,
1) first of all, I would suggest you to load your sprite at the beginning of your program. Then, when you need to show it, use PositionEntity.

In case you need more instances of your sprite, just use CopyEntity. This way you use the LoadSprite only once in your code, and that is good practice, since any Load... command slows down the program.

2) to make any entity to disappear - and a sprite is treated like an entity - you have two possibilities: HideEntity and FreeEntity.

The first one just hide the entity, but it remains in memory (that is, you can later show it again). The second one deletes it permanently, and releases the associated memory for it.

Hope this has sense for you,
Sergio.


Mortiis(Posted 2007) [#3]
Just a quick messy example with types.I don't have the chance to try it now so there may be errors.I have to run take care cya :)


Type tDirt
    field sprite$
    sprite fadeout#
end type

global sDirt.tDirt = new tDirt

sDirt\fadeout# = 1

sDirt\sprite = LoadSprite("dirt.bmp", 4)
ScaleSprite sDirt\sprite,0.5, 1

hideentity sDirt\sprite

while not keyhit(1)

    if mousehit(1)
        CameraPick(camera1, siktx + 15, sikty + 15)
    
        sDirt2.tDirt = new tDirt
        sDirt2\sprite = copyentity(sDirt\sprite)

        sDirt2\fadeout = 1.0
        
        positionentity sDirt2\sprite, pickedx(), pickedy()+f1, pickedz()
    endif

    for sDirt2.tDirt = each tDirt
        entityalpha sDirt2\tDirt, sDirt2\fadeout
        sDirt2\fadeout = sDirt2\fadeout -.5

        if sDirt2\fadeout = 0 then
            freentity sDirt2\sprite
            delete(sDirt2)
        endif
    next

wend



H&K(Posted 2007) [#4]
Leave them with your car keys.
Or in a room with children