kittykatattack / hexi

Make games the fun way!
MIT License
551 stars 83 forks source link

setPivot to a scene is possible? #34

Open gustavoelizalde opened 7 years ago

gustavoelizalde commented 7 years ago

Hi!,

I've a gameScene which is a group of sprites

gameScene = g.group(paddle, ball, topBorder, blocks, message);

And I want to apply a setPivot(0.5,0.5) to be used later on a "Shake" effect to the entire scene...

But I'm getting console error messages:

Uncaught Error: [object Object] does not have a PivotX value

It's possible what I'm trying to do?

kittykatattack commented 7 years ago

Hello!

the shake function should look something like this:

g.shake(gameScene, 16, false);

You can find a working example of this here:

https://github.com/kittykatattack/hexi/blob/master/examples/src/breakout.js#L207

I've just tested in and it works, so I wonder if there might be something else wrong with your code?

gustavoelizalde commented 7 years ago

Yes, but I want to set the "angularShake" to "true", but to achieve this, as docs says:

Make sure that you've set your sprite's x/y pivot point to 0.5 for this to work effectively

When I tried to use setPivot(0.5,0.5) on the gameScene returns the error above.

gameScene.setPivot(0.5, 0.5); g.shake(gameScene, 100, true);

I tried several ways to set this prop on the "breakout.js" example, but always getting an error.

kittykatattack commented 7 years ago

You're right! Hexi's group is a Pixi Container under the hood. I just checked Pixi's documentation and indeed Containers do not have an anchor property, which is what Hexi needs to add the pivotX and pivotY properties to sprites. I'll update the comments in the code to highlight this. A work-around would be to create a parent sprite the size of the game scene, add your child sprites to it, and then use something like parentSprite.setPivot(0.5, 0.5) to center the paren't sprite's rotation axis.

But I think it would be better if a group objects could have its rotation axis centered, so I'll look into when we do our next Hexi feature review.