Jump to content

adding diffrent objects with createFromObjects.


adamosen
 Share

Recommended Posts

Hi, im a bit of a noob and i tried to make a simple tile based game along with Tiled and added some objects with createFromObjects.

 

i have the following in create:

 

    map.createFromObjects('objects', 149, 'items1', 0, true, false, pickup);

    map.createFromObjects('objects', 150, 'items1', 1, true, false, pickup);

 

then in update:     

 

game.physics.arcade.overlap(player, pickup, collectitem, null, this);

 
    function collectitem(player, item) {
 
        item.kill();
 
        score += 10;
   
        scoreText.text = 'Score:' + score;
    }
this works fine but if i want different code to run depending on which gid the objects have without make more functions, how can i do this?
 
something like:
 
    function collectitem(player, item) {
 
        item.kill();
 
        if (item.gid = 149)
        {
            score += 15;
        }
   
        if (item.gid = 150)
        {
            score += 10;
        }
   
        scoreText.text = 'Score:' + score;
    }
 
but this doesn't work obviously, how can i do it?
 
 

 

Link to comment
Share on other sites

i have the feeling you didn't post the whole code here (for the creation and configuration of the objects)

after creating those objects you obviously need to configure them further..  adding physics and so on..  right?  (or is it possible to check for overlap with a simple sprite without physicsbody in arcade?)

 

you are probably running over the whole group of objects with a forEach() ?

 

in addition you  could just give every object a name and then just check against the name.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...