Jump to content

game.world.setBounds doesnt work


oddskill
 Share

Recommended Posts

Hello.

 

In following example

 

http://oddskill.bplaced.net/coding/2dshooter1/index.html

 

i try to set the world bounds smaller

than the whole canvas, to be able to display some scores, controls etc below the world

in the canvas (where the background is green ), but the sprite that should bounce in the world bounds enters the

area below the bounds i set.

 

I know i could handle that by hand in update function, just wanna know what am i doing wrong.

 

best regards

 

Chris

 

PS: sourcecode below

var game = new Phaser.Game(640, 480, Phaser.CANVAS, 'container', { preload: preload, create: create, update: update });var img;var spriteexplosion;var sound;function preload() {    game.load.image('cow', './assets/cow.png');  game.load.audio('explosionsfx', 'assets/explosion.wav');  game.load.spritesheet('explosiongfx', 'assets/explosion.png', 128, 128, 16);  game.load.spritesheet('background', 'assets/parallax100.png', 640, 480, 1);}function create() {  game.stage.backgroundColor = '#00ff00';    game.physics.startSystem(Phaser.Physics.ARCADE);  game.bg = game.add.tileSprite(0,0,640,400,'background');  game.bg.autoScroll(0,100);  img = game.add.sprite(20, 20, 'cow');  game.physics.enable(img, Phaser.Physics.ARCADE);  img.body.velocity.x=100;  img.body.velocity.y=100;  img.body.collideWorldBounds = true;  img.body.bounce.set(1);  img.anchor.setTo(0.5, 0.5);  img.inputEnabled = true;  img.input.start(0, true);    img.events.onInputDown.add(select);  game.world.setBounds(0,0,640,400);      sound = game.add.audio('explosionsfx',1,true);}function update() {  }function select(img, pointer) {  img.destroy();  sound.play('',0,1,false);  spriteexplosion = game.add.sprite(img.x, img.y, 'explosiongfx');  spriteexplosion.anchor.setTo(0.5, 0.5);  spriteexplosion.animations.add('explosiongfx_anim');  spriteexplosion.animations.play('explosiongfx_anim', 20, false);}
Link to comment
Share on other sites

Currently the World cannot be smaller than the size of your game. You can override this by doing:

    game.world.bounds.setTo(x, y, width, height);    if (game.camera.bounds)    {        //  The Camera can never be smaller than the game size        game.camera.bounds.setTo(x, y, width, height);    }   game.physics.setBoundsToWorld();

But it may have undesirable side-effects. Worth trying though!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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