Sprite Entities Cont Entities allow you to take the sprite and build more complex meshes from it. In this tiny example, we're taking single frame sprite and adding a bunch of frames to form a ring of sprites out of 1 sprite . These can then be rotated, scaled, moved and ultimately even collided with !
The main benefit of entities is their batch friendly, so the entire sprite drawn, is only
one draw call. Where, normally you'd have to draw each face separately.
load3Dimage "animal.jpg",1
load3dimage "particle_white.bmp",2
; Create the foreground sprite + mesh around with it's mesh
CreateSprite 1
positionsprite 1,400,300
SpriteDrawmode 1,2
SpriteImage 1,1
centerspritehandle 1
SpriteVertexQuantity 1,8
SpriteFaceQuantity 1,8
PokeSpriteVertex 1, 4, 200,0,0
PokeSpriteVertex 1, 5, 300,0,0
PokeSpriteVertex 1, 6, 300,300,0
PokeSpriteVertex 1, 7, 200,300,0
PokeSpriteFaceVerts 1,1,4
PokeSpriteface 1,1,0,4,0,0,$ffff00
PokeSpriteface 1,1,1,5,1,0,$ffff00
PokeSpriteface 1,1,2,6,1,1,$ffffff
PokeSpriteface 1,1,3,7,0,1,$ff00ff
; deform the vertex 0 and 2 top left and bottom right
pokespritevertex 1,0,-30,-40,0
pokespritevertex 1,2,130,290,0
; POke Face 0 of this Sprite
PokeSpriteface 1,0,2,2,1.0,1.0,$ff00ff
; Create a bunch of entity sprites. These create rings of sprite frames
For lp=0 to 100
me= MakeParticleSprite(2,rnd(800),rnd(600),rndrange(10,20))
next
Do
Cls 0
drawallsprites
turnsprite 1,0.05
turnsprite me,0.15
scalesprite 2,1+cos(angle#)
print Fps()
angle#=angle#+1
Sync
loop
Function MakeParticleSprite(ThisIMage,Xpos#,Ypos#,points)
ThisSprite=NewSprite(Xpos#,Ypos#,ThisIMage)
SpriteDRawMOde ThisSprite, 2+16
SpriteVertexQuantity thisSprite,(Points+1)*4
SpriteFaceQuantity thisSprite,(Points+1)
angleStep#=360.0/points
size=32
For lp=0 to points-1
angle#=wrapangle(angle#,anglestep#)
Radius#=100
SetVerts(ThisSprite,VertexOffset,Angle#,Radius#,Size,wrapangle(angle#,-45))
SetFace(ThisSprite,ThisFace,VertexOffset,RndRgb())
VertexOffset=VertexOffset+4
inc thisface
next
EndFUnction ThisSPrite
Function SetVerts(ThisSprite,VertexOffset,Angle#,Radius,Size,Rotation)
CenterX#=CosNewValue(0,angle#,Radius)
CenterY#=SinNewValue(0,angle#,Radius)
For lp=0 to 3
X#=CosNewValue(CenterX#,Rotation,Size)
Y#=SinNewValue(CenterY#,Rotation,Size)
PokeSpriteVertex ThisSprite,VertexOffset,X#,y#,z#
Rotation=wrapangle(Rotation,90)
inc VertexOffset
next
EndFunction
Function SetFace(ThisSprite,ThisFace,VertexOffset,ThisColour)
PokeSpriteFaceVerts ThisSprite,ThisFace,4
PokeSpriteface ThisSprite,ThisFace,0,VertexOffset+0,0,0,ThisColour
PokeSpriteface ThisSprite,ThisFace,1,VertexOffset+1,1,0,ThisColour
PokeSpriteface ThisSprite,ThisFace,2,VertexOffset+2,1,1,ThisColour
PokeSpriteface ThisSprite,ThisFace,3,VertexOffset+3,0,1,ThisColour
EndFunction