mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-20 17:26:01 +08:00
[libgdx] Added physics methods to apply translation and rotation forces.
This commit is contained in:
parent
ec1d6028c0
commit
2563c7cbce
@ -108,7 +108,22 @@ public class PhysicsConstraint implements Updatable {
|
||||
mix = data.mix;
|
||||
}
|
||||
|
||||
public void translate () {
|
||||
/** Translates the physics constraint so next {@link #update(Physics)} forces are applied as if the bone moved an additional
|
||||
* amount in world space. */
|
||||
public void translate (float x, float y) {
|
||||
ux -= x;
|
||||
uy -= y;
|
||||
cx -= x;
|
||||
cy -= y;
|
||||
}
|
||||
|
||||
/** Rotates the physics constraint so next {@link #update(Physics)} forces are applied as if the bone rotated an additional
|
||||
* amount in world space. */
|
||||
public void rotate (float degrees) {
|
||||
float r = degrees * degRad, cos = cos(r), sin = sin(r);
|
||||
r = tx * cos - ty * sin;
|
||||
ty = tx * sin + ty * cos;
|
||||
tx = r;
|
||||
}
|
||||
|
||||
/** Applies the constraint to the constrained bones. */
|
||||
|
||||
@ -803,6 +803,20 @@ public class Skeleton {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/** Calls {@link PhysicsConstraint#translate(float, float)} for each physics constraint. */
|
||||
public void physicsTranslate (float x, float y) {
|
||||
Object[] physicsConstraints = this.physicsConstraints.items;
|
||||
for (int i = 0, n = this.physicsConstraints.size; i < n; i++)
|
||||
((PhysicsConstraint)physicsConstraints[i]).translate(x, y);
|
||||
}
|
||||
|
||||
/** Calls {@link PhysicsConstraint#rotate(float)} for each physics constraint. */
|
||||
public void physicsRotate (float degrees) {
|
||||
Object[] physicsConstraints = this.physicsConstraints.items;
|
||||
for (int i = 0, n = this.physicsConstraints.size; i < n; i++)
|
||||
((PhysicsConstraint)physicsConstraints[i]).rotate(degrees);
|
||||
}
|
||||
|
||||
/** Returns the skeleton's time. This is used for time-based manipulations, such as {@link PhysicsConstraint}.
|
||||
* <p>
|
||||
* See {@link #update(float)}. */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user