Heppell08 Posted February 17, 2014 Share Posted February 17, 2014 I've been working away and eventually got myself stuck again. I'm trying to fire a function when the player collides with a specific tile in my game. I've searched the source code and looked at examples and used the same logic but still getting an undefined error in console. I'm using phaser 1.1.5.Heres what i'm doing...map.setTileIndexCallback([146, 147], emitBlock, this);// tile 146 amd 147 are the functioned tiles in my indexThen for testing:emitBlock: function() { console.log('Blocks Emitted!'); },but all i get is an undefined error. Now looking at the phaser source it says this about tile callbacks:setTileIndexCallback: function (indexes, callback, callbackContext, layer)so the index is my tiles [146,147], my callback is the function emitBlock, the context is this. I've also replaced 'this' with player for testing but no difference is made. Anyone know what i am doing wrong here to be getting an undefined error for a tile callback function? The layer in the callback in phaser says if not defined it just uses the current tilemap layer so i shouldnt need to define considering im using 1 tilemap for my game. Thanks Link to comment Share on other sites More sharing options...
1-800-STAR-WARS Posted February 17, 2014 Share Posted February 17, 2014 Looks like emitBlock is in a different scope. Inside an object literal for example? So if it were, for example:var someObject = { emitBlock: function () {}}Your function call should be:map.setTileIndexCallback([146, 147], someObject.emitBlock, this); Link to comment Share on other sites More sharing options...
Heppell08 Posted February 17, 2014 Author Share Posted February 17, 2014 This doesn't work either. I tried to set is as player.emitBlock and map.emitBlock but it then says can't call something or other. I'll have to look deeper but in the examples its as simple as setting the index of the tile which I've done. Setting the function, which I've done. Looked at the JSON for the index to be 100% sure and it works like it should. Only issue is when the player touches the tile I want to callback on I get the can't call 'call' error. Says something about context being false or something. I'll have to edit this post with the error exactly as I'm on my phone right now. I've tried every which way In the examples and using some of my own initiative to get this working like it does in examples and it still is giving my an issue. All I want is:Player collides with tile I.D.After hitting the tile, do a function.That is it! Any ideas what is going on here?Thanks Link to comment Share on other sites More sharing options...
1-800-STAR-WARS Posted February 17, 2014 Share Posted February 17, 2014 Not sure - but if you could post some more complete code (in a gist, or codepen, or something?) I'm sure we can get to the bottom of it. Link to comment Share on other sites More sharing options...
Heppell08 Posted February 17, 2014 Author Share Posted February 17, 2014 Yeah I figured it out. Your first answer was right but I needed to declare a whole new var and not use player or map.I used tileFunc1 = { emitBlock: function() { // stuff } }Then setTileindex with the stuff above which now works.Got 3 of them coded in and working! Thanks 1-800-STAR-WARS 1 Link to comment Share on other sites More sharing options...
Recommended Posts