Animate Object

Monkey Forums/Monkey Programming/Animate Object

darky000(Posted 2013) [#1]
Hello,

I am fairly new to this game creation and I searched the forum for answers and it seems it's a bit complicated for my understanding so I apologize if my question has been answered in some way.

How do I change the image of an object?


MikeHart(Posted 2013) [#2]
Define object in your context! Every image is per definition an object (instance of the class Image). When you load an Image in a specific way, you can tell Monkey that the image is actually a row of "sub images" (frames), which then you can let Monkey draw separately. Look into LoadImage and DrawImage to see what it takes to draw sub frames.

Or are you talking about a specific 3rd party framework?


Midimaster(Posted 2013) [#3]
normaly you draw images, but not objects in Monkey.
DrawImage Girl,X,Y

If you use as source a image-strip including 10 pictures of the girl organized in f.e 100x100pix frames, you could use the command....

DrawImageRect Image,X,Y,SourceX,SourceY,W,H


..in our own new function:

Method OnRender()
     ....
     DrawImageFrame Girl, X, Y, Frame
     ....
End

Function DrawImageFrame:Void(Girl:Image, X%, Y%, Frame%)
     DrawImageRect Girl,X,Y,Frame*100,0,100,100
End


If you have organized the actors in types you would do the same:

Class TPeople
   Field Img:Image, Frame%, MaxFrame%
   Field X%,Y%,W%,H%

   Method Draw()
        DrawImageRect Img,X,Y,Frame*100,0,100,100
        Frame=(Frame+1) Mod MaxFrame
   End
End




If you have the frames of the same actor in single file, I would create an array for the images an draw only one to the screen:

 Field Girl:Image[10]

Method OnCreate()
     Girl[0]=LoadImage("....
     Girl[1]=LoadImage("....
     ....
End


Method OnRender()
    .....
    DrawImage Girl[Frame],X,Y
End



darky000(Posted 2013) [#4]
@Mike - I'm using the fantomEngine framework.

@MidiMaster - thanks for that simple explanation. I'll try this in a bit later... I'm currently away right now.


MikeHart(Posted 2013) [#5]
Ok :-)

Did you got the my book? In "At the docks" the game has an animated object. Look there if you have the book.

And

ftEngine.CreateAnimImage:ftObject(atl:Image, frameStartX:Int, frameStartY:Int, frameWidth:Int, frameHeight:Int, frameCount:Int, xpos:Float, ypos:Float, _ucob:Object=Null)


is the command you create/load an animated image object with. All the frames of an image have to be in one file. If you want to exchange the images of a ftObject, then just do something like this:

yourFtObject.img = YourImageHandle


Personally I would not do it like that.


darky000(Posted 2013) [#6]
Thanks Mike! :)

Found it and works! Learned something today.

Thanks to Midi too for the basics of animating in monkey. I'm loving this community already.