Jump to content

Tween on game.world.bounds not working!


Batzi
 Share

Recommended Posts

Hey guys, I am trying to set the game world bounds everytime I am zooming in/out of a map however, when I apply a tween to the game world bounds, it is not working.

 

Here is my code

            var t = this.game.add.tween(this.sprites.scale);            function mouseWheel(event) {                var tween = myGame.add.tween(myGame.world.bounds);                if (event.wheelDelta > 0 && scale <= 1) {                    scale += 0.1;                    sprites.scale.setTo(scale, scale);                    myPlayer.body.setSize(50 * scale, 50 * scale, 20 * scale, 80 * scale);                    myHouse.body.setSize(150 * scale, 50 * scale, 20 * scale, 240 * scale);                    myCharacter.body.setSize(110 * scale, 20 * scale, 0, 120 * scale);                    myHydro.body.setSize(100 * scale, 100 * scale, 100 * scale, 100 * scale);                    tween.to({width:5263*scale,height:2636*scale},50);                    tween.start();                    // myGame.world.setBounds(0, 0, 5263 * scale, 2636 * scale);                } else if (event.wheelDelta < 0 && scale >= 0.5) {                    scale -= 0.1;                } else {                    t.stop();                }                sprites.scale.setTo(scale, scale);                myPlayer.body.setSize(50 * scale, 50 * scale, 20 * scale, 80 * scale);                myHouse.body.setSize(150 * scale, 50 * scale, 20 * scale, 240 * scale);                myCharacter.body.setSize(110 * scale, 20 * scale, 0, 120 * scale);                myHydro.body.setSize(100 * scale, 100 * scale, 100 * scale, 100 * scale);                tween.to({width:5263*scale,height:(2636+getHeight())*scale},50);                tween.start();                // myGame.world.setBounds(0, 0, 5263 * scale, (2636 + getHeight()) * scale);            }

The part that is not working is this

var tween = myGame.add.tween(myGame.world.bounds);
tween.to({width:5263*scale,height:(2636+getHeight())*scale},50);tween.start();

The code basically scales down/up a group of sprites including the map whenever the wheel is up/down. That works perfectly!

 

Why do you think the tween is not working on the game world bounds?

Link to comment
Share on other sites

What would you expect scaling the world bounds to be doing, in this case?

Are your width and height values of your bounds being altered if you log it?

The reason I am scaling the world bounds is simply because whenever I zoom in/out (scale in/out) a group of sprites which includes the map itself, I want to hide the black bars whenever the user scrolls up/down/left/right. If I don't tween it, scaling the world bounds works except it is not smooth at all! I commented a line in the code, that's the working version that is not smooth. I'll try to log the values to see what happens but that's pretty much the idea behind scaling the world bounds. 

Link to comment
Share on other sites

Hmm, I suspect that what you really want to be doing is scaling the camera bounds, rather than the world bounds.

 

The world bounds doesn't really do anything apart from setting the boundaries of which entities outside of it should be culled. 

 

The reason why world.setBounds() works is because it actually updates the camera bounds too.

 

setBounds(x, y, width, height)

Updates the size of this world and sets World.x/y to the given values The Camera bounds and Physics bounds (if set) are also updated to match the new World bounds.

 

Perhaps, you should try tweeting the Phaser.Camera's bounds , rather than the Phaser.World's bounds. That might actually achieve the effect you want.

Link to comment
Share on other sites

Hmm, I suspect that what you really want to be doing is scaling the camera bounds, rather than the world bounds.

 

The world bounds doesn't really do anything apart from setting the boundaries of which entities outside of it should be culled. 

 

The reason why world.setBounds() works is because it actually updates the camera bounds too.

 

 

Perhaps, you should try tweeting the Phaser.Camera's bounds , rather than the Phaser.World's bounds. That might actually achieve the effect you want.

You're right and it makes more sense to scale the camera instead! It works! :) Thank you again man!! 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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