/** * Updates the bone and object structure with the given time to the given root bone. * * @param time The time which has to be between 0 and {@link #length} to work properly. * @param root The root bone which is not allowed to be null. The whole animation runs relative to * the root bone. */ public void update(int time, Bone root) { if (!this.prepared) throw new SpriterException( "This animation is not ready yet to animate itself. Please call prepare()!"); if (root == null) throw new SpriterException( "The root can not be null! Set a root bone to apply this animation relative to the root bone."); this.currentKey = mainline.getKeyBeforeTime(time); for (Timeline.Key timelineKey : this.unmappedTweenedKeys) timelineKey.active = false; for (BoneRef ref : currentKey.boneRefs) this.update(ref, root, time); for (ObjectRef ref : currentKey.objectRefs) this.update(ref, root, time); }
/** * Prepares this animation to set this animation in any time state. This method has to be called * before {@link #update(int, Bone)}. */ public void prepare() { if (this.prepared) return; this.tweenedKeys = new Timeline.Key[timelines.length]; this.unmappedTweenedKeys = new Timeline.Key[timelines.length]; for (int i = 0; i < this.tweenedKeys.length; i++) { this.tweenedKeys[i] = new Timeline.Key(i); this.unmappedTweenedKeys[i] = new Timeline.Key(i); this.tweenedKeys[i].setObject(new Object(new Point(0, 0))); this.unmappedTweenedKeys[i].setObject(new Object(new Point(0, 0))); } if (mainline.keys.length > 0) currentKey = mainline.getKey(0); this.prepared = true; }