animated Images?

Monkey Forums/Monkey Programming/animated Images?

Jesse(Posted 2011) [#1]
is there a way to load animated images like BlitzBasic/Max? or an alternative for monkey?


matt(Posted 2011) [#2]
You want to look into the frames parameter of the LoadImage command

docs: index.html#/mojo.graphics/LoadImage


Jesse(Posted 2011) [#3]
Thanks a lot. I didn't realize all the information was in the documentation.


therevills(Posted 2011) [#4]
Does Monkey support sprite sheets that spans horizontal and vertical images?

Ive just loaded an image which contains 16 (32x32 pixels) sprites, 8 on the top row and 8 on the bottom row. And I used the command:

enemy1Img = LoadImage("aster32.png", 16, Image.MidHandle)


When I displayed the first frame it was messed up - I had to change the image to one long line of sprites.

BTW The size of the image is 256x64


Jesse(Posted 2011) [#5]
From Monkey documentation:

The frames of a multiple frame image must be laid out in a horizontal strip, in which case the width of the loaded image is the width of image file divided by the number of frames, and the height of the image is the height of the image file.



I believe Mar is looking into changing the something in LoadImage. From this thread:
http://www.monkeycoder.co.nz/Community/posts.php?topic=188

I believe he is going to redo the LoadImage format as I don't see any other way he can solve that problem.


therevills(Posted 2011) [#6]
Thanks Jesse... didnt read the doco there!

Yeah I saw your thread about the white images...


marksibly(Posted 2011) [#7]
Hi,

Actually, there may already be a solution!

Try something like:

Local atlas:=LoadImage( "blah.png" )
Local image:=atlas.GrabImage( 0,0,frame_w,frame_h,frame_count )

This should correctly 'wrap around' allowing you have multiple rows of frames instead of just a single row.


therevills(Posted 2011) [#8]
Yep that works! :)

Would be nice if there was one command to do it though :P


degac(Posted 2011) [#9]
What's wrong with
LoadImage(URL,width,height,frame_count)

?

edit:
I discovered there's no reference in the guide, and in the source code is marked as *deprecated* - but I dont' know why eliminate it, as it seems to work (and it's used by SetFont command too)


therevills(Posted 2011) [#10]
Thats only good for an image in a horizontal strip format.


degac(Posted 2011) [#11]
@Therevills

no, sorry, you are referring to the first variation of LoadImage

There are 2 different implementation (thanks overloading)

LoadImage(URL,frame_count)
LoadImage(URL,width,height,frame_count)

The second one is similar to the Blitz3d/BlitzMax one: URL can be a 'rectangular/boxed' image divided in X x Y images (of the same sizes)
So you can provide a 128x64 pixel images containg 32x32 pixels frames (frame_count is 4x2 = 8 frame)


taumel(Posted 2011) [#12]
I've used LoadImage and DawImageRect (where you have to deal with calculating the rect on your own) and it worked out pretty well: mno


therevills(Posted 2011) [#13]
Thanks degac...

Its funny as the code Mark provided is very similar to the code in graphics.monkey:

'deprecated!
Function LoadImage:Image( path$,frameWidth,frameHeight,frameCount,flags=Image.DefaultFlags )
	Local atlas:Image=New Image( path,1,0 )
	If atlas Return atlas.GrabImage( 0,0,frameWidth,frameHeight,frameCount,flags )
End



marksibly(Posted 2011) [#14]
Hi,

> LoadImage(URL,width,height,frame_count)

I don't like this version for 2 reasons:

* It creates an extra image 'behind the back' of the user.

* It could encourage people to loading atlases multiple times, wasting gfx mem.

In general, GrabImage should be preferred I think as it encourages 'image sharing'.

The above LoadImage is therefore currently 'deprecated' and marked for destruction!


therevills(Posted 2011) [#15]
So you are saying that we shouldn't be so lazy :P


marksibly(Posted 2011) [#16]
>So you are saying that we shouldn't be so lazy :P

Bingo!


therevills(Posted 2011) [#17]
:)

BTW Why "atlas"?


marksibly(Posted 2011) [#18]
Hi,

> BTW Why "atlas"?

It's a term often used in 3D to describe the practice of packing multiple anims/images/textures into one larger anim/image/texture.


therevills(Posted 2011) [#19]
Ta! Learn something new everyday :)

http://en.wikipedia.org/wiki/Texture_atlas