xronn Posted February 25, 2014 Share Posted February 25, 2014 Hi, So i'm trying to make it so when my player collides with an element it will callback to another function where I will run my magic; //Coins coinGroup = this.add.group(); coin = coinGroup.create(163, 228, 'coin'); coin1 = coinGroup.create(163, 208, 'x3coin'); coin2 = coinGroup.create(500, 228, 'coin'); coin3 = coinGroup.create(500, 208, 'x3coin'); var score = 5;Create function, adding and positing my coins //Coin Collectgame.physics.collide(hero, coinGroup, coinPickup, null, this); Update function, the collide check and call back to the functioncoinPickup: function(){ score = 50;}The callback function error - https://www.dropbox.com/s/vit43bnc2ew9txs/Screenshot%202014-02-25%2000.03.57.png Link to comment Share on other sites More sharing options...
Zaidar Posted February 25, 2014 Share Posted February 25, 2014 From the code you send the only thing I see is that you create your coinPickup function as an object notation, but I don't think you used it in the rest of your game. What id you replace coinPickup: function(){bycoinPickup= function(){? Link to comment Share on other sites More sharing options...
XekeDeath Posted February 25, 2014 Share Posted February 25, 2014 Error says you have an unexpected identifier on line 186 of game.js.Which one is line 186 of game.js? Link to comment Share on other sites More sharing options...
xronn Posted February 25, 2014 Author Share Posted February 25, 2014 Line 186 is this :186: quitGame: function (pointer) { // Here you should destroy anything you no longer need. // Stop music, delete sprites, purge caches, free resources, all that good stuff. // Then let's go back to the main menu. this.this.state.start('MainMenu'); }But this function was fine until I added the coinPickup function so not sure why this would cause any issue Link to comment Share on other sites More sharing options...
Zaidar Posted February 25, 2014 Share Posted February 25, 2014 didn't you forget a comma after this function ? Otherwise we need more code to understand what's wrong. Link to comment Share on other sites More sharing options...
XekeDeath Posted February 25, 2014 Share Posted February 25, 2014 Yep, missing comma is my diagnosis.coinPickup: function(){ score = 50;}, //<< this one right here... You needs it. Link to comment Share on other sites More sharing options...
Zaidar Posted February 25, 2014 Share Posted February 25, 2014 you need commas after each function declaration, but not the last one. Link to comment Share on other sites More sharing options...
xronn Posted February 25, 2014 Author Share Posted February 25, 2014 you need commas after each function declaration, but not the last one.Okay thanks I'll give that a go, sorry I missed your first replyDoes this line go in the update function?//Coin Collectgame.physics.collide(hero, coinGroup, coinPickup, null, this); Link to comment Share on other sites More sharing options...
Zaidar Posted February 25, 2014 Share Posted February 25, 2014 Yes, it does. Link to comment Share on other sites More sharing options...
xronn Posted February 25, 2014 Author Share Posted February 25, 2014 Okay, that removed that error, I got the menu screen up with no errors but when I click to load my game state it throws this error: Uncaught ReferanceError: coinpickup is not defined game.js:130Line 130 is this - this.physics.collide(hero, coinGroup, coinPickup, null, this); Link to comment Share on other sites More sharing options...
XekeDeath Posted February 25, 2014 Share Posted February 25, 2014 Tried this.coinPickup ? Link to comment Share on other sites More sharing options...
xronn Posted February 25, 2014 Author Share Posted February 25, 2014 Aha! this.coinPickup has done the trick thanks both XekeDeath & Zaidar for your support!! Link to comment Share on other sites More sharing options...
xronn Posted February 26, 2014 Author Share Posted February 26, 2014 One final question, I'm updating the score now in this function when the player hits a coin using phaser 1.1.3 i see theres a remove sprite function. I'm trying to remove the sprite the player steps on so far I got this; //Coins coinGroup = this.add.group(); coin = coinGroup.create(163, 228, 'coin'); coin1 = coinGroup.create(163, 208, 'x3coin'); coin2 = coinGroup.create(500, 228, 'coin'); coin3 = coinGroup.create(500, 208, 'x3coin'); //Coin Collect this.physics.collide(hero, coinGroup, this.coinPickup, null, this); }, coinPickup: function(){ score += Math.floor((Math.random()*10)+1); scoreText.setText(score); this.coinGroup.remove(); },this.coingroup.remove();Throws out this error:Uncaught TypeError: Cannot call method 'remove' of undefined game.js:165Line 165 is:this.coinGroup.remove(); Link to comment Share on other sites More sharing options...
jflowers45 Posted February 26, 2014 Share Posted February 26, 2014 one thing worth trying ... instead of coinGroup = this.add.group();coin = coinGroup.create(163, 228, 'coin');...... try this.coinGroup = this.add.group();coin = this.coinGroup.create(163, 228, 'coin');...... Link to comment Share on other sites More sharing options...
xronn Posted February 26, 2014 Author Share Posted February 26, 2014 Hi, I gave that ago when I walk into the coins now it throws this error - Uncaught TypeError: Cannot read property 'group' of undefined Link to comment Share on other sites More sharing options...
XekeDeath Posted February 27, 2014 Share Posted February 27, 2014 Your problem is probably scoping.coinGroup = this.add.group();This is either going to be a global var, or if you defined it earlier, it'll be local to the (create?) function.That makes it completely different to the variable you are trying to reference here:this.coinGroup.remove();That one is looking at the (state?) object that the function is called on, and trying to get the group there. It is not there, because you never added it to the (state?) object. jflowers45's suggestion should work, provided you complete the remove function call. You will need to tell the group what to remove. The collision function is passed 2 parameters from the Phaser Engine that correspond to the colliding objects, in the order you put them in the collision function.In this case, you would have:coinPickup: function(hero, coin){Note that coin is the sprite object involved in the collision - the one you are picking up - not the coin group. (Things in brackets with ? are assumptions about your code) Link to comment Share on other sites More sharing options...
Kiwiboy Posted August 22, 2014 Share Posted August 22, 2014 Post below.. Link to comment Share on other sites More sharing options...
Kiwiboy Posted August 22, 2014 Share Posted August 22, 2014 Ehm accidentally sent an unfinished post, used to the code hotkeys now ^^I'll summarize this time. So the problem is; sometimes the order of the colliding objects are wrong. update: function() { //this.player is a group with two sprites //this.effects is a list, it consists of a particle emitter and just a sprite this.physics.arcade.overlap(this.player, this.effects, this.Death, null, this);},Death: function(p, effect) { console.log(p, effect);}When it's the emitter it logs the player sprite first, then the emitted sprite. When it's the sprite effect, for some reason it logs that first and the player sprite becomes the effect parameter.So... it feels you probably need more to help me but if you have any idea that would be great!Cheers! Link to comment Share on other sites More sharing options...
Recommended Posts