sprite

merli

Member
Licensed User
Hello Gents

I have problem with sprites and I don't know where I am doing something wrong
I am trying to create Isometric game engine using Sprite 1.3 library

I am creating sprites at runtime like this

AddObject("spr"&index,"Sprite")

and initializing them and assigning bitmaps

Control("spr"&index,"Sprite").New3 .....

and finally adding them to GW and setting to positions by this:

game.SpriteAdd(Control("spr"&ind,"Sprite").Value)
Control("spr"&ind,"Sprite").X=objects(ind).xbmp
Control("spr"&ind,"Sprite").Y=objects(ind).ybmp

Some of this sprites will be not moveable some of them are moveable. As this is isometric space some sprites are in front of others and some of them are behind. For each game tick I like to do this:

1) delete each movable sprite from GW
2) move them by set Sprite.X and Sprite.Y - of course follows collision detection etc ...
3) recalculate order of all objects (sprites) in scene
4) Insert each movable sprite into specific index into collection of sprites in GW
5) GW.tick

I created Subs:

Sub Sprite_Delete(index)
Control("spr"&index,"Sprite").MarkedForDelete=True
game.DeleteMarkedSprites
End Sub

Sub Sprite_Insert(sprite,index)
sprite_tmp.Value=game.GetSprite(game.SpritesCount-1)
For i=game.SpritesCount-1 To index+1 Step -1
game.SpriteReplace(game.GetSprite(i-1),i)
Next
game.SpriteAdd(sprite_tmp.Value)
game.SpriteReplace(Control(sprite,"Sprite").value,index)
End Sub

And I call them for testing like this

Sub Timer1_Tick
If counter>0 Then
Sprite_Delete(3) 'delete spr3 from gw
Remove_Object(3) 'delete from sorted objects
objects(3).y=objects(3).y+ystep 'move object to y axis by 3 pixels in 3d space
Add_Object(3) 'add object No 3 to sorted list
ind=Find_Object_Index(3) 'find position of object No 3 in sorted list
Sprite_Insert("spr3",ind) 'insert sprite of object 3 to its new position

.... there are some lines to convert position in 3d space to position in 2d space

Control("spr3","Sprite").X=objects(3).xbmp 'set new 2d x y position of sprite
Control("spr3","Sprite").Y=objects(3).ybmp
counter=counter-1 'decrement couter
Else
ystep=-ystep 'if couter expires reverse move
counter=20 'and setup new counter
End If
Game.Tick
End Sub

What I think it should do is move sprite No 3 up and down by timer tick. What actually happens is that sprite No 3 is deleted from GW but never reappears on Form. It just disappears like the wind. When I thy to debug I found that GW.spritescount is all the time the same (6) what is number of sprites added. And also when I look into GW.spriteindex(spr3) is OK. Sprite is added on good position. Just will not show on screen. Where the problem can be? Please help

Update:
Problem solved .... a few moments I wrote this i found that I need to set this sprite active:
Control("spr3","Sprite").IsActive=True
Any1 of you knows why? Does MarkForDelete and DeleteMarkedSprites make sprite inactive?
 
Last edited:
Top