Really rotate an image

Monkey Forums/Monkey Programming/Really rotate an image

Tazzy(Posted 2014) [#1]
Hi All,

I'm using FantomEngine for my game and I run into a problem with animations combined with TexturePacker spritesheets, which by design can be saved rotated on the canvas.

To fix that I need to really rotate an image, isntead of using the Matrix, or at least use an image as canvas so that I can rotate it myself. Is there any way in Monkey to do that, or is there another work-around without changing the FantomEngine source?

I can't seem ti find anything in the documentation about it.

Any help is appreciated :)

Cheers,

Tazzy


muddy_shoes(Posted 2014) [#2]
What do you mean by "really rotate"? DrawImage has a rotation parameter. Does that in some way not "really rotate" the image?

If you want to use TexturePacker's rotation then you'll need to store the rotation of the frame and unrotate on render. I don't use FantomEngine so I've no idea if it supports the rotated flag in TexturePacker's output or how it does animations.

You may well find the easiest option is to just turn off rotation in TexturePacker.


LemonBytes(Posted 2014) [#3]
You can create your own Image class and encapsulate this for you. It should be easy and useful


Tazzy(Posted 2014) [#4]
Hi,

The problem is FantomEngine does the DrawImage for you with it's engine and also supports animation frames. However the rotation, scale etc. can only be set on the image object and not on the individual frames which are just simple mojo.Image classes. So to make this work all frames need to be oriented in the same position.

TexturePacker tries to add as many images as possible in a small texture. I order to do that it sometimes rotates the image in the atlas. The data file indicates it's rotated in that case, so you should be able to rotate it back. So I need something like:
newImg:Image = oldImage.Rotate(-90)

or 

newImg:Image = CreateImage(oldImage.Height, oldImage.Width)
context := newImage.CreateContext()
context.Rotate -90
context.DrawImage(oldImage)


to 'really" rotate the image (e.g. The Image class contains the rotated image)


muddy_shoes(Posted 2014) [#5]
It's possible to create an unrotated texture but not without effort and you'll only succeed in destroying the advantage of packing the texture in the first place. Sounds like you'll need to alter FantomEngine to take a rotation per frame if you want to use the rotation feature in TP.

Again, it's likely far easier to just turn it off. The packing efficiency difference is usually small.


ziggy(Posted 2014) [#6]
Yes, TexturePacker allows for disabling rotation in the export settings.