lewster32 / phaser-plugin-isometric

Feature-packed axonometric plugin for Phaser 2 which stays true to the Phaser API.
http://rotates.org/phaser/iso
MIT License
472 stars 165 forks source link

Tile Rotation (Flipping axis) #55

Open dud3 opened 7 years ago

dud3 commented 7 years ago

Is the following correct: https://stackoverflow.com/questions/39799689/phaser-how-to-rotate-an-isometric-body

If not, can we rotate the tile like the link above describes?

dud3 commented 7 years ago

Ping.

dud3 commented 7 years ago

@lewster32 what if we rotate the tile so that'll be parallel to the isometric axes?

lewster32 commented 7 years ago

Sorry for the delay - yes, you cannot rotate bodies as their edges must be aligned to the isometric axes. Rotating doesn't really make a lot of sense in an isometric scene as due to the sprites being 3D representations, any rotations would typically have to be entirely redrawn (i.e. entirely different frames, rather than just transformations to an existing frame). I don't think I'm entirely understanding what you're trying to achieve, so if you have an example then I can try to be more specific, and maybe suggest workarounds.

dud3 commented 7 years ago

@lewster32 Sorry for my late reply as well, the following is what I'm trying to achieve:

countrylife-001 countrylife-002

BTW: sorry, it's not a usual rotation, we're not using any trig functions, simply flipping x and y axis.

Guessing the following does the flipping transformation y=x, after applying it the bouds don't get recalculated.

var cow = game.add.isoSprite(100, 100, 0, 'animal-cow-brown', 0);
cow.width *= -1;

How do we calculate the bound of an object? What about the height of an isometric object?

I think there must be something wrong with the bounds calculation, they don't seem accurate.

lewster32 commented 7 years ago

Does flipping the scale not work? That is how I'd normally do this in Phaser. cow.scale.x *= -1

lewster32 commented 7 years ago

Appears not - the issue seems to be that bounds are initially derived from the sprite size and assumed to be cubic. When changing the scale or width, any non-cubic bounds are not then automatically updated. I guess the workaround is to manually update the bounds yourself when changing the orientation of the sprite, as there is naturally a looser orientation between the sprite and its body with an isometric system; it has to assume some basic things about the sprite, as it cannot interpret any orientation or shape other than the cubic bounds it should occupy for its size.

In order to set your own bounds, you would use cow.body.setSize as documented here.