My object index is undefined?????

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.

Share this post

Link to post
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



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.