Jump to content

rotate sprite along z-axis

Recommended Posts

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 post
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.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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...