Page 1 of 1
AnimateSprite3D for Windows Mac and Linux
Posted: Sun Jul 24, 2011 7:33 am
by J. Baker
Here's a small procedure for animating Sprite3D. Download zip file for an example.
DOWNLOAD EXAMPLE
Code: Select all
Structure Sprite3DCalculations
Animate.l
Loop.l
LoopStart.l
EndStructure
Procedure AnimateSprite3D(Sprite3D, SpriteNumberFrom, SpriteNumberTo, FpsDelay) ;FpsDelay must have a value of 1 or higher in order to playback fps accurately
Static Dim Sprites3D.Sprite3DCalculations(99) ;99 can be change to however many AnimatedSprite3D's you want to use
If Sprites3D(Sprite3D)\LoopStart = 0 ;as it should when first started
Sprites3D(Sprite3D)\Loop = FpsDelay ;we make sure we start the first sprite frame without delay or error
Sprites3D(Sprite3D)\LoopStart = 1 ;then we kill it as this is only needed to start with
EndIf
If Sprites3D(Sprite3D)\Loop = FpsDelay ;if true we change to the next sprite frame
If Sprites3D(Sprite3D)\Animate = (SpriteNumberTo - SpriteNumberFrom) +1 ;if the last sprite frame is used we need to restart from the first sprite frame
Sprites3D(Sprite3D)\Animate = 0 ;reset Animate back to 0
EndIf
CreateSprite3D(Sprite3D, SpriteNumberFrom + Sprites3D(Sprite3D)\Animate) ;this keeps updating the sprite frames with the same Sprite3D
Sprites3D(Sprite3D)\Animate +1 ;getting ready for the next sprite frame
Sprites3D(Sprite3D)\Loop = 1 ;restart the FpsDelay loop
Else
Sprites3D(Sprite3D)\Loop +1 ;if the loop doesn't = FpsDelay we add +1 until it does
EndIf
EndProcedure
Re: AnimateSprite3D for Windows Mac and Linux
Posted: Sun Jul 24, 2011 9:26 am
by J. Baker
EDIT: Removed this code as its no longer needed.
Re: AnimateSprite3D for Windows Mac and Linux
Posted: Sun Jul 24, 2011 10:28 am
by J. Baker
EDIT: removed comments as they pertained to the old procedure.
Re: AnimateSprite3D for Windows Mac and Linux
Posted: Sun Jul 24, 2011 10:53 am
by DoubleDutch
Thanks for this.

Re: AnimateSprite3D for Windows Mac and Linux
Posted: Sun Jul 24, 2011 7:57 pm
by J. Baker
Ok, new procedure updated on the first post. It now includes the FpsDelay within it. So if your games fps is 60 and your AnimateSprite3D is 15 fps, you would just put a 4 as the FpsDelay value. I'm sure you get it.

Re: AnimateSprite3D for Windows Mac and Linux
Posted: Sun Jul 24, 2011 8:11 pm
by J. Baker
DoubleDutch wrote:Thanks for this.

Your welcome!

Re: AnimateSprite3D for Windows Mac and Linux
Posted: Mon Jul 25, 2011 12:36 am
by J. Baker
Ok, small code change. FpsDelay must have a value of 1 or higher. As no frame starts at 0 because it doesn't exist. Otherwise a delay of 4 would have actually been 5. I updated the code above and the download example.

Re: AnimateSprite3D for Windows Mac and Linux
Posted: Wed Jul 27, 2011 9:57 am
by J. Baker
Ok, I made a big mistake of only testing this with sprite numbers from 1 to 15. I wasn't even thinking like if sprite numbers 31 to 45 or something were used. But the code has been fixed and I added better comments. My apologies.

