Basic PNG Animation
Monkey Targets Forums/Flash/Basic PNG Animation
| ||
This is a really stupid question, but how do I make a basic looping animation? Here's my code:
Import mojo
Import monkey
Import "C:\Users\Joseph\Documents\MonkeyPro56\Sleeping Disorder\00001.png"
Import "C:\Users\Joseph\Documents\MonkeyPro56\Sleeping Disorder\00002.png"
Import "C:\Users\Joseph\Documents\MonkeyPro56\Sleeping Disorder\00003.png"
Import "C:\Users\Joseph\Documents\MonkeyPro56\Sleeping Disorder\00004.png"
Import "C:\Users\Joseph\Documents\MonkeyPro56\Sleeping Disorder\00005.png"
Import "C:\Users\Joseph\Documents\MonkeyPro56\Sleeping Disorder\00006.png"
Import "C:\Users\Joseph\Documents\MonkeyPro56\Sleeping Disorder\00007.png"
Import "C:\Users\Joseph\Documents\MonkeyPro56\Sleeping Disorder\00008.png"
Import "C:\Users\Joseph\Documents\MonkeyPro56\Sleeping Disorder\00009.png"
Import "C:\Users\Joseph\Documents\MonkeyPro56\Sleeping Disorder\00010.png"
Global ImageIndex:Int
Global ImageId01:Image
Global ImageId02:Image
Global ImageId03:Image
Global ImageId04:Image
Global ImageId05:Image
Global ImageId06:Image
Global ImageId07:Image
Global ImageId08:Image
Global ImageId09:Image
Global ImageId10:Image
Function Main:Int() ; New MyApp ; End
Class MyApp Extends App
Method OnCreate()
SetUpdateRate 60
ImageIndex=1
ImageId01=LoadImage("00001.png")
ImageId02=LoadImage("00002.png")
ImageId03=LoadImage("00003.png")
ImageId04=LoadImage("00004.png")
ImageId05=LoadImage("00005.png")
ImageId06=LoadImage("00006.png")
ImageId07=LoadImage("00007.png")
ImageId08=LoadImage("00008.png")
ImageId09=LoadImage("00009.png")
ImageId10=LoadImage("00010.png")
End
Method OnUpdate()
If ImageIndex>10 Then ImageIndex=1 Else ImageIndex+=1
End
Method OnRender()
If ImageIndex = 1 Then
DrawImage(ImageId01)
If ImageIndex = 2 Then
DrawImage(ImageId02)
If ImageIndex = 3 Then
DrawImage(ImageId03)
If ImageIndex = 4 Then
DrawImage(ImageId04)
If ImageIndex = 5 Then
DrawImage(ImageId05)
If ImageIndex = 6 Then
DrawImage(ImageId06)
If ImageIndex = 7 Then
DrawImage(ImageId07)
If ImageIndex = 8 Then
DrawImage(ImageId08)
If ImageIndex = 9 Then
DrawImage(ImageId09)
If ImageIndex = 10 Then
DrawImage(ImageId10)
End
End
|
| ||
| I dont think you have to import images If the animation is going too fast put a delay in there inbetween each animation-frame create some variables: animation_timer:Int=0 anim_frame:Int=1 anim_delay:Int=150 create an array of images called image_array:Image[50] then if MilliSecs() > animation_timer+anim_delay anim_frame=anim_frame+1 animation_timer=MilliSecs() if anim_frame>10 anim_frame=1 endif endif
Method OnRender()
DrawImage(image_array[anim_frame],0,0)
End
|
| ||
It gives me this error in the output tab:C:/Users/Joseph/Documents/MonkeyPro56/FlashRunner.monkey<77> : Syntax error - unexpected token '' Monkey runtime error: C:/Users/Joseph/Documents/MonkeyPro56/FlashRunner.monkey<77> : Syntax error - unexpected token '' I'm having a little trouble understanding. Could you please provide a little more code? I feel clueless. |
| ||
| heres the easiest was i know of but i bet someone else can give you something better.The code below works i tested it. There is no scaling or timing in it apart from setupdaterate 30 |
| ||
| OMG! It works! Thanks a ton! |