Hi, I have an Animation class that should be able to alter a reference to an image (which is in a Sprite Class).
Strict
Import mojo2
Class MyApp Extends App
Field sprite:Sprite
Field canvas:Canvas
Field animation:Animation
Method OnCreate:Int()
canvas = New Canvas
sprite = New Sprite
sprite.image = Image.Load("player.png")
Local frames:= Image.LoadFrames("player_action.png", 3, False, 0, 0)
animation = New Animation(sprite.image, frames)
Return 0
End
Method OnUpdate:Int()
animation.Update()
Return 0
End
Method OnRender:Int()
canvas.Clear()
canvas.DrawImage(sprite.image, 100, 100)
canvas.Flush()
Return 0
End
End
Class Sprite
Field image:Image
End
Class Animation
Method New(image:Image, frames:Image[])
Self.image = image
Self.frames = frames
End
Method Update:Void()
time += 1
time = time Mod 60
If time > 40
image = frames[2]
Elseif time > 20
image = frames[1]
Else
image = frames[0]
End
End
Field image:Image
Field frames:Image[]
Field time:Int
End
Function Main:Int()
New MyApp
Return 0
End
The logic works, but the image reference stays the same in the sprite. Do I really have to to do sprite.image to change the reference?
|