How do I use sprites?

Blitz3D Forums/Blitz3D Beginners Area/How do I use sprites?

Ace Killjoy(Posted 2008) [#1]
I'm having a terrible time learning about sprites.
I want to create a sprite for the flash at the end of my gun when it fires, but I don't know what to do.
I'm not sure how to make it so that the flash shows and the background does not (I'm guessing MaskImage but I'm not sure how to use that either).
If some one could explain how to set up a sprite like that it would help a lot.
PS: I use Correl Photo Paint to create my textures.


Terry B.(Posted 2008) [#2]
Well first, you load it.

Then to make it only show non-black parts, you do this.


LoadSprite("Sprite.bmp",4)



The 4 makes black transparent.


Ace Killjoy(Posted 2008) [#3]
Thanks, this sound better than MaskImage (though I still wish I could figure it out).
Are there any other numbers?
Also, is the sprite suposed to be in a certain format (I ask because I keep seeing refferences to .png or something)?


Terry B.(Posted 2008) [#4]
not neccessarily a certain format no. And as for other numbers:
Taken from Loadsprite's documents.
Note: four is masked, thats the one you want.



tex_flag (optional) - texture flag:
1: Color
2: Alpha
4: Masked
8: Mipmapped
16: Clamp U
32: Clamp V
64: Spherical reflection map




Ross C(Posted 2008) [#5]
You also have the 128 and 256 and 512 flags too.

Cubemapping - 128
Force VRAM - 256
Hi-Colour - 512


Ace Killjoy(Posted 2008) [#6]
Wow, I don't understand any of those.
But I did try what you suggested (I had always attempted to make them with a white background, not black) and it worked. Thanks.
The way I made it, the flag "4" didn't give the effect I wanted but having the flag as fasle worked just fine.

I'm not sure if this is a good idea but I'll try it anyway.
Rather than start another topic, I'll just ask this related question:
How can I make it so that the sprite flashes only for a split second?
I've tried making timers (via the Millisecs() command) but the sprite never dissapears.
Is there a better solution?


Ross C(Posted 2008) [#7]
Use hideentity in conjunction with your timers.

If you wish to change the mask colour of your sprite:

http://www.blitzbasic.com/codearcs/codearcs.php?code=1013


Ace Killjoy(Posted 2008) [#8]
Maybe this will help.
This is a Function that I made for this action (it doesn't work the way I want):


If you need to know where I said to activate the function then tell me.
Also, when I move around the terrain, the sprites keep popping up in different places.


IPete2(Posted 2008) [#9]
AceKilljoy,

Use a transparent png instead and use the 3 flag (colour and alpha) to load it. This will give you fade off to transparent, rather than yucky black - or mask colour.

In fact what you could do is texture a cone with a flare style texture - move it, resize it and alpha fade it as your character shoots - that would possibly look even better.

Best regards,

IPete2.


Ace Killjoy(Posted 2008) [#10]
When I save something as a .png, is it automatically transparent?
If not, I'm not sure how to do that.


Ace Killjoy(Posted 2008) [#11]
Should I start another topic?


Ross C(Posted 2008) [#12]
It's not the best texture format to use for alpha i've found. (maybe i'm not using the correct tools? I've had better luck with .dds textures)

Skidracer wrote a really good piece of code that outlines the mask area with the pixels of non masked colour closest to it, giving a great mask finish. I'm afraid i can't find it, but it's in the code archives.

You basically choose your mask colour for your texture (black i assume?), then send the texture across to the function.


Ace Killjoy(Posted 2008) [#13]
I got the sprite to work fine.
But I can't figure out how to flash it for a split-second and then hide it.
Also, when I move around, the sprite keeps popping up in different areas.


Ben(t)(Posted 2008) [#14]
your spite is moving in different places because of how you position it

Function burst(gun)
gunflash=LoadSprite("Burst 1.bmp")
EntityParent gunflash,gun

;===================
PositionEntitygunflash,EntityX(gun,1)-10,EntityY(gun,1)+80,EntityZ(gun,1)
;===================


;take out the -10,+80 and replace them below the rotateentity command with a moveentity command
RotateEntity gunflash,EntityPitch(gun,1),EntityYaw(gun,1),EntityRoll(gun,1)


PositionEntitygunflash,EntityX(gun,1),EntityY(gun,1),EntityZ(gun,1)

RotateEntity gunflash,EntityPitch(gun,1),EntityYaw(gun,1),EntityRoll(gun,1)
moveentity gunflash,-10,80,0

the sprite jumps because the position entity command refers to 0,0,0 in the map and moves the entity from there, moveentity moves the entity by however much you want, from its current position


Ace Killjoy(Posted 2008) [#15]
Unfortunatly, that made it worse.
I even tried taking the -10,+80 off of the PositionEntity command a leaving the MoveEntity command out and it still moved more than before.


Nate the Great(Posted 2008) [#16]
You could just use FreeEntity() and then reload and repostition the sprite every time it flashes. This might cause a bit of a slow down though. :)


GfK(Posted 2008) [#17]
I think you're confusing yourself talking about images and sprites as if they're the same thing - they are not.

There's no point whatsoever in reloading the sprite every time you fire the gun. Use HideEntity/ShowEntity, or EntityAlpha.


Ace Killjoy(Posted 2008) [#18]
Ya, I'm trying to use ShowEntity/HideEntity but I can't get the timers to work right.
I need a sample code or something because I'm really inexperienced in using timers.
Sorry if I'm being a pest about this.


xtremegamr(Posted 2008) [#19]

Global burst,bursttime,burststart

Function Burst()

;load the burst sprite, position it, etc. here
burst=True
burststart=Millisecs()

End Function

Function UpdateBurstTimer(burstsprite)

If burst then

If Millisecs()-burststart>=bursttime Then

burst=False
HideEntity(burstsprite)

End if

End If

End Function



Try this; this is kinda like the code I use to calculate FPS. Just set 'bursttime' to the amount of time you want the burst to appear, and call Burst(). Then, in the loop, run this:


If burst Then UpdateBurstTimer()




Ace Killjoy(Posted 2008) [#20]
This may sound extreemly noobish, but where do I set "bursttime" and call Burst()?
Also, do I do it like this:
bursttime=1
Burst()
?