arrays/lists with animsprite

Just starting out? Need help? Post your questions and find answers here.
Cammar
New User
New User
Posts: 8
Joined: Mon Mar 20, 2006 2:55 pm

arrays/lists with animsprite

Post by Cammar »

I am using the animsprite lib for my animation (kicks ass by the way), its saving me lots of time but I want to load my sprites a little more dynamically. As far as I know the only way to create animsprites is to use unique variable names

Code: Select all

CreateAnimSprite(Name.AnimSprite, 1, 75, 75)
What I'm trying to acheive is something more like

Code: Select all

CreateAnimSprite(Array(1).AnimSprite, 1, 75, 75)

Or

CreateAnimSprite(List()\ID.AnimSprite, 1, 75, 75)
I'm running into syntax errors with a few really simple tests using the above methods. Does any one want to share the correct way of doing this?

Thanks
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

I can't test the following because I do not possess the library in question, but try the following:

Code: Select all

NewList Soldiers.AnimSprite()
AddElement(Soldiers())
CreateAnimSprite(Soldiers(), 1, 75, 75)
or

Code: Select all

Dim Soldiers.AnimSprite(10)
CreateAnimSprite(Soldiers(1), 1, 75, 75)
I may look like a mule, but I'm not a complete ass.
Cammar
New User
New User
Posts: 8
Joined: Mon Mar 20, 2006 2:55 pm

Post by Cammar »

Both seem to work just fine, thanks for the help. Any one have any semi-advanced examples using animsprite lying around that I could get a look at?
Cammar
New User
New User
Posts: 8
Joined: Mon Mar 20, 2006 2:55 pm

Post by Cammar »

Right...so a new problem regarding the AnimSprite lib has appeared. I have a sprite with 4 directions, when it moves I want it to animate (easy enough) and when it's not moving I want to display the first frame only, easy enough again just have to se set the frame manually each time. When I set the frame manually I get a flicker every so often, I knocked up this example to demonstrate:

Code: Select all

InitSprite()
InitMouse()
InitKeyboard()
UsePNGImageDecoder()

Global Glb_ScreenWidth, Glb_ScreenHeight
Glb_ScreenWidth = 800
Glb_ScreenHeight = 600

OpenWindow(0,0,0,Glb_ScreenWidth,Glb_ScreenHeight,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"") 
OpenWindowedScreen(WindowID(0),0,0,Glb_ScreenWidth,Glb_ScreenHeight,0,0,0) 

CreateSprite(1, 60, 30)
StartDrawing(SpriteOutput(1))
  Box(0,0,30,30,RGB(255,0,0))
  Box(30,0,30,30,RGB(0,0,255))
StopDrawing()

TransparentSpriteColor(1,255,0,255)
CreateAnimSprite(big.AnimSprite,1,30,30,100)


Repeat 

  
  ExamineKeyboard()
  
  ClearScreen(0,0,0) 
  
  SetAnimFrame(big, 1)
  DisplayAnimSprite(big,100,100)

  frame = CurrentAnimFrame(big)

  StartDrawing(ScreenOutput())
   
   DrawText("Current Frame: " + Str(frame))
  StopDrawing()
  
  FlipBuffers()  

  If KeyboardPushed(#PB_Key_Escape)   ; press Esc to quit
    End
  EndIf
ForEver  
End
Why does the sprite flicker like that? I'm setting the frame to 1 each cycle before the draw command. :(
Post Reply