[libgdx] Finished sliders.

This commit is contained in:
Nathan Sweet 2025-04-27 14:57:51 -04:00
parent ac1c5ecb68
commit 6d3b6ebf0b
4 changed files with 18 additions and 16 deletions

View File

@ -893,7 +893,7 @@ public class Animation {
return ENTRIES;
}
/** Sets the transform mode for the specified frame.
/** Sets the inherit transform mode for the specified frame.
* @param frame Between 0 and <code>frameCount</code>, inclusive.
* @param time The frame time in seconds. */
public void setFrame (int frame, float time, Inherit inherit) {
@ -917,9 +917,8 @@ public class Animation {
float[] frames = this.frames;
if (time < frames[0]) {
if (blend == setup || blend == first) pose.inherit = bone.data.setup.inherit;
return;
}
pose.inherit = Inherit.values[(int)frames[search(frames, time, ENTRIES) + INHERIT]];
} else
pose.inherit = Inherit.values[(int)frames[search(frames, time, ENTRIES) + INHERIT]];
}
}
@ -1733,7 +1732,7 @@ public class Animation {
/** Sets the time, mode, index, and frame time for the specified frame.
* @param frame Between 0 and <code>frameCount</code>, inclusive.
* @param time Seconds between frames. */
* @param delay Seconds between frames. */
public void setFrame (int frame, float time, SequenceMode mode, int index, float delay) {
frame *= ENTRIES;
frames[frame] = time;

View File

@ -420,8 +420,8 @@ public class SkeletonBinary extends SkeletonLoader {
data.skinRequired = (nn & 1) != 0;
data.loop = (nn & 2) != 0;
data.additive = (nn & 4) != 0;
if ((nn & 8) != 0) data.setup.mix = (nn & 16) != 0 ? input.readFloat() : 1;
if ((nn & 32) != 0) data.setup.time = input.readFloat();
if ((nn & 8) != 0) data.setup.time = input.readFloat();
if ((nn & 16) != 0) data.setup.mix = (nn & 32) != 0 ? input.readFloat() : 1;
constraints[i] = data;
}
}

View File

@ -895,8 +895,8 @@ public class SkeletonJson extends SkeletonLoader {
case "inherit" -> {
var timeline = new InheritTimeline(frames, bone.index);
for (int frame = 0; keyMap != null; keyMap = keyMap.next, frame++) {
float time = keyMap.getFloat("time", 0);
timeline.setFrame(frame, time, Inherit.valueOf(keyMap.getString("inherit", Inherit.normal.name())));
timeline.setFrame(frame, keyMap.getFloat("time", 0),
Inherit.valueOf(keyMap.getString("inherit", Inherit.normal.name())));
}
timelines.add(timeline);
}
@ -1154,8 +1154,8 @@ public class SkeletonJson extends SkeletonLoader {
float lastDelay = 0;
for (int frame = 0; keyMap != null; keyMap = keyMap.next, frame++) {
float delay = keyMap.getFloat("delay", lastDelay);
timeline.setFrame(frame, keyMap.getFloat("time", 0),
SequenceMode.valueOf(keyMap.getString("mode", "hold")), keyMap.getInt("index", 0), delay);
timeline.setFrame(frame, keyMap.getFloat("time", 0), SequenceMode.valueOf(keyMap.getString("mode", "hold")),
keyMap.getInt("index", 0), delay);
lastDelay = delay;
}
timelines.add(timeline);

View File

@ -54,6 +54,7 @@ public class Slider extends Constraint<Slider, SliderData, SliderPose> {
public void update (Skeleton skeleton, Physics physics) {
if (pose.mix == 0) return;
SliderData data = this.data;
Timeline[] timelines = data.animation.timelines.items;
int timelineCount = data.animation.timelines.size;
Bone[] bones = skeleton.bones.items;
@ -85,6 +86,9 @@ public class Slider extends Constraint<Slider, SliderData, SliderPose> {
skeleton.updateCache.add(this);
Slot[] slots = skeleton.slots.items;
Constraint[] constraints = skeleton.constraints.items;
PhysicsConstraint[] physics = skeleton.physics.items;
int physicsCount = skeleton.physics.size;
for (int i = 0; i < timelineCount; i++) {
Timeline t = timelines[i];
if (t instanceof BoneTimeline timeline) {
@ -96,13 +100,12 @@ public class Slider extends Constraint<Slider, SliderData, SliderPose> {
skeleton.resetCache(slots[timeline.getSlotIndex()]);
else if (t instanceof PhysicsConstraintTimeline timeline) {
if (timeline.constraintIndex == -1) {
PhysicsConstraint[] constraints = skeleton.physics.items;
for (int ii = 0, nn = skeleton.physics.size; ii < nn; ii++)
skeleton.resetCache(constraints[ii]);
for (int ii = 0; ii < physicsCount; ii++)
skeleton.resetCache(physics[ii]);
} else
skeleton.resetCache(skeleton.constraints.items[timeline.constraintIndex]);
skeleton.resetCache(constraints[timeline.constraintIndex]);
} else if (t instanceof ConstraintTimeline timeline) //
skeleton.resetCache(skeleton.constraints.items[timeline.getConstraintIndex()]);
skeleton.resetCache(constraints[timeline.getConstraintIndex()]);
}
}
}