-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Access to custom properties on inserted tiles #283
Comments
@luttje Thanks for the kind words! I agree getting the custom properties from Tiled should be easier, the current state is not ideal for sure. I definitely think this is something that should be exposed to the consuming game code. Instead of a derived Actor type, how does a new component to hold this data sound? This would make it easy to reuse Tiled properties on any excalibur Entities from Tiled including Actors. // New component to hold the raw Tiled data
export class TiledObjectComponent extends Component<'ex.tiled'> {
public readonly type = 'ex.tiled';
constructor(public tiled: TiledObject) {}
}
// Updating the tiled insert logic https://github.com/excaliburjs/excalibur-tiled/blob/02c122a11f3737928d9d19db3b3b77e6895c6196/src/tiled-map-resource.ts#L167
const actor = new Actor(...)
actor.addComponent(new TiledObjectComponent(tile));
// Consuming game code
this.actors.forEach(actor => {
// retrieve the component if it exists on the actor/entity
const maybeTiled = actor.get(TiledObjectComponent); // only exists on our Tiled created actor/entity
if (maybeTiled) {
console.log(maybeTiled.getProperty<string>('Item')?.value);
}
}); cc @jedeen @kamranayub Thoughts? |
Thanks for the fast response and that bit of code, it really helped me while refactoring my (in hindsight) hugely inefficient code. It would be nice to see a component like that shipped with this plugin. 👍 |
No promises, but I might be able to squeeze this into the plugin in the next release (theoretically sometime in Jan) 🤞 |
First of all: Thanks for the great engine! Loving it so far 👍
Context
I'm creating 'inserted tiles' in Tiled with which the player can interact with their pointer. I'm creating custom properties in Tiled which are succesfully loaded by this plugin.
Sadly when excalibur-tiled builds the tilemap most custom properties on the
TiledObject
s are not copied to the actor. This is because a genericActor
object is created. From the properties onlycollisionType
andzIndex
are used while constructing the actor.Proposal
To maintain easy access to the custom properties from Tiled I suggest to derive a new class from Actor. E.g: a
TiledActor
which has one additional propertyrawTiled: TiledObject
which refers to the original Tiled data.We could then later access the properties easily:
Current solution
The current solution is a bit tedious and has me comparing the position of an actor with the tiled map data:
Perhaps I'm overthinking it or missing something. Looking forward to your thoughts.
The text was updated successfully, but these errors were encountered: