-
-
Notifications
You must be signed in to change notification settings - Fork 645
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
Add a default shape to an entity body if not overridden by the entity constructor. #614
Comments
Need to update the wiki entry here: https://github.com/melonjs/melonjs/wiki/Shapes to show two things:
This code example can be added to the comment docs as well. |
if you look at the code of Entity, you initialize the body based on settings.getTMXShapes or otherwise it is [] possible ideas:
|
I agree with @ldd. Moved this to the next major milestone. Documentation is not the right solution. We need a better API to provide a default shape as a rule. The exception is that users may instead add a list of their own shapes. I suggest we rename |
Yeah agreed, i think that is an excellent idea! |
Not sure I agee with this, especially with the part where we expose the getTMXShape function so that end user can override it to add their own shape, that sounds awefully "custom" to me ! In my opinion having to manually add a shape to a body makes as much sense as when we manually add a renderable to an entity, and as far as i can see this is also how it works in physic engine, no? However, as a compromise, we could add a basic rect shape at the size of the entity renderable frame, but this would be done in the getBounds function (as part of the initial check for bounds) so that this would work both for tiled and manual coding. |
I think the idea would be to pass a shape through as an option, over it falling back to an empty array. |
The tradeoff here is convenience vs customizability. A body without a shape is not useful, in the same way that an entity without a body is not useful. An entity that cannot perform physics or hit detection is just a sprite, and we have a lightweight class for that. The problem we need to solve here is that adding an entity is not enough to get collision detection, you also need to add a shape. The simplest, most basic case is that adding an entity should also add a default shape. However, it should not always add a default shape. The best API I can think of is one that opts-in to not have a default shape. And why opt-in when you can just give it the shape you really want in place of a default dummy shape? Well, we already have that functionality through |
umm what about
etc |
pros of my idea:
cons of my idea:
|
To be honest i think that this is over complicating things and we should keep all this as simple as possible. For "collidable" object, an entity must define a body that contains at least one shape, and at this point i would even just modiffy the code to just throw an exception at rutime if no shape is defined for an object. To disable collsion collisionType can be used, and for non collidable object a simple renderable object is the way to go. |
Throwing an exception just pushes the onus of the default shape boilerplate code to the user. melonJS should always try to provide sane defaults, to the best of its ability. |
yes indeed, and exactly like renderable. I'm only worried that we will end up with something super complicated, where we could just say that end-user have to add a collision shape, if we do not want to throw an exception, we could add a warning message in the console ("no collision shape defined for object XXXX, collision will be disable"), that seems to be fine enough for me. |
Like @parasyte commented, I think exposing TMXShapes makes sense. (maybe?) Let me at least mention my specific case: That's all that baseEntity does. |
… default shape defined in Tiled useful when using custom shapes (e.g. Physic Editor) and to avoid deleting the provided default one before manually adding others.
err... this one , I dunno what to do :) last time we however discussed that settings should provide a |
this.body = new me.Body(this, settings.shapes instanceof Array ? settings.shapes : [ new me.Rect(0, 0, this.width, this.height) ]); This solves it all. We get our overrides; |
+1000. (it doesn't help with isometric shapes, but...) settings.shapes = [...]; bonus: noDefaultShape is no longer needed |
Yeah i agree. I like this proposal as well :) On Thu Feb 12 2015 at 9:30:30 AM ldd notifications@github.com wrote:
|
why is |
my only issue with this is that now (after) we would have a set of instantiated which means that when passing |
instead of noDefaultShape, in Tiled or programmatically, you set shapes = [] but I guess technically speaking noDefaultShape can still be used, if desired. |
In Tiled, it's |
no, that does not work as programmatically add or not a default shape defeats the initial purpose of the https://github.com/melonjs/melonJS/blob/master/src/entity/entity.js#L120 so I would rather do : if (settings.noDefaultshape === true) {
this.body = new me.Body(this, []);
} else {
this.body = new me.Body(this, settings.shapes instanceof Array ? settings.shapes : [ new me.Rect(0, 0, this.width, this.height) ]);
} |
also, as a bonus question, what would be the default value of |
In what way is settings.noDefaultShape = true; ... or ... settings.shapes = []; Bonus answer: Lines 127 to 130 in 3572679
|
By the way, |
yes, they are the same, but from Tiled itself it's easier to set a custom property, rather then settings the array to []. But yes, the internal (melonJS) code should set array to [] if the flag is defined. as a reminder this flag is iniitally only to discard any shape creation when using Tiled. |
- shapes are now defined under `settings.shapes[]` - upon creating the body shape array will be populated with (cloned version of ?) the settings.shapes objects - getTMXShapes is now "really" private (changed the name to ensure nobody would use it) - further clean-up of the TmxObject is probably possible
well this is one example where we need a proper way to not use the given default shape, as the way I did it for now is not super clean. Shall we use `noDefaultShape` here as well ?
hi guys, so I implemented what I think is the result of the above discussion. Please review and comments (separate branch for now until we reach a consensus) |
do we merge this branch ? |
@obiot Yeah, the last patch is way better! 😆 I'm ok with merging this branch now. |
- Supported ways to declare no default shape: - In code: `settings.shapes = [];` - Add a TMX property: `shapes = json:[]`
No description provided.
The text was updated successfully, but these errors were encountered: