sprite help

Blitz3D Forums/Blitz3D Beginners Area/sprite help

melonhead(Posted 2011) [#1]
how do you mask a sprite

im tring to find out how to mask a sprite im testing out sprites and having a little bit of a hard time in masking them.

here the code i have so i can test out the sprite loading up


Graphics3D 640,480


cam = CreateCamera()
MoveEntity cam,0,0,-5

sp = LoadSprite("itom_sprites/fire_a.bmp")
SpriteViewMode sp,4 ,

While Not KeyDown(1)
If KeyDown(200) Then
MoveEntity sp,0,0,.1
EndIf
If KeyDown(208) Then
MoveEntity sp,0,0,-.1
EndIf


UpdateWorld
RenderWorld
Flip

Wend
End


Warner(Posted 2011) [#2]
LoadSprite has flags that you could try. Ie: ..
sprite = LoadSprite("masked.bmp", 1+4)
.. should make all black pixels in the sprite transparent.


melonhead(Posted 2011) [#3]
uuumm im using some black in my sprites im using a pink color for the background for everything so i can mask it


stayne(Posted 2011) [#4]
MaskImage handle,red,green,blue

IDE's help area is your friend.


melonhead(Posted 2011) [#5]
MaskImage for some reason doesn't work on sprites. it work for 2d coding but for3d it doesn't work right


GfK(Posted 2011) [#6]
MaskImage for some reason doesn't work on sprites.
That's because sprites and images are two entirely different things.

A sprite is type of quad in 3D space with a 2D image applied as a texture, whereas an image is simply a rectangular block of data that contains said image.

Its been years since I used Blitz3D but I think you might have to use LoadTexture() and TextureFilter() in combination with CreateSprite(), before manually applying the texture to the sprite.


Warner(Posted 2011) [#7]
You could replace all the black pixels by pixels with the color (1,1,1), then replace the pink pixels by black pixels.
Or you could replace all the pink pixels by pixels with an alpha of 0, then save the image as .png. This can be done in a more elaborate imaging program, such as Photoshop, pixlr.com or the gimp, not MsPaint.


Ross C(Posted 2011) [#8]
I have a function in my code archive entry to do this. Pixels are masked based on the their alpha values, not their colour. This function will iterate through all the pixel (texels) and change the ones that match the colour you specify.

Oh and you will need to create sprite, then load texture, then apply the texture to the sprite, so you can actuall access the texture.

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

Last edited 2011


melonhead(Posted 2011) [#9]
wow that help ROSS C i even got the animation working working with it as well just got to find out how to make it so when it hit a wall it randomly goes and other direction. im not really good with the TO, WHILE, WHEN, FOR commands.


melonhead(Posted 2011) [#10]
it looks something like this right now


Graphics3D 640,480

cam = CreateCamera()
MoveEntity cam,0,0,-5
cube = CreateCube()
MoveEntity cube ,0,0,1

sp = CreateSprite()
fire =LoadAnimTexture ("itom_sprites/fire.tga",63,64,64,0,2 )

While Not KeyDown(1)
EntityTexture sp,fire,frame
frame=MilliSecs()/150 Mod 2


MoveEntity sp ,Rnd (.06,-.06),Rnd (.06,-.06),Rnd (.06,-.06)




If KeyDown(200) Then
MoveEntity sp,0,0,.1
EndIf
If KeyDown(208) Then
MoveEntity sp,0,0,-.1
EndIf



RenderWorld:Flip

Wend
End

Last edited 2011

Last edited 2011