So, I have been following along with Joao on making the “food run” game. We are at the point where the food entities are being collected, the code worked on his but not mine. I have checked the collision on the entities, my code like spot on. Due to being on a Chromebook F12 doesn’t seem to bring up the log so I’m not sure how I could check that.
// code starts here
var CollectableController = pc.createScript('collectableController');
CollectableController.prototype.initialize = function() {
this.entity.collision.on('triggerenter'), ()=> {
this.app.fire('collected');
this.entity.destroy();
}
};
Chrome should still have access to the browser developer tools
Code looks fine out of context of the project. Have you attached the script to the entity?
That worked for find the dev tools thank you.
yes I have attached the script to the food entities
Can you post the project link here please?
Ah, there’s a typo. Change
CollectableController.prototype.initialize = function() {
this.entity.collision.on('triggerenter'), ()=> {
this.app.fire('collected');
this.entity.destroy();
}
};
To
CollectableController.prototype.initialize = function() {
this.entity.collision.on('triggerenter', ()=> {
this.app.fire('collected');
this.entity.destroy();
});
};
Your code is basically the following. So no function callback was passed to the event listener and it created an anonymous function to isn’t stored anywhere.
CollectableController.prototype.initialize = function() {
this.entity.collision.on('triggerenter');
() => {
this.app.fire('collected');
this.entity.destroy();
}
};
i see it there thank you, you have been a great help