-
Hey folks, I am just beginning my Excalibur journey and am migrating my existing Phaser.js project to Excalibur. So I may be missing something quintessential. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @cdelstad Apologies it took a moment to answer you!
In the current incarnation of the plugin, this can be accessed off of a component on the colliding actors. (This doesn't seem to be very well documented unfortunately something I've added to my list of docs to fix) playerActor.on('collisionstart', evt => {
const data = evt.other.get(TiledObjectComponent)
console.log(data);
}); Giving Tiled objects a Name property also propagates through to the Actor as well. ![]() Additionally the Tiled editor renamed Type to Class so this get's confusing! These properties are needed (unfortunately casing also matters in the current incarnation for CollisionType = Passive to work)
This also works, and it looks like you might have to do that for Circle colliders because the current automagic integration appears to have a bug and the sizing/position is wrong :( ![]() ![]() Here is the workaround code I shared with you in Discord const script = Resources.TiledMap.data.getObjectLayerByName("script");
for (let obj of script.objects) {
// Cannot rely on [0] so need to loop for value = portal and name = name?
if (obj.properties.some(p => p.value ==='portal')){ // < -- no longer depends on prop order
// Actors have a built in circle collider if radius is set
const actorWithCircleCollider = new ex.Actor({
pos: ex.vec(obj.x + obj.width!/2, obj.y + obj.width!/2), // < -- tiled renders stuff oddly
radius: (obj.width || 20) / 2, // < - radius is 1/2 width
collisionType: ex.CollisionType.Passive,
color: ex.Color.Green, // <-- debug color
z: 99, // < -- debug z above all
name:'portal',
anchor: ex.vec(0.5, 0.5), // < -- switch back to center
});
actorWithCircleCollider.on('collisionstart', () => {
console.log('Look at the portal on that!');
});
game.currentScene.add(actorWithCircleCollider);
}
} I've 100% fixed this in the new plugin PR (although unmerged) excaliburjs/excalibur-tiled#477 |
Beta Was this translation helpful? Give feedback.
Hi @cdelstad
Apologies it took a moment to answer you!
In the current incarnation of the plugin, this can be accessed off of a component on the colliding actors. (This doesn't seem to be very well documented unfortunately…