Jump to content

Problem with moving to Phaser 2.0.1-game.world.removeAll()


Jojo
 Share

Recommended Posts

First of all I want to say I love everything so far, been coding games for 30+ years (yep that old) and love how things feel,

 

My problem is right at the start of my code, so a little worried how things are going to go later if I hit a problem like this to start with, I have cut everything back and still get this problem

 

I keep getting this error,

 

  1. Uncaught TypeError: Cannot read property 'visible' of undefined phaser.min.js:9

 

 

When I click anywhere on the screen on the map page.

 

I did not have this on the old Phaser, 

 

 

If I remove this line it looks like it is working 'game.world.removeAll()'

 

I can run the same code in the old phaser with out getting the error.

 

I have had a look at the doc's and can see no change to world.removeAll.

 

 

code below-----

 

 

<!DOCTYPE HTML>
<html>
<head>
    <meta charset="UTF-8" />
    <title>Test Me</title>
    <script src="phaser.min.js"></script>

</head>
<body>
<div id="phaser-example"></div>
<script type="text/javascript">

 var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });

 var  winW = 480;
 var  winH = 600;


function strartfrontscreen(){
   
    game.world.removeAll()
     
    game.world.setBounds(0, 0, winW-1, winH);  
    

    

    
     frontScreen = game.add.sprite(0, 0, 'frontscreen' );
    
     button = game.add.button(100, 0, 'startBut', actionOnClick, this, 2, 1, 0);
     button.width = 225;
     button.height = 100;
     
     bounce1 = game.add.tween(button);
     bounce1.to({y: 480 }, 2000, Phaser.Easing.Bounce.Out);
     bounce1.start();


}

function preload() {



    game.load.image('mainmap', 'images/MainMap001.jpg');
    game.load.image('frontscreen', 'images/frontScreen.jpg');
    game.load.image('frontscreenloadinglev', 'images/loading.jpg');    
    game.load.spritesheet('startBut', 'images/startBut.gif', 360, 150);


}



function create() {



strartfrontscreen()



}



function update() {







}

 function actionOnClick(){
 

            
 game.world.removeAll()
 
   
 

 
 game.add.sprite(0, 0, 'mainmap' );


}

</script>
</body>
</html>
 

 

Thanks

 

Jonathan

 

Link to comment
Share on other sites

My question is this: Why are you calling removeAll()? You should be creating states and switching between them with game.state.start('StateName');

var winW = 480;var winH = 600;var FrontScreen = {    preload: function(){        game.load.image('mainmap', 'images/MainMap001.jpg');        // add the rest of your image preloading here    },    create: function(){        this.startfrontscreen();    },    startfrontscreen: function(){       //all your code here    },    actionOnClick(){        var clearWorld = true;        var clearCache = false; //if set to true, all your resources will be cleared        game.state.start('MainScreen', clearWorld, clearCache);    }};var MainScreen = {    preload: function(){    },    create: function(){        game.add.sprite(0, 0, 'mainmap');    },};var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example');game.state.add('MainScreen');game.state.add('FrontScreen');game.state.start('FrontScreen');

That should give you the effect you want, but doing it nice and clean.

 

When you call game.state.start() with the clearWorld boolean set, it will clear the world for you so that you don't have to worry about it. I think the reason you were getting that error is maybe because removeAll() functions a bit differently in phaser 2.0.

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 year later...

This is not working for me. I keep seeing the previous state objects being rendered below the new state objects. I just can't find a way fix this. even the removeAll() function does nothing. 

 

var clearWorld = true;

var clearCache = false; //if set to true, all your resources will be cleared
game.state.start('MainScreen', clearWorld, clearCache);

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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