Jump to content

My object index is undefined?????


Artuki
 Share

Recommended Posts

levers = this.physics.add.staticGroup();

levers.create(200, 160, 'lever', frame = 0, true, 0);

 

console.log(lever.index) doesn't work in my overlap function. Apparently, index is undefined.

 

I want to link a lever to a bridge so I was going to set both bridge and lever to have index 0 in their respective groups.

Link to comment
Share on other sites

There's a few ways, but here's one:

var partA = levers.create(x, y, key);
var partB = levers.create(x, y, key);

partA.setData('index', 0);
partB.setData('index', 0);

function collide (a, b) {

  if (a.getData('index') === b.getData('index'))
  {
    // do stuff
  }

}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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