Jojo Posted March 19, 2014 Share Posted March 19, 2014 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, 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 More sharing options...
Jojo Posted March 20, 2014 Author Share Posted March 20, 2014 Can anyone help with this bug? http://mypickandmix.com/test/errorTest/test2.html I have uploaded it to here, it is very strange? In chrome press F12 and you will see the error popping up every time you click on the screen. Swop back to the old Phaser and all is fine. Thanks Link to comment Share on other sites More sharing options...
jyapayne Posted March 20, 2014 Share Posted March 20, 2014 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 More sharing options...
Arlefreak Posted March 30, 2014 Share Posted March 30, 2014 I have the same problem, it seems that when removing a child with inputEnable it causes this error, I reported on Github https://github.com/photonstorm/phaser/issues/672 Link to comment Share on other sites More sharing options...
JP91 Posted March 30, 2014 Share Posted March 30, 2014 why are you using that way removeAll? using group.removeAll() sprite.parent be undefined and will no longer have visible property and and then checkPointerOver throw the error Link to comment Share on other sites More sharing options...
omarojo Posted June 18, 2015 Share Posted June 18, 2015 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 clearedgame.state.start('MainScreen', clearWorld, clearCache); Link to comment Share on other sites More sharing options...
Recommended Posts