SatriaAI Posted December 12, 2017 Share Posted December 12, 2017 I've follow the example in phaser.io but my star didn't appear. Does in my codes have mystake? Can you help me find the problem? Thaanks This my Code... main.js Quote Link to comment Share on other sites More sharing options...
ugajin Posted December 13, 2017 Share Posted December 13, 2017 One issue appears to be with the overlap callback function expression CollectStar, which is orphaned, Try this: function collectStar(player, star){ star.kill(); } function collectStar(player, star){ star.kill(); } You also have global variables, and a missing semicolon. Can you provide a link to the example? Quote Link to comment Share on other sites More sharing options...
mattstyles Posted December 15, 2017 Share Posted December 15, 2017 Global variables are fine (if thats your thing), and semicolons are optional in JS, its rare a missing semicolon would cause a problem (rarer than using them actually, but thats a different discussion!). What is the error? I'm expecting a syntax error, as ugajin pointed out, the collectStar function should be causing an error. The console should have thrown you a pretty informative error about this, did you check it? Quote Link to comment Share on other sites More sharing options...
SatriaAI Posted December 22, 2017 Author Share Posted December 22, 2017 On 12/13/2017 at 6:32 PM, ugajin said: One issue appears to be with the overlap callback function expression CollectStar, which is orphaned, Try this: function collectStar(player, star){ star.kill(); } function collectStar(player, star){ star.kill(); } You also have global variables, and a missing semicolon. Can you provide a link to the example? I've checked its semicolon, and variable that should be. But if i remove the collectStar() from callback and i touch the star its cause the errors. Else if i put the collectStar() callback in the console say Uncaught Quote ReferenceError: collectStar is not defined else if i use the Quote function collectStar(player, star){ star.kill(); } the console say this, Quote Uncaught SyntaxError: Unexpected identifier where's my wrong? its cause me so confused Quote Link to comment Share on other sites More sharing options...
ugajin Posted December 23, 2017 Share Posted December 23, 2017 Try moving the function expression collectStar inside 'main' main = . . . update : function(){ ... }, collectStar : function(player, star){ star.kill(); } }); You may also need to prefix the overlap callback with 'this' as in 'this.collectStar' It would be easier to help if you provided the project as a zip file, or something. Quote Link to comment Share on other sites More sharing options...
SatriaAI Posted December 24, 2017 Author Share Posted December 24, 2017 23 hours ago, ugajin said: Try moving the function expression collectStar inside 'main' main = . . . update : function(){ ... }, collectStar : function(player, star){ star.kill(); } }); You may also need to prefix the overlap callback with 'this' as in 'this.collectStar' It would be easier to help if you provided the project as a zip file, or something. I think that will not solve the problem because you place the function as part not as callback. The end, that i found if you will use it for callback you must place it outside of part Phaser.Game I think phaser just have preload, create, update, and render as main part build in. like this Quote main = .... create : function(){ ... }, update : function(){ ... } }); function collectStar(player, star) { star.kill(); } it solve my problem use Phaser 2.9.4 or newest. I appreciate all of you help guys. Its fun when you work with community Quote Link to comment Share on other sites More sharing options...
SatriaAI Posted December 24, 2017 Author Share Posted December 24, 2017 sorry at the beginning i confused where i must put my code as callback or as main function. But in kind of your help Quote Link to comment Share on other sites More sharing options...
ugajin Posted December 24, 2017 Share Posted December 24, 2017 Yes, that will work too! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.