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

Is it some sort of undocumented feature or just incorrect documentation?

Here is inheritance tree for Phaser.Group;

 

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

 

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

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

 Share

  • Recently Browsing   0 members

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