melonJS icon indicating copy to clipboard operation
melonJS copied to clipboard

Rotate

Open nvlbg opened this issue 14 years ago • 4 comments

I think it would be a good feature if the SpriteObject could rotate itself at least at 90 degrees. So it would be used like so:

this.rotate(true); // rotates the image 90 degrees

now I could flipX/flipY and get the image result I want.

Edit: here is some code that rotates canvas 90 degrees

http://pastebin.com/VSDMx30L

I haven't personally tested it, but I'm pretty sure it works correct.

nvlbg avatar Aug 03 '12 20:08 nvlbg

what do you mean ?

in the current 0.9.4 (github) melonJS already support rotation and also anchor point, so that you can specify around which point to perform it.

basically if you want to apply a 90 degrees rotation to a sprite, what you need to do is : this.mySpriteEntity.angle = Number.prototype.degToRad (90);

is this what you want or you want an "helper" function that just rotate by 90 degrees every time it's called ? if the second, I don't know, as I'm already thinking about removing the doClimb function, etc... they are useless and does not help people understanding how the engine is working (I saw people using doClimb for movement on the y axis in a RPG....)

ghost avatar Aug 04 '12 03:08 ghost

Yes, thank you for the note. Since I was using 0.9.3 and didn't find anything in the documentation, I thought such possibility wasn't implemented.

nvlbg avatar Aug 04 '12 08:08 nvlbg

I have just realized that rotating sprite just rotates the image but not the collision box. Shouldn't this feature also rotate the collision box?

nvlbg avatar Aug 04 '12 09:08 nvlbg

This is let to the "end-user" to decide, as for the scaling function.

Note that anyway with the current collision detection implementation being rectangle based, the only one managable are the 90 degrees based rotation.

ghost avatar Aug 05 '12 08:08 ghost