Researched all though the forum but I couldn't find any discussion on this topic.
Say for example, I have the following four frames of animation on a orxObject with a Box BodyPart:
Frame1: 90 x 160
Frame2: 96 x 160
Frame3: 102 x 162
Frame4: 96 x 160
Does the sizing of the Box BodyPart only fit automatically to the first frame and stay that way even though the size of the object will change during animation?
The wiki says at
http://orx-project.org/wiki/en/orx/config/settings_structure/orxbody
TopLeft/BottomRight: Define the extrema of the box (in 2D it's a rectangle, of course) in the parent's space (ie. in object's space). By default their values are full which means TopLeft and BottomRight will match the full rectangle defined by the parent object's current graphic.
The current graphic could change size and so this quote seems to indicate the size of the box should hopefully change with it. By adding a ShowDebug = true to the Physics section on my config, I can see that the box size doesn't change.
One last thing, this is a test under Orx from last October so things might have changed in this area. I can supply a small zipped demo if anyone needs it.
Comments
Also it's good to note that most physics engine do not support scaling up/down bodies at runtime, orx is working around this limitation by deleting a part and re-creating a new one whenever the scale of an object changes.
You mentioned scaling an object, but I think perhaps I haven't presented the problem clearly, as I'm not scaling the object.
In my example I have four animation frames, something like:
[ManRunningAnim]
KeyData1 = Run1
KeyData2 = Run2
KeyData3 = Run3
KeyData4 = Run4
The legs in frames Run2 and Run3 are much further apart so that their pixel width is greater than Run1 and Run4.
Because I have a box bodypart, and ShowDebug = true, the debug box surrounding the object stays the same width even though my running man sprite varies in width as it animates.
Apologies if I have gotten this wrong based on what you said, and there may be nothing I can do about it.
What I meant is that there's no runtime scaling of parts except when an object gets scaled (and in that case, it's not really scaling that happens for the parts but deletion+re-creation).
Animation frames never have any impact on physics bodies & parts.
If you want to have different body/part configurations based on animation frames, you'll have to do it manually, using animation custom events.
I confirmed yesterday (as you also mentioned) that the size of the physics box comes from the initial graphic assigned to an object. And as you say, the animation that comes after has no bearing.
That's fair enough. I'll do this up and post the solution for anyone else that might be interested.
But is there a way to alter the TopLeft/BottomRight parameters of a box bodypart during runtime?
I could perhaps do a orxPhysics_DeletePart / orxPhysics_CreatePart on every frame but I feel this is pretty dangerous.
Next, I have to work out how to get the size of the current frame graphic, give it to the object graphic, and I should be ok.
If you change the size of your graphic this way, you'll eventually end up with graphical artifacts.
What you will need to do is to delete the current part and create a new one at the correct size. You have two options for this:
- Either you modify the config values for the parts and simply call orxBody_AddPartFromConfig() for the re-creation, but that means you'll have to precise the size of the parts and not rely on orx to use the graphic's size
- Or you can simply call orxBody_AddPart() which takes an orxBODY_PART_DEF which contains all the info to create the new part. In this case, you can get the def from the former part, modify its size, and create a new part with it.
Here's an example (untested as I'm typing in the forum editor):
I'm continuing with this at the moment.
Again, thanks, Iarwain. This was enormously important to achieve for the current project.