Jump to content

Tween scale from center


user471
 Share

Recommended Posts

What can I do with Groups? They don't have anchors.

You can try tweening the group position at the same time that you scale it up. So it will look like its scaling from the center.

game.add.tween(foo.scale).to({ x: 2, y: 2});game.add.tween(foo.position).to({ x: -foo.width, y: -foo.height});

This may not be perfect but tweak some parameter arround and you should have it working as you like. There might be a simpler way for group but this is the first thing I can think about.

Link to comment
Share on other sites

Here is inheritance tree for Phaser.Group;

 

Phaser.Group -> PIXI.DisplayObjectContainer -> PIXI.DisplayObject

 

And PIXI.DisplayObject has property "pivot: PIXI.Point" ;)

But there is similar DisplayObject properties like alpha, scale and they are in documentation. What is the difference?

Link to comment
Share on other sites

  • 7 months later...

You can try tweening the group position at the same time that you scale it up. So it will look like its scaling from the center.

game.add.tween(foo.scale).to({ x: 2, y: 2});game.add.tween(foo.position).to({ x: -foo.width, y: -foo.height});

This may not be perfect but tweak some parameter arround and you should have it working as you like. There might be a simpler way for group but this is the first thing I can think about.

game.add.tween(sprite.scale).to( { x: 2, y: 2 }, tweenTime, Phaser.Easing.Linear.None, true, 0, 1000, true);game.add.tween(sprite.position).to( { x: sprite.position.x - sprite.width / 2, y: sprite.position.y - sprite.height / 2}, tweenTime, Phaser.Easing.Linear.None, true, 0, 1000, true );

This works for me. You just need to calculate the position of the scaled sprite. It is: origin.x - (scale.width - origin.width) / 2 (in this case scale.width = 2 * origin.width). The same formula for Y axis.

Link to comment
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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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