Jump to content

Texture orientation (rotation) on a sprite


chadn
 Share

Recommended Posts

I'm new to Phaser I'm hoping this will be a quick answer. 

 

I have my sprite atlas with my ship textures currently oriented pointing up. When loading a sprite from a texture this messes with the acceleration vector based on the rotation. I'd like to rotate a texture without rotating the sprite body which seems like the easiest solution (if it exists).

I can see two work around options here, either create a rotationOffset property and calculate "forward" against that .. or ensure my textures are oriented at a 90 degree angle (no I wont do that). 

 

Working example to demonstrate this (use arrow keys and not the ship is flying sideways):

http://jsfiddle.net/WsWhL/

 
Ship Atlas for reference (I URI encoded the data in the sample):
 

Why I'm here: I found PIXI.js and thought it was pretty awesome so I wrote a small ECS framework around it, I got things loading and moving "yay!". I then got to the point where I needed to add collision and physics systems, a lot of work there, so now I'm taking a break and looking at Phaser because it's PIXI based and most of the guts are already there to mock out a small HTML game. Thanks for the great framework! (although it's not ECS) :P

 

 

Link to comment
Share on other sites

 

I can see two work around options here, either create a rotationOffset property and calculate "forward" against that .. or ensure my textures are oriented at a 90 degree angle (no I wont do that).

 

The first one is the easiest, but takes more code / processing. The second one you do once and don't need to change your code at all. Personally I do the second one in my games, but honestly it won't take much to extend your Sprites to add offset support either. You could just replace the whole Sprite.angle getter.

Link to comment
Share on other sites

 
 
I'm using this for now...
Phaser.Sprite.prototype.rotationOffset = 0;Phaser.Sprite.prototype.getRotation = function(){    return this.rotation + (this.rotationOffset || 0);};

The problem I'm facing now is with 50+ sprites saved saved with that orientation (0 degrees, straight up), I bought TexturePacker last week, not sure if that has a way to orient all sprites.

Short of loading each sprite image and doing a transform, is there a tool that will allow me to do this when creating an atlas?

 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...