Re: AnimateSprite3D for Windows Mac and Linux
Posted: Fri Jul 29, 2011 8:50 am
by J. Baker
Here's another example with a smaller procedure but you add your own delays in the repeat section.
Will work with the same images in the download example from above.
Code: Select all
Structure Sprite3DCalculations
Animate.l
EndStructure
Procedure AnimateSprite3D(Sprite, SpriteNumberFrom, SpriteNumberTo)
Static Dim Sprites3D.Sprite3DCalculations(99)
If Sprites3D(Sprite)\Animate = (SpriteNumberTo - SpriteNumberFrom) +1
Sprites3D(Sprite)\Animate = SpriteNumberFrom -1
EndIf
Sprites3D(Sprite)\Animate +1
CreateSprite3D(Sprite, Sprites3D(Sprite)\Animate)
EndProcedure
If InitKeyboard() = 0
MessageRequester("Error!", "Keyboard system can not be initialized.", 0)
End
EndIf
If InitSprite() = 0
MessageRequester("Error!", "Sprite system can not be initialized.", 0)
End
EndIf
If InitSprite3D() = 0
MessageRequester("Error!", "Sprite3D system can't be initialized.", 0)
End
EndIf
UsePNGImageDecoder()
If OpenScreen(1280, 720, 32, "Sprite3D Animated", #PB_Screen_SmartSynchronization)
CatchSprite(1, ?Pic1, #PB_Sprite_Texture | #PB_Sprite_AlphaBlending)
CatchSprite(2, ?Pic2, #PB_Sprite_Texture | #PB_Sprite_AlphaBlending)
CatchSprite(3, ?Pic3, #PB_Sprite_Texture | #PB_Sprite_AlphaBlending)
CatchSprite(4, ?Pic4, #PB_Sprite_Texture | #PB_Sprite_AlphaBlending)
CatchSprite(5, ?Pic5, #PB_Sprite_Texture | #PB_Sprite_AlphaBlending)
CatchSprite(6, ?Pic6, #PB_Sprite_Texture | #PB_Sprite_AlphaBlending)
CatchSprite(7, ?Pic7, #PB_Sprite_Texture | #PB_Sprite_AlphaBlending)
CatchSprite(8, ?Pic8, #PB_Sprite_Texture | #PB_Sprite_AlphaBlending)
CatchSprite(9, ?Pic9, #PB_Sprite_Texture | #PB_Sprite_AlphaBlending)
CatchSprite(10, ?Pic10, #PB_Sprite_Texture | #PB_Sprite_AlphaBlending)
CatchSprite(11, ?Pic11, #PB_Sprite_Texture | #PB_Sprite_AlphaBlending)
CatchSprite(12, ?Pic12, #PB_Sprite_Texture | #PB_Sprite_AlphaBlending)
CatchSprite(13, ?Pic13, #PB_Sprite_Texture | #PB_Sprite_AlphaBlending)
CatchSprite(14, ?Pic14, #PB_Sprite_Texture | #PB_Sprite_AlphaBlending)
CatchSprite(15, ?Pic15, #PB_Sprite_Texture | #PB_Sprite_AlphaBlending)
Sprite3DAniDelay = 4
ImageSize = 256
Repeat
SetFrameRate(60)
FlipBuffers()
ClearScreen(RGB(0,0,0))
Start3D()
If Sprite3DAniDelay = 4 ;added a delay since the animation is only 15 fps.
AnimateSprite3D(1, 1, 15)
Sprite3DAniDelay = 0
EndIf
Sprite3DAniDelay +1
ZoomSprite3D(1, ImageSize +zoom.d, ImageSize +zoom.d)
DisplaySprite3D(1, 32, 32)
Stop3D()
If ImageSize +zoom.d < 512
zoom.d +0.5
EndIf
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
Else
MessageRequester("Error!", "Can not open a 1280x720 - 32 bit screen.", 0)
EndIf
End
DataSection
Pic1: IncludeBinary "images/star00001.png"
Pic2: IncludeBinary "images/star00002.png"
Pic3: IncludeBinary "images/star00003.png"
Pic4: IncludeBinary "images/star00004.png"
Pic5: IncludeBinary "images/star00005.png"
Pic6: IncludeBinary "images/star00006.png"
Pic7: IncludeBinary "images/star00007.png"
Pic8: IncludeBinary "images/star00008.png"
Pic9: IncludeBinary "images/star00009.png"
Pic10: IncludeBinary "images/star00010.png"
Pic11: IncludeBinary "images/star00011.png"
Pic12: IncludeBinary "images/star00012.png"
Pic13: IncludeBinary "images/star00013.png"
Pic14: IncludeBinary "images/star00014.png"
Pic15: IncludeBinary "images/star00015.png"
EndDataSection