Jump to content

rotate sprite along z-axis


qbss
 Share

Recommended Posts

Is there any way to rotate sprite (concretely coin) along z-axis? It is 3d efect but maybe achievable in canvas and phaser by setting scale or other properties. Ultimate efect I want to achieve can be done by such spritesheet: coin.png

Link to comment
Share on other sites

Ok, one another problem is because my coin is asymmetric . So when I scale from 1 to -1, then I want to constantly rotate in the same direction (again from 1 to -1). So as far as I can see one solution is create 2 frame spritesheet (reverse parties)  and when tween is complete set second frame , set scale again to 1 and then play tween again.

Link to comment
Share on other sites

Tween with yoyo should do all the job for you! Let's say, you have coin atlas and two sprites in it: "front" and "back". Then you can listen to onComplete and change frame in it:

    var sprite = game.add.sprite(0, 0, 'coin', 'front');
    sprite.position.set(100,100);
    sprite.anchor.set(0.5, 0);
    
    var tween = game.add.tween(sprite.scale).to( { x: -1 }, 1000, "Linear", true, 0, -1, true);
    tween.onLoop.add(function() {
        sprite.frameName = (sprite.frameName === 'front') ? 'back' : 'front';
    }, this);

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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