SatriaAI

Can anyone help with this phaser example?

Recommended Posts

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?

 

Share this post


Link to post
Share on other sites

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? 

Share this post


Link to post
Share on other sites
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

Untitled.png

where's my wrong? its cause me so confused :(

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.