[haxe] Formatting

This commit is contained in:
Mario Zechner 2025-07-16 01:34:53 +02:00
parent ab64434ae7
commit 9fcc5a8b8c
173 changed files with 1591 additions and 1238 deletions

View File

@ -5,11 +5,10 @@ set -e
echo "Formatting Haxe files..."
if command -v haxelib &> /dev/null && haxelib list formatter &> /dev/null; then
find .. -name "*.hx" \
-not -path "*/.*" \
-not -path "*/node_modules/*" \
-not -path "*/build/*" \
| xargs haxelib run formatter -s
# Format spine-haxe directory
if [ -d ../spine-haxe ]; then
haxelib run formatter -s ../spine-haxe
fi
else
echo "Warning: haxe formatter not found. Install with: haxelib install formatter"
fi

View File

@ -32,9 +32,9 @@ show_help() {
echo ""
echo "Tools used:"
echo " Java: Spotless with Eclipse formatter"
echo " TypeScript: Biome"
echo " TypeScript: tsfmt (typescript-formatter)"
echo " C/C++: clang-format"
echo " C#: dotnet-format"
echo " C#: dotnet format"
echo " Haxe: haxe formatter"
echo " Dart: dart format"
echo " Swift: swift-format"

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package;
@ -35,63 +35,61 @@ import starlingExamples.Scene.SceneManager;
import starling.core.Starling;
import flixel.FlxG;
import flixel.FlxGame;
import openfl.display.Sprite;
import openfl.text.TextField;
import openfl.text.TextFormat;
import openfl.events.MouseEvent;
import openfl.geom.Rectangle;
import starling.events.Event;
class Main extends Sprite {
private var background:Sprite;
private var background:Sprite;
private var flixelButton:Sprite;
private var starlingButton:Sprite;
private var starlingButton:Sprite;
private var uiContainer:Sprite;
private static inline var ratio = 4;
private static inline var STAGE_WIDTH:Int = 100 * ratio;
private static inline var STAGE_HEIGHT:Int = 200 * ratio;
private static inline var BUTTON_WIDTH:Int = 80 * ratio;
private static inline var BUTTON_HEIGHT:Int = 40 * ratio;
private static inline var BUTTON_SPACING:Int = 20 * ratio;
private static inline var STAGE_WIDTH:Int = 100 * ratio;
private static inline var STAGE_HEIGHT:Int = 200 * ratio;
private static inline var BUTTON_WIDTH:Int = 80 * ratio;
private static inline var BUTTON_HEIGHT:Int = 40 * ratio;
private static inline var BUTTON_SPACING:Int = 20 * ratio;
public function new() {
super();
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
public function new() {
super();
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
private function onAddedToStage(e:Event):Void {
removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
createUI();
centerUI();
stage.addEventListener(Event.RESIZE, onResize);
}
private function onAddedToStage(e:Event):Void {
removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
createUI();
centerUI();
stage.addEventListener(Event.RESIZE, onResize);
}
private function createUI():Void {
uiContainer = new Sprite();
addChild(uiContainer);
private function createUI():Void {
uiContainer = new Sprite();
addChild(uiContainer);
background = new Sprite();
background.graphics.beginFill(0xA2A2A2);
background.graphics.drawRect(0, 0, STAGE_WIDTH, STAGE_HEIGHT);
background.graphics.endFill();
uiContainer.addChild(background);
background = new Sprite();
background.graphics.beginFill(0xA2A2A2);
background.graphics.drawRect(0, 0, STAGE_WIDTH, STAGE_HEIGHT);
background.graphics.endFill();
uiContainer.addChild(background);
flixelButton = createButton("Flixel", 0xFF0000);
uiContainer.addChild(flixelButton);
flixelButton = createButton("Flixel", 0xFF0000);
uiContainer.addChild(flixelButton);
starlingButton = createButton("Starling", 0x00FF00);
uiContainer.addChild(starlingButton);
starlingButton = createButton("Starling", 0x00FF00);
uiContainer.addChild(starlingButton);
positionButtons();
positionButtons();
flixelButton.addEventListener(MouseEvent.CLICK, onFlixelClick);
starlingButton.addEventListener(MouseEvent.CLICK, onStarlingClick);
}
flixelButton.addEventListener(MouseEvent.CLICK, onFlixelClick);
starlingButton.addEventListener(MouseEvent.CLICK, onStarlingClick);
}
private function createButton(label:String, color:Int):Sprite {
private function createButton(label:String, color:Int):Sprite {
var button = new Sprite();
var g = button.graphics;
@ -116,53 +114,54 @@ class Main extends Sprite {
return button;
}
private function positionButtons():Void {
var totalHeight = (BUTTON_HEIGHT * 2) + BUTTON_SPACING;
var startY = (STAGE_HEIGHT - totalHeight) / 2;
private function positionButtons():Void {
var totalHeight = (BUTTON_HEIGHT * 2) + BUTTON_SPACING;
var startY = (STAGE_HEIGHT - totalHeight) / 2;
flixelButton.x = (STAGE_WIDTH - BUTTON_WIDTH) / 2;
flixelButton.y = startY + BUTTON_HEIGHT + BUTTON_SPACING;
flixelButton.x = (STAGE_WIDTH - BUTTON_WIDTH) / 2;
flixelButton.y = startY + BUTTON_HEIGHT + BUTTON_SPACING;
starlingButton.x = (STAGE_WIDTH - BUTTON_WIDTH) / 2;
starlingButton.y = startY;
}
starlingButton.x = (STAGE_WIDTH - BUTTON_WIDTH) / 2;
starlingButton.y = startY;
}
private function centerUI():Void {
uiContainer.x = (stage.stageWidth - STAGE_WIDTH) / 2;
uiContainer.y = (stage.stageHeight - STAGE_HEIGHT) / 2;
}
uiContainer.x = (stage.stageWidth - STAGE_WIDTH) / 2;
uiContainer.y = (stage.stageHeight - STAGE_HEIGHT) / 2;
}
private function onResize(e:Event):Void {
centerUI();
}
private function onResize(e:Event):Void {
centerUI();
}
private function onFlixelClick(e:MouseEvent):Void {
trace("Launching Flixel game");
private function onFlixelClick(e:MouseEvent):Void {
trace("Launching Flixel game");
destroyUI();
addChild(new FlxGame(640, 480, FlixelState));
FlxG.autoPause = false;
}
}
private function destroyUI():Void {
flixelButton.removeEventListener(MouseEvent.CLICK, onFlixelClick);
starlingButton.removeEventListener(MouseEvent.CLICK, onStarlingClick);
stage.removeEventListener(Event.RESIZE, onResize);
flixelButton.removeEventListener(MouseEvent.CLICK, onFlixelClick);
starlingButton.removeEventListener(MouseEvent.CLICK, onStarlingClick);
stage.removeEventListener(Event.RESIZE, onResize);
removeChild(uiContainer);
removeChild(uiContainer);
background = null;
flixelButton = null;
starlingButton = null;
uiContainer = null;
}
background = null;
flixelButton = null;
starlingButton = null;
uiContainer = null;
}
private var starlingSingleton:Starling;
private function onStarlingClick(e:MouseEvent):Void {
trace("Launching Starling game");
private function onStarlingClick(e:MouseEvent):Void {
trace("Launching Starling game");
starlingSingleton = new Starling(starling.display.Sprite, stage, new Rectangle(0, 0, 800, 600));
starlingSingleton.supportHighResolutions = true;
starlingSingleton.addEventListener(Event.ROOT_CREATED, onStarlingRootCreated);
}
}
private function onStarlingRootCreated(event:Event):Void {
destroyUI();

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package;
@ -34,10 +34,8 @@ import flixel.FlxG;
import flixel.FlxGame;
import openfl.display.Sprite;
class MainFlixel extends Sprite
{
public function new()
{
class MainFlixel extends Sprite {
public function new() {
super();
addChild(new FlxGame(640, 480, FlixelState));
FlxG.autoPause = false;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package;

View File

@ -25,11 +25,10 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package flixelExamples;
import flixel.util.FlxColor;
import flixel.text.FlxText;
import spine.Skin;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package flixelExamples;
@ -43,6 +43,7 @@ class BasicExample extends FlxState {
var loadBinary = true;
var skeletonSprite:SkeletonSprite;
override public function create():Void {
FlxG.cameras.bgColor = 0xffa1b2b0;
@ -66,22 +67,20 @@ class BasicExample extends FlxState {
trace("loaded");
}
override public function update(elapsed:Float):Void
{
if (FlxG.keys.anyPressed([RIGHT])) {
skeletonSprite.x += 15;
}
if (FlxG.keys.anyPressed([LEFT])) {
skeletonSprite.x -= 15;
}
if (FlxG.keys.anyPressed([DOWN])) {
skeletonSprite.y += 15;
}
if (FlxG.keys.anyPressed([UP])) {
skeletonSprite.y -= 15;
}
super.update(elapsed);
override public function update(elapsed:Float):Void {
if (FlxG.keys.anyPressed([RIGHT])) {
skeletonSprite.x += 15;
}
if (FlxG.keys.anyPressed([LEFT])) {
skeletonSprite.x -= 15;
}
if (FlxG.keys.anyPressed([DOWN])) {
skeletonSprite.y += 15;
}
if (FlxG.keys.anyPressed([UP])) {
skeletonSprite.y -= 15;
}
super.update(elapsed);
}
}

View File

@ -25,11 +25,10 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package flixelExamples;
import flixel.text.FlxText;
import flixel.math.FlxPoint;
import spine.Skin;
@ -47,6 +46,7 @@ class CelestialCircusExample extends FlxState {
var loadBinary = true;
var skeletonSprite:SkeletonSprite;
override public function create():Void {
FlxG.cameras.bgColor = 0xffa1b2b0;
@ -55,7 +55,8 @@ class CelestialCircusExample extends FlxState {
add(button);
var atlas = new TextureAtlas(Assets.getText("assets/celestial-circus.atlas"), new FlixelTextureLoader("assets/celestial-circus.atlas"));
var data = SkeletonData.from(loadBinary ? Assets.getBytes("assets/celestial-circus-pro.skel") : Assets.getText("assets/celestial-circus-pro.json"), atlas, .15);
var data = SkeletonData.from(loadBinary ? Assets.getBytes("assets/celestial-circus-pro.skel") : Assets.getText("assets/celestial-circus-pro.json"),
atlas, .15);
var animationStateData = new AnimationStateData(data);
animationStateData.defaultMix = 0.25;
@ -73,32 +74,27 @@ class CelestialCircusExample extends FlxState {
var dragging:Bool = false;
var lastX:Float = 0;
var lastY:Float = 0;
override public function update(elapsed:Float):Void
{
override public function update(elapsed:Float):Void {
super.update(elapsed);
mousePosition = FlxG.mouse.getPosition();
if (FlxG.mouse.justPressed && skeletonSprite.overlapsPoint(mousePosition))
{
if (FlxG.mouse.justPressed && skeletonSprite.overlapsPoint(mousePosition)) {
dragging = true;
lastX = mousePosition.x;
lastY = mousePosition.y;
lastY = mousePosition.y;
}
if (FlxG.mouse.justReleased) dragging = false;
if (FlxG.mouse.justReleased)
dragging = false;
if (dragging)
{
if (dragging) {
skeletonSprite.x += mousePosition.x - lastX;
skeletonSprite.y += mousePosition.y - lastY;
skeletonSprite.skeleton.physicsTranslate(
mousePosition.x - lastX,
mousePosition.y - lastY,
);
skeletonSprite.skeleton.physicsTranslate(mousePosition.x - lastX, mousePosition.y - lastY,);
lastX = mousePosition.x;
lastY = mousePosition.y;
lastY = mousePosition.y;
}
}
}

View File

@ -25,11 +25,10 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package flixelExamples;
import spine.Skin;
import flixel.ui.FlxButton;
import flixel.FlxG;

View File

@ -25,11 +25,10 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package flixelExamples;
import flixel.util.FlxSave;
import flixel.math.FlxPoint;
import flixel.util.FlxColor;
@ -49,7 +48,8 @@ class ControlBonesExample extends FlxState {
var loadBinary = true;
private var controlBones = [];
private var controls:Array<FlxSprite> = [];
private var controls:Array<FlxSprite> = [];
override public function create():Void {
FlxG.cameras.bgColor = 0xffa1b2b0;
@ -92,7 +92,7 @@ class ControlBonesExample extends FlxState {
}
var point = [.0, .0];
skeletonSprite.beforeUpdateWorldTransforms = function (go) {
skeletonSprite.beforeUpdateWorldTransforms = function(go) {
for (i in 0...controls.length) {
var bone = controlBones[i];
var control = controls[i];
@ -101,7 +101,7 @@ class ControlBonesExample extends FlxState {
go.haxeWorldCoordinatesToBone(point, bone);
bone.pose.x = point[0];
bone.pose.y = point[1];
}
}
};
super.create();
@ -111,25 +111,24 @@ class ControlBonesExample extends FlxState {
var offsetX:Float = 0;
var offsetY:Float = 0;
var sprite:FlxSprite;
override public function update(elapsed:Float):Void
{
override public function update(elapsed:Float):Void {
super.update(elapsed);
mousePosition = FlxG.mouse.getPosition();
for (control in controls) {
if (FlxG.mouse.justPressed && control.overlapsPoint(mousePosition))
{
if (FlxG.mouse.justPressed && control.overlapsPoint(mousePosition)) {
sprite = control;
offsetX = mousePosition.x - sprite.x;
offsetY = mousePosition.y - sprite.y;
}
}
if (FlxG.mouse.justReleased) sprite = null;
if (FlxG.mouse.justReleased)
sprite = null;
if (sprite != null)
{
if (sprite != null) {
sprite.x = mousePosition.x - offsetX;
sprite.y = mousePosition.y - offsetY;
}

View File

@ -25,11 +25,10 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package flixelExamples;
import flixel.text.FlxText;
import flixel.ui.FlxButton;
import flixel.FlxG;
@ -76,9 +75,7 @@ class EventsExample extends FlxState {
skeletonSprite.skeleton.setupPoseBones();
add(skeletonSprite);
trackEntry.onEvent.add(
(entry, event) -> log('Custom event for ${entry.animation.name}: ${event.data.name}'));
trackEntry.onEvent.add((entry, event) -> log('Custom event for ${entry.animation.name}: ${event.data.name}'));
add(textContainer);
super.create();
@ -88,6 +85,7 @@ class EventsExample extends FlxState {
private var logs = new Array<FlxText>();
private var logsNumber = 0;
private var yOffset = 12;
private function log(text:String) {
var length = logs.length;
var newLog = new FlxText(250, 30, text);

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package flixelExamples;
@ -43,8 +43,7 @@ import flixel.FlxG;
import flixel.FlxState;
import flixel.text.FlxText;
class FlixelState extends FlxState
{
class FlixelState extends FlxState {
var spineSprite:SkeletonSprite;
var sprite:FlxSprite;
var sprite2:FlxSprite;
@ -57,8 +56,7 @@ class FlixelState extends FlxState
var scale = 4;
var speed:Float;
override public function create():Void
{
override public function create():Void {
FlxG.cameras.bgColor = 0xffa1b2b0;
// setting speed of spineboy (450 is the speed to not let him slide)
@ -76,8 +74,8 @@ class FlixelState extends FlxState
// creating the text to display overlapping state
myText = new FlxText(0, 25, 150, "", 16);
myText.alignment = CENTER;
group.add(myText);
myText.alignment = CENTER;
group.add(myText);
var button = new FlxButton(0, 0, "Next scene", () -> FlxG.switchState(() -> new BasicExample()));
button.setPosition(FlxG.width * .75, FlxG.height / 10);
@ -92,14 +90,14 @@ class FlixelState extends FlxState
// instructions
var groupInstructions = new FlxSpriteGroup();
groupInstructions.setPosition(50, 405);
groupInstructions.add(new FlxText(0, 0, 200, "Left/Right - Move", 16));
groupInstructions.add(new FlxText(0, 25, 150, "Space - Jump", 16));
groupInstructions.add(new FlxText(200, 25, 400, "Click the button for the next example", 16));
groupInstructions.add(new FlxText(0, 0, 200, "Left/Right - Move", 16));
groupInstructions.add(new FlxText(0, 25, 150, "Space - Jump", 16));
groupInstructions.add(new FlxText(200, 25, 400, "Click the button for the next example", 16));
add(groupInstructions);
// loading spineboy
var atlas = new TextureAtlas(Assets.getText("assets/spineboy.atlas"), new FlixelTextureLoader("assets/spineboy.atlas"));
var skeletondata = SkeletonData.from(Assets.getText("assets/spineboy-pro.json"), atlas, 1/scale);
var skeletondata = SkeletonData.from(Assets.getText("assets/spineboy-pro.json"), atlas, 1 / scale);
var animationStateData = new AnimationStateData(skeletondata);
spineSprite = new SkeletonSprite(skeletondata, animationStateData);
@ -166,8 +164,8 @@ class FlixelState extends FlxState
}
var justSetIdle = true;
override public function update(elapsed:Float):Void
{
override public function update(elapsed:Float):Void {
if (FlxG.overlap(spineSprite, group)) {
myText.text = "Overlapping";
} else {
@ -191,11 +189,13 @@ class FlixelState extends FlxState
var flipped = false;
var deltaX;
if (FlxG.keys.anyPressed([RIGHT])) {
if (spineSprite.flipX == true) flipped = true;
if (spineSprite.flipX == true)
flipped = true;
spineSprite.flipX = false;
}
if (FlxG.keys.anyPressed([LEFT])) {
if (spineSprite.flipX == false) flipped = true;
if (spineSprite.flipX == false)
flipped = true;
spineSprite.flipX = true;
}
@ -211,14 +211,12 @@ class FlixelState extends FlxState
spineSprite.state.setAnimationByName(0, "walk", true);
}
}
} else if (!jumping && !justSetIdle) {
justSetWalking = false;
justSetIdle = true;
spineSprite.state.setAnimationByName(0, "idle", true);
}
super.update(elapsed);
}
}

View File

@ -25,11 +25,10 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package flixelExamples;
import spine.Skin;
import flixel.ui.FlxButton;
import flixel.FlxG;
@ -43,9 +42,10 @@ import spine.atlas.TextureAtlas;
class MixAndMatchExample extends FlxState {
var loadBinary = false;
// var loadBinary = true;
// var loadBinary = true;
var skeletonSprite:SkeletonSprite;
override public function create():Void {
FlxG.cameras.bgColor = 0xffa1b2b0;
@ -54,7 +54,8 @@ class MixAndMatchExample extends FlxState {
add(button);
var atlas = new TextureAtlas(Assets.getText("assets/mix-and-match.atlas"), new FlixelTextureLoader("assets/mix-and-match.atlas"));
var data = SkeletonData.from(loadBinary ? Assets.getBytes("assets/mix-and-match-pro.skel") : Assets.getText("assets/mix-and-match-pro.json"), atlas, .5);
var data = SkeletonData.from(loadBinary ? Assets.getBytes("assets/mix-and-match-pro.skel") : Assets.getText("assets/mix-and-match-pro.json"), atlas,
.5);
var animationStateData = new AnimationStateData(data);
animationStateData.defaultMix = 0.25;
@ -80,5 +81,4 @@ class MixAndMatchExample extends FlxState {
super.create();
}
}

View File

@ -25,11 +25,10 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package flixelExamples;
import spine.Skin;
import flixel.ui.FlxButton;
import flixel.FlxG;

View File

@ -25,11 +25,10 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package flixelExamples;
import flixel.ui.FlxButton;
import flixel.FlxG;
import spine.flixel.SkeletonSprite;
@ -44,6 +43,7 @@ class SequenceExample extends FlxState {
var loadBinary = true;
var skeletonSprite:SkeletonSprite;
override public function create():Void {
FlxG.cameras.bgColor = 0xffa1b2b0;
@ -64,5 +64,4 @@ class SequenceExample extends FlxState {
add(skeletonSprite);
super.create();
}
}

View File

@ -25,11 +25,10 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package flixelExamples;
import spine.Skin;
import flixel.ui.FlxButton;
import flixel.FlxG;

View File

@ -25,11 +25,10 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package flixelExamples;
import spine.Skin;
import flixel.ui.FlxButton;
import flixel.FlxG;

View File

@ -25,11 +25,10 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package flixelExamples;
import spine.Skin;
import flixel.ui.FlxButton;
import flixel.FlxG;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package starlingExamples;
@ -44,8 +44,9 @@ import starling.display.Quad;
class AnimationBoundExample extends Scene {
var loadBinary = false;
var skeletonSpriteClipping: SkeletonSprite;
var skeletonSpriteNoClipping: SkeletonSprite;
var skeletonSpriteClipping:SkeletonSprite;
var skeletonSpriteNoClipping:SkeletonSprite;
public function load():Void {
background.color = 0x333333;
var scale = .2;
@ -66,8 +67,8 @@ class AnimationBoundExample extends Scene {
var animationClipping = skeletonSpriteClipping.state.setAnimationByName(0, "portal", true).animation;
var animationBoundClipping = skeletonSpriteClipping.getAnimationBounds(animationClipping, true);
var quad:Quad = new Quad(animationBoundClipping.width * scale, animationBoundClipping.height * scale, 0xc70000);
quad.x = skeletonSpriteClipping.x + animationBoundClipping.x * scale;
quad.y = skeletonSpriteClipping.y + animationBoundClipping.y * scale;
quad.x = skeletonSpriteClipping.x + animationBoundClipping.x * scale;
quad.y = skeletonSpriteClipping.y + animationBoundClipping.y * scale;
var animationStateDataNoClipping = new AnimationStateData(skeletondata);
animationStateDataNoClipping.defaultMix = 0.25;
@ -80,8 +81,8 @@ class AnimationBoundExample extends Scene {
var animationNoClipping = skeletonSpriteNoClipping.state.setAnimationByName(0, "portal", true).animation;
var animationBoundNoClipping = skeletonSpriteNoClipping.getAnimationBounds(animationNoClipping, false);
var quadNoClipping:Quad = new Quad(animationBoundNoClipping.width * scale, animationBoundNoClipping.height * scale, 0xc70000);
quadNoClipping.x = skeletonSpriteNoClipping.x + animationBoundNoClipping.x * scale;
quadNoClipping.y = skeletonSpriteNoClipping.y + animationBoundNoClipping.y * scale;
quadNoClipping.x = skeletonSpriteNoClipping.x + animationBoundNoClipping.x * scale;
quadNoClipping.y = skeletonSpriteNoClipping.y + animationBoundNoClipping.y * scale;
addChild(quad);
addChild(quadNoClipping);

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package starlingExamples;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package starlingExamples;
@ -52,7 +52,8 @@ class CelestialCircusExample extends Scene {
background.color = 0x333333;
var atlas = new TextureAtlas(Assets.getText("assets/celestial-circus.atlas"), new StarlingTextureLoader("assets/celestial-circus.atlas"));
var skeletondata = SkeletonData.from(loadBinary ? Assets.getBytes("assets/celestial-circus-pro.skel") : Assets.getText("assets/celestial-circus-pro.json"), atlas);
var skeletondata = SkeletonData.from(loadBinary ? Assets.getBytes("assets/celestial-circus-pro.skel") : Assets.getText("assets/celestial-circus-pro.json"),
atlas);
var animationStateData = new AnimationStateData(skeletondata);
animationStateData.defaultMix = 0.25;
@ -83,10 +84,7 @@ class CelestialCircusExample extends Scene {
skeletonTouch.getMovement(this, movement);
skeletonSprite.x += movement.x;
skeletonSprite.y += movement.y;
skeletonSprite.skeleton.physicsTranslate(
movement.x / skeletonSprite.scale,
movement.y / skeletonSprite.scale,
);
skeletonSprite.skeleton.physicsTranslate(movement.x / skeletonSprite.scale, movement.y / skeletonSprite.scale,);
}
} else {
var sceneTouch = e.getTouch(this);
@ -94,8 +92,5 @@ class CelestialCircusExample extends Scene {
SceneManager.getInstance().switchScene(new SnowglobeExample());
}
}
}
}

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package starlingExamples;
@ -58,7 +58,6 @@ class CloudPotExample extends Scene {
skeletonSprite.skeleton.updateWorldTransform(Physics.update);
var bounds = skeletonSprite.skeleton.getBounds();
skeletonSprite.scale = 0.2;
skeletonSprite.x = Starling.current.stage.stageWidth / 2;
skeletonSprite.y = Starling.current.stage.stageHeight / 2;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package starlingExamples;
@ -48,11 +48,12 @@ class ControlBonesExample extends Scene {
var skeletonSprite:SkeletonSprite;
private var movement = new openfl.geom.Point();
private var controlBones = [];
private var controls = [];
private var controls = [];
public function load():Void {
var atlas = new TextureAtlas(Assets.getText("assets/stretchyman.atlas"), new StarlingTextureLoader("assets/stretchyman.atlas"));
var skeletondata = SkeletonData.from(loadBinary ? Assets.getBytes("assets/stretchyman-pro.skel") : Assets.getText("assets/stretchyman-pro.json"), atlas);
var skeletondata = SkeletonData.from(loadBinary ? Assets.getBytes("assets/stretchyman-pro.skel") : Assets.getText("assets/stretchyman-pro.json"),
atlas);
var animationStateData = new AnimationStateData(skeletondata);
animationStateData.defaultMix = 0.25;
@ -97,7 +98,7 @@ class ControlBonesExample extends Scene {
}
var point = [.0, .0];
skeletonSprite.beforeUpdateWorldTransforms = function (go) {
skeletonSprite.beforeUpdateWorldTransforms = function(go) {
for (i in 0...controls.length) {
var bone = controlBones[i];
var control = controls[i];
@ -106,7 +107,7 @@ class ControlBonesExample extends Scene {
go.haxeWorldCoordinatesToBone(point, bone);
bone.pose.x = point[0];
bone.pose.y = point[1];
}
}
};
addEventListener(TouchEvent.TOUCH, onTouch);

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package starlingExamples;
@ -66,8 +66,7 @@ class EventsExample extends Scene {
// add callback to the TrackEntry
skeletonSprite.state.setAnimationByName(0, "walk", true);
var trackEntry = skeletonSprite.state.addAnimationByName(0, "run", true, 3);
trackEntry.onEvent.add(
(entry, event) -> log('Custom event for ${entry.animation.name}: ${event.data.name}'));
trackEntry.onEvent.add((entry, event) -> log('Custom event for ${entry.animation.name}: ${event.data.name}'));
addChild(skeletonSprite);
juggler.add(skeletonSprite);
@ -83,6 +82,7 @@ class EventsExample extends Scene {
private var logs = new Array<TextField>();
private var logsNumber = 0;
private var yOffset = 12;
private function log(text:String) {
var length = logs.length;
var newLog = new TextField(250, 30, text);

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package starlingExamples;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package starlingExamples;
@ -58,7 +58,7 @@ class SackExample extends Scene {
skeletonSprite.scale = 0.2;
skeletonSprite.x = Starling.current.stage.stageWidth / 2;
skeletonSprite.y = Starling.current.stage.stageHeight/ 2;
skeletonSprite.y = Starling.current.stage.stageHeight / 2;
skeletonSprite.state.setAnimationByName(0, "cape-follow-example", true);

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package starlingExamples;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package starlingExamples;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package starlingExamples;
@ -57,10 +57,9 @@ class SnowglobeExample extends Scene {
skeletonSprite.skeleton.updateWorldTransform(Physics.update);
var bounds = skeletonSprite.skeleton.getBounds();
skeletonSprite.scale = 0.15;
skeletonSprite.x = Starling.current.stage.stageWidth / 2;
skeletonSprite.y = Starling.current.stage.stageHeight/ 1.5;
skeletonSprite.y = Starling.current.stage.stageHeight / 1.5;
skeletonSprite.state.setAnimationByName(0, "shake", true);

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package starlingExamples;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package starlingExamples;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package starlingExamples;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
@ -37,7 +37,8 @@ package spine;
class Bone extends PosedActive<BoneData, BoneLocal, BonePose> {
static public var yDown:Bool = false;
static public var yDir(get, never):Int;
static private function get_yDir(): Int {
static private function get_yDir():Int {
return Bone.yDown ? -1 : 1;
}
@ -49,7 +50,7 @@ class Bone extends PosedActive<BoneData, BoneLocal, BonePose> {
public var sorted = false;
public function new (data:BoneData, parent:Bone) {
public function new(data:BoneData, parent:Bone) {
super(data, new BonePose(), new BonePose());
this.parent = parent;
applied.bone = this;

View File

@ -25,13 +25,12 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
/** The setup pose for a bone. */
class BoneData extends PosedData<BoneLocal> {
/** The index of the bone in spine.Skeleton.getBones(). */
public final index:Int;
@ -41,6 +40,7 @@ class BoneData extends PosedData<BoneLocal> {
public var length = 0.;
// Nonessential.
/** The color of the bone as it was in Spine, or a default color if nonessential data was not exported. Bones are not usually
* rendered at runtime. */
public var color = new Color(0, 0, 0, 0);
@ -51,10 +51,12 @@ class BoneData extends PosedData<BoneLocal> {
/** False if the bone was hidden in Spine and nonessential data was exported. Does not affect runtime rendering. */
public var visible = false;
public function new (index:Int, name:String, parent:BoneData) {
public function new(index:Int, name:String, parent:BoneData) {
super(name, new BoneLocal());
if (index < 0) throw new SpineException("index must be >= 0.");
if (name == null) throw new SpineException("name cannot be null.");
if (index < 0)
throw new SpineException("index must be >= 0.");
if (name == null)
throw new SpineException("name cannot be null.");
this.index = index;
this.parent = parent;
}

View File

@ -25,13 +25,12 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
/** Stores a bone's local pose. */
class BoneLocal implements Pose<BoneLocal> {
/** The local x translation. */
public var x:Float = 0;
@ -55,17 +54,19 @@ class BoneLocal implements Pose<BoneLocal> {
/** Determines how parent world transforms affect this bone. */
public var inherit(default, set):Inherit;
function set_inherit (value:Inherit):Inherit {
if (value == null) throw new SpineException("inherit cannot be null.");
function set_inherit(value:Inherit):Inherit {
if (value == null)
throw new SpineException("inherit cannot be null.");
inherit = value;
return value;
}
public function new () {
}
public function new() {}
public function set (pose:BoneLocal):Void {
if (pose == null) throw new SpineException("pose cannot be null.");
public function set(pose:BoneLocal):Void {
if (pose == null)
throw new SpineException("pose cannot be null.");
x = pose.x;
y = pose.y;
rotation = pose.rotation;
@ -75,5 +76,4 @@ class BoneLocal implements Pose<BoneLocal> {
shearY = pose.shearY;
inherit = pose.inherit;
}
}

View File

@ -25,14 +25,13 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
/** The applied pose for a bone. This is the {@link Bone} pose with constraints applied and the world transform computed by
* Skeleton.updateWorldTransform(Physics). */
class BonePose extends BoneLocal implements Update {
public var bone:Bone;
/** Part of the world transform matrix for the X axis. If changed, updateAppliedTransform() should be called. */
@ -61,14 +60,15 @@ class BonePose extends BoneLocal implements Update {
// }
/** Called by Skeleton.updateCache() to compute the world transform, if needed. */
public function update (skeleton:Skeleton, physics:Physics):Void {
if (world != skeleton._update) updateWorldTransform(skeleton);
public function update(skeleton:Skeleton, physics:Physics):Void {
if (world != skeleton._update)
updateWorldTransform(skeleton);
}
/** Computes the world transform using the parent bone's applied pose and this pose. Child bones are not updated.
*
* @see https://esotericsoftware.com/spine-runtime-skeletons#World-transforms World transforms in the Spine Runtimes Guide
*/
*
* @see https://esotericsoftware.com/spine-runtime-skeletons#World-transforms World transforms in the Spine Runtimes Guide
*/
public function updateWorldTransform(skeleton:Skeleton):Void {
if (local == skeleton._update)
updateLocalTransform(skeleton);
@ -139,15 +139,19 @@ class BonePose extends BoneLocal implements Update {
c = pc * la + pd * lc;
d = pc * lb + pd * ld;
case Inherit.noScale, Inherit.noScaleOrReflection:
var r = rotation * MathUtils.degRad, cos = Math.cos(r), sin = Math.sin(r);
var r = rotation * MathUtils.degRad,
cos = Math.cos(r),
sin = Math.sin(r);
var za = (pa * cos + pb * sin) / skeleton.scaleX;
var zc = (pc * cos + pd * sin) / skeleton.scaleY;
var s = Math.sqrt(za * za + zc * zc);
if (s > 0.00001) s = 1 / s;
if (s > 0.00001)
s = 1 / s;
za *= s;
zc *= s;
s = Math.sqrt(za * za + zc * zc);
if (inherit == Inherit.noScale && ((pa * pd - pb * pc < 0) != ((skeleton.scaleX < 0) != (skeleton.scaleY < 0)))) s = -s;
if (inherit == Inherit.noScale && ((pa * pd - pb * pc < 0) != ((skeleton.scaleX < 0) != (skeleton.scaleY < 0))))
s = -s;
r = Math.PI / 2 + Math.atan2(zc, za);
var zb:Float = Math.cos(r) * s;
var zd:Float = Math.sin(r) * s;
@ -169,13 +173,13 @@ class BonePose extends BoneLocal implements Update {
}
/** Computes the applied transform values from the world transform.
*
* If the world transform is modified (by a constraint, rotateWorld(), etc) then this method should be called so
* the applied transform matches the world transform. The applied transform may be needed by other code (eg to apply another
* constraint).
*
* Some information is ambiguous in the world transform, such as -1,-1 scale versus 180 rotation. The applied transform after
* calling this method is equivalent to the local transform used to compute the world transform, but may not be identical. */
*
* If the world transform is modified (by a constraint, rotateWorld(), etc) then this method should be called so
* the applied transform matches the world transform. The applied transform may be needed by other code (eg to apply another
* constraint).
*
* Some information is ambiguous in the world transform, such as -1,-1 scale versus 180 rotation. The applied transform after
* calling this method is equivalent to the local transform used to compute the world transform, but may not be identical. */
public function updateLocalTransform(skeleton:Skeleton):Void {
local = 0;
world = skeleton._update;
@ -215,15 +219,19 @@ class BonePose extends BoneLocal implements Update {
ia = pd * pid;
ib = pb * pid;
case Inherit.noScale, Inherit.noScaleOrReflection:
var r = rotation * MathUtils.degRad, cos = Math.cos(rotation), sin = Math.sin(rotation);
var r = rotation * MathUtils.degRad,
cos = Math.cos(rotation),
sin = Math.sin(rotation);
pa = (pa * cos + pb * sin) / skeleton.scaleX;
pc = (pc * cos + pd * sin) / skeleton.scaleY;
var s = Math.sqrt(pa * pa + pc * pc);
if (s > 0.00001) s = 1 / s;
if (s > 0.00001)
s = 1 / s;
pa *= s;
pc *= s;
s = Math.sqrt(pa * pa + pc * pc);
if (inherit == Inherit.noScale && (pid < 0 != ((skeleton.scaleX < 0) != (skeleton.scaleY < 0)))) s = -s;
if (inherit == Inherit.noScale && (pid < 0 != ((skeleton.scaleX < 0) != (skeleton.scaleY < 0))))
s = -s;
r = MathUtils.PI / 2 + Math.atan2(pc, pa);
pb = Math.cos(r) * s;
pd = Math.sin(r) * s;
@ -255,24 +263,26 @@ class BonePose extends BoneLocal implements Update {
}
/** If the world transform has been modified and the local transform no longer matches, {@link #updateLocalTransform(Skeleton)}
* is called. */
public function validateLocalTransform (skeleton: Skeleton) {
if (local == skeleton._update) updateLocalTransform(skeleton);
* is called. */
public function validateLocalTransform(skeleton:Skeleton) {
if (local == skeleton._update)
updateLocalTransform(skeleton);
}
public function modifyLocal (skeleton: Skeleton) {
if (local == skeleton._update) updateLocalTransform(skeleton);
public function modifyLocal(skeleton:Skeleton) {
if (local == skeleton._update)
updateLocalTransform(skeleton);
world = 0;
resetWorld(skeleton._update);
}
public function modifyWorld (update:Int) {
public function modifyWorld(update:Int) {
local = update;
world = update;
resetWorld(update);
}
public function resetWorld (update:Int) {
public function resetWorld(update:Int) {
var children = bone.children;
for (i in 0...bone.children.length) {
var child = children[i].applied;
@ -331,14 +341,14 @@ class BonePose extends BoneLocal implements Update {
}
/** Transforms a point from world coordinates to the parent bone's local coordinates. */
public function worldToParent(world: Array<Float>):Array<Float> {
public function worldToParent(world:Array<Float>):Array<Float> {
if (world == null)
throw new SpineException("world cannot be null.");
return bone.parent == null ? world : bone.parent.applied.worldToLocal(world);
}
/** Transforms a point from the parent bone's coordinates to world coordinates. */
public function parentToWorld(world: Array<Float>):Array<Float> {
public function parentToWorld(world:Array<Float>):Array<Float> {
if (world == null)
throw new SpineException("world cannot be null.");
return bone.parent == null ? world : bone.parent.applied.localToWorld(world);
@ -373,7 +383,7 @@ class BonePose extends BoneLocal implements Update {
d = sin * rb + cos * d;
}
public function toString ():String {
public function toString():String {
return bone.data.name;
}
}

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
@ -33,17 +33,16 @@ abstract class Constraint< //
T:Constraint<T, D, P>, //
D:ConstraintData<T, P>, //
P:Pose<Any>> //
extends PosedActive<D, P, P> implements Update {
public function new (data:D, pose:P, constrained:P) {
extends PosedActive<D, P, P> implements Update {
public function new(data:D, pose:P, constrained:P) {
super(data, pose, constrained);
}
public abstract function copy (skeleton:Skeleton):T;
public abstract function copy(skeleton:Skeleton):T;
public abstract function sort (skeleton:Skeleton):Void;
public abstract function sort(skeleton:Skeleton):Void;
public function isSourceActive ():Bool {
public function isSourceActive():Bool {
return true;
}
}
}

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
@ -33,11 +33,10 @@ package spine;
abstract class ConstraintData< //
T:Constraint<Dynamic, Dynamic, Dynamic>, //
P:Pose<Any>> //
extends PosedData<P> {
extends PosedData<P> {
function new(name:String, setup:P) {
super(name, setup);
}
public abstract function create (skeleton:Skeleton):T;
public abstract function create(skeleton:Skeleton):T;
}

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
@ -50,7 +50,8 @@ class Event {
public var balance = 0.;
public function new(time:Float, data:EventData) {
if (data == null) throw new SpineException("data cannot be null.");
if (data == null)
throw new SpineException("data cannot be null.");
this.time = time;
this.data = data;
}

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;

View File

@ -25,19 +25,23 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
interface HasTextureRegion {
/** The name used to find the region. */
public var path:String;
/** Sets the region used to draw the attachment. After setting the region or if the region's properties are changed,
* updateRegion() must be called. */
public var region:TextureRegion;
/** The color to tint the attachment. */
public var color:Color;
public var sequence:Sequence;
/** Updates any values the attachment calculates using the region. Must be called after setting the
* region or if the region's properties are changed. */
public function updateRegion():Void;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
@ -34,7 +34,6 @@ package spine;
*
* @see https://esotericsoftware.com/spine-ik-constraints IK constraints in the Spine User Guide */
class IkConstraint extends Constraint<IkConstraint, IkConstraintData, IkConstraintPose> {
/** The 1 or 2 bones that will be modified by this IK constraint. */
public final bones:Array<BonePose>;
@ -43,7 +42,8 @@ class IkConstraint extends Constraint<IkConstraint, IkConstraintData, IkConstrai
public function new(data:IkConstraintData, skeleton:Skeleton) {
super(data, new IkConstraintPose(), new IkConstraintPose());
if (skeleton == null) throw new SpineException("skeleton cannot be null.");
if (skeleton == null)
throw new SpineException("skeleton cannot be null.");
bones = new Array<BonePose>();
for (boneData in data.bones)
@ -51,24 +51,27 @@ class IkConstraint extends Constraint<IkConstraint, IkConstraintData, IkConstrai
target = skeleton.bones[data.target.index];
}
public function copy (skeleton:Skeleton) {
public function copy(skeleton:Skeleton) {
var copy = new IkConstraint(data, skeleton);
copy.pose.set(pose);
return copy;
}
/** Applies the constraint to the constrained bones. */
public function update (skeleton:Skeleton, physics:Physics):Void {
public function update(skeleton:Skeleton, physics:Physics):Void {
var p = applied;
if (p.mix == 0) return;
if (p.mix == 0)
return;
var target = target.applied;
switch (bones.length) {
case 1: apply1(skeleton, bones[0], target.worldX, target.worldY, p.compress, p.stretch, data.uniform, p.mix);
case 2: apply2(skeleton, bones[0], bones[1], target.worldX, target.worldY, p.bendDirection, p.stretch, data.uniform, p.softness, p.mix);
case 1:
apply1(skeleton, bones[0], target.worldX, target.worldY, p.compress, p.stretch, data.uniform, p.mix);
case 2:
apply2(skeleton, bones[0], bones[1], target.worldX, target.worldY, p.bendDirection, p.stretch, data.uniform, p.softness, p.mix);
}
}
public function sort (skeleton:Skeleton) {
public function sort(skeleton:Skeleton) {
skeleton.sortBone(target);
var parent = bones[0].bone;
skeleton.sortBone(parent);
@ -76,24 +79,25 @@ class IkConstraint extends Constraint<IkConstraint, IkConstraintData, IkConstrai
parent.sorted = false;
skeleton.sortReset(parent.children);
skeleton.constrained(parent);
if (bones.length > 1) skeleton.constrained(bones[1].bone);
if (bones.length > 1)
skeleton.constrained(bones[1].bone);
}
override public function isSourceActive () {
override public function isSourceActive() {
return target.active;
}
public function set_target (target:Bone):Bone {
if (target == null) throw new SpineException("target cannot be null.");
public function set_target(target:Bone):Bone {
if (target == null)
throw new SpineException("target cannot be null.");
this.target = target;
return target;
}
/** Applies 1 bone IK. The target is specified in the world coordinate system. */
static public function apply1(skeleton:Skeleton, bone:BonePose, targetX:Float, targetY:Float, compress:Bool, stretch:Bool,
uniform:Bool, mix:Float) {
if (bone == null) throw new SpineException("bone cannot be null.");
static public function apply1(skeleton:Skeleton, bone:BonePose, targetX:Float, targetY:Float, compress:Bool, stretch:Bool, uniform:Bool, mix:Float) {
if (bone == null)
throw new SpineException("bone cannot be null.");
bone.modifyLocal(skeleton);
var p = bone.bone.parent.applied;
var pa = p.a, pb = p.b, pc = p.c, pd = p.d;
@ -127,7 +131,8 @@ class IkConstraint extends Constraint<IkConstraint, IkConstraintData, IkConstrai
switchDefault();
}
rotationIK += MathUtils.atan2Deg(ty, tx);
if (bone.scaleX < 0) rotationIK += 180;
if (bone.scaleX < 0)
rotationIK += 180;
if (rotationIK > 180)
rotationIK -= 360;
else if (rotationIK < -180) //
@ -139,13 +144,14 @@ class IkConstraint extends Constraint<IkConstraint, IkConstraintData, IkConstrai
tx = targetX - bone.worldX;
ty = targetY - bone.worldY;
}
var b = bone.bone.data.length * bone.scaleX;
var b = bone.bone.data.length * bone.scaleX;
if (b > 0.0001) {
var dd = tx * tx + ty * ty;
var dd = tx * tx + ty * ty;
if ((compress && dd < b * b) || (stretch && dd > b * b)) {
var s = (Math.sqrt(dd) / b - 1) * mix + 1;
bone.scaleX *= s;
if (uniform) bone.scaleY *= s;
if (uniform)
bone.scaleY *= s;
}
}
}
@ -153,12 +159,14 @@ class IkConstraint extends Constraint<IkConstraint, IkConstraintData, IkConstrai
/** Applies 2 bone IK. The target is specified in the world coordinate system.
* @param child A direct descendant of the parent bone. */
static public function apply2(skeleton:Skeleton, parent:BonePose, child:BonePose, targetX:Float, targetY:Float, bendDir:Int,
stretch:Bool, uniform:Bool, softness:Float, mix:Float):Void {
if (parent == null) throw new SpineException("parent cannot be null.");
if (child == null) throw new SpineException("child cannot be null.");
if (parent.inherit != Inherit.normal || child.inherit != Inherit.normal) return;
static public function apply2(skeleton:Skeleton, parent:BonePose, child:BonePose, targetX:Float, targetY:Float, bendDir:Int, stretch:Bool, uniform:Bool,
softness:Float, mix:Float):Void {
if (parent == null)
throw new SpineException("parent cannot be null.");
if (child == null)
throw new SpineException("child cannot be null.");
if (parent.inherit != Inherit.normal || child.inherit != Inherit.normal)
return;
parent.modifyLocal(skeleton);
child.modifyLocal(skeleton);
var px = parent.x, py = parent.y, psx = parent.scaleX, psy = parent.scaleY, csx = child.scaleX;
@ -232,8 +240,9 @@ class IkConstraint extends Constraint<IkConstraint, IkConstraintData, IkConstrai
cos = 1;
if (stretch) {
a = (Math.sqrt(dd) / (l1 + l2) - 1) * mix + 1;
parent.scaleX *= a;
if (uniform) parent.scaleY *= a;
parent.scaleX *= a;
if (uniform)
parent.scaleY *= a;
}
}
a2 = Math.acos(cos) * bendDir;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
@ -33,7 +33,6 @@ package spine;
*
* @see https://esotericsoftware.com/spine-ik-constraints IK constraints in the Spine User Guide */
class IkConstraintData extends ConstraintData<IkConstraint, IkConstraintPose> {
/** The bones that are constrained by this IK constraint. */
public final bones:Array<BoneData> = new Array<BoneData>();
@ -44,17 +43,17 @@ class IkConstraintData extends ConstraintData<IkConstraint, IkConstraintPose> {
* on both the X and Y axes. */
public var uniform = false;
public function new(name:String) {
super(name, new IkConstraintPose());
}
public function create (skeleton:Skeleton):IkConstraint {
public function create(skeleton:Skeleton):IkConstraint {
return new IkConstraint(this, skeleton);
}
public function set_target (target:BoneData) {
if (target == null) throw new SpineException("target cannot be null.");
public function set_target(target:BoneData) {
if (target == null)
throw new SpineException("target cannot be null.");
this.target = target;
return target;
}

View File

@ -25,13 +25,12 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
/** Stores the current pose for an IK constraint. */
class IkConstraintPose implements Pose<IkConstraintPose> {
/** For two bone IK, controls the bend direction of the IK bones, either 1 or -1. */
public var bendDirection = 0;
@ -39,29 +38,27 @@ class IkConstraintPose implements Pose<IkConstraintPose> {
public var compress:Bool = false;
/** When true and the target is out of range, the parent bone is scaled to reach it.
*
* For two bone IK: 1) the child bone's local Y translation is set to 0, 2) stretch is not applied if softness is
* > 0, and 3) if the parent bone has local nonuniform scale, stretch is not applied. */
*
* For two bone IK: 1) the child bone's local Y translation is set to 0, 2) stretch is not applied if softness is
* > 0, and 3) if the parent bone has local nonuniform scale, stretch is not applied. */
public var stretch:Bool = false;
/** A percentage (0-1) that controls the mix between the constrained and unconstrained rotation.
*
* For two bone IK: if the parent bone has local nonuniform scale, the child bone's local Y translation is set to 0. */
*
* For two bone IK: if the parent bone has local nonuniform scale, the child bone's local Y translation is set to 0. */
public var mix = 0.;
/** For two bone IK, the target bone's distance from the maximum reach of the bones where rotation begins to slow. The bones
* will not straighten completely until the target is this far out of range. */
* will not straighten completely until the target is this far out of range. */
public var softness = 0.;
public function new () {
}
public function new() {}
public function set (pose:IkConstraintPose) {
public function set(pose:IkConstraintPose) {
mix = pose.mix;
softness = pose.softness;
bendDirection = pose.bendDirection;
compress = pose.compress;
stretch = pose.stretch;
}
}
}

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
@ -63,7 +63,7 @@ class MathUtils {
* @param x The x-coordinate.
* @return The arc tangent in degrees.
*/
static public function atan2Deg (y:Float, x:Float):Float {
static public function atan2Deg(y:Float, x:Float):Float {
return Math.atan2(y, x) * MathUtils.radDeg;
}

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
@ -56,9 +56,10 @@ class PathConstraint extends Constraint<PathConstraint, PathConstraintData, Path
private final lengths = new Array<Float>();
private final segments = new Array<Float>();
public function new (data:PathConstraintData, skeleton:Skeleton) {
public function new(data:PathConstraintData, skeleton:Skeleton) {
super(data, new PathConstraintPose(), new PathConstraintPose());
if (skeleton == null) throw new SpineException("skeleton cannot be null.");
if (skeleton == null)
throw new SpineException("skeleton cannot be null.");
bones = new Array<BonePose>();
for (boneData in data.bones)
@ -76,18 +77,23 @@ class PathConstraint extends Constraint<PathConstraint, PathConstraintData, Path
/** Applies the constraint to the constrained bones. */
public function update(skeleton:Skeleton, physics:Physics):Void {
var attachment = slot.applied.attachment;
if (!Std.isOfType(attachment, PathAttachment)) return;
if (!Std.isOfType(attachment, PathAttachment))
return;
var pathAttachment = cast(attachment, PathAttachment);
var p = applied;
var mixRotate = p.mixRotate, mixX = p.mixX, mixY = p.mixY;
if (mixRotate == 0 && mixX == 0 && mixY == 0) return;
if (mixRotate == 0 && mixX == 0 && mixY == 0)
return;
var data = data;
var fTangents = data.rotateMode == RotateMode.tangent, fScale = data.rotateMode == RotateMode.chainScale;
var boneCount = bones.length, spacesCount = fTangents ? boneCount : boneCount + 1;
var fTangents = data.rotateMode == RotateMode.tangent,
fScale = data.rotateMode == RotateMode.chainScale;
var boneCount = bones.length,
spacesCount = fTangents ? boneCount : boneCount + 1;
ArrayUtils.resize(spaces, spacesCount, 0);
if (fScale) ArrayUtils.resize(lengths, boneCount, 0);
if (fScale)
ArrayUtils.resize(lengths, boneCount, 0);
var spacing = p.spacing;
var bones = bones;
@ -102,7 +108,8 @@ class PathConstraint extends Constraint<PathConstraint, PathConstraintData, Path
lengths[i] = Math.sqrt(x * x + y * y);
}
}
for (i in 1...spacesCount) spaces[i] = spacing;
for (i in 1...spacesCount)
spaces[i] = spacing;
case SpacingMode.proportional:
var sum = 0.;
var i = 0, n = spacesCount - 1;
@ -110,12 +117,14 @@ class PathConstraint extends Constraint<PathConstraint, PathConstraintData, Path
var bone = bones[i];
var setupLength:Float = bone.bone.data.length;
if (setupLength < PathConstraint.epsilon) {
if (fScale) lengths[i] = 0;
if (fScale)
lengths[i] = 0;
spaces[++i] = spacing;
} else {
var x = setupLength * bone.a, y = setupLength * bone.c;
var length = Math.sqrt(x * x + y * y);
if (fScale) lengths[i] = length;
if (fScale)
lengths[i] = length;
spaces[++i] = length;
sum += length;
}
@ -132,19 +141,23 @@ class PathConstraint extends Constraint<PathConstraint, PathConstraintData, Path
var bone = bones[i];
var setupLength = bone.bone.data.length;
if (setupLength < PathConstraint.epsilon) {
if (fScale) lengths[i] = 0;
if (fScale)
lengths[i] = 0;
spaces[++i] = spacing;
} else {
var x = setupLength * bone.a, y = setupLength * bone.c;
var length = Math.sqrt(x * x + y * y);
if (fScale) lengths[i] = length;
if (fScale)
lengths[i] = length;
spaces[++i] = (lengthSpacing ? Math.max(0, setupLength + spacing) : spacing) * length / setupLength;
}
}
}
var positions = computeWorldPositions(skeleton, pathAttachment, spacesCount, fTangents);
var boneX = positions[0], boneY = positions[1], offsetRotation = data.offsetRotation;
var boneX = positions[0],
boneY = positions[1],
offsetRotation = data.offsetRotation;
var tip = false;
if (offsetRotation == 0)
tip = data.rotateMode == RotateMode.chain;
@ -209,20 +222,26 @@ class PathConstraint extends Constraint<PathConstraint, PathConstraintData, Path
ArrayUtils.resize(positions, spacesCount * 3 + 2, 0);
var out:Array<Float> = positions, world = new Array<Float>();
var closed = path.closed;
var verticesLength = path.worldVerticesLength, curveCount = Std.int(verticesLength / 6), prevCurve = NONE;
var verticesLength = path.worldVerticesLength,
curveCount = Std.int(verticesLength / 6),
prevCurve = NONE;
if (!path.constantSpeed) {
var lengths = path.lengths;
curveCount -= closed ? 1 : 2;
var pathLength = lengths[curveCount];
if (data.positionMode == PositionMode.percent) position *= pathLength;
if (data.positionMode == PositionMode.percent)
position *= pathLength;
var multiplier: Float;
var multiplier:Float;
switch (data.spacingMode) {
case SpacingMode.percent: multiplier = pathLength;
case SpacingMode.proportional: multiplier = pathLength / spacesCount;
default: multiplier = 1;
case SpacingMode.percent:
multiplier = pathLength;
case SpacingMode.proportional:
multiplier = pathLength / spacesCount;
default:
multiplier = 1;
}
ArrayUtils.resize(world, 8, 0);
@ -234,7 +253,8 @@ class PathConstraint extends Constraint<PathConstraint, PathConstraintData, Path
if (closed) {
p %= pathLength;
if (p < 0) p += pathLength;
if (p < 0)
p += pathLength;
curve = 0;
} else if (p < 0) {
if (prevCurve != BEFORE) {
@ -276,8 +296,7 @@ class PathConstraint extends Constraint<PathConstraint, PathConstraintData, Path
path.computeWorldVertices(skeleton, slot, curve * 6 + 2, 8, world, 0, 2);
}
}
addCurvePosition(p, world[0], world[1], world[2], world[3], world[4], world[5], world[6], world[7], out, o,
tangents || (i > 0 && space == 0));
addCurvePosition(p, world[0], world[1], world[2], world[3], world[4], world[5], world[6], world[7], out, o, tangents || (i > 0 && space == 0));
i++;
o += 3;
}
@ -341,13 +360,17 @@ class PathConstraint extends Constraint<PathConstraint, PathConstraintData, Path
w += 6;
}
if (data.positionMode == PositionMode.percent) position *= pathLength;
if (data.positionMode == PositionMode.percent)
position *= pathLength;
var multiplier:Float;
switch (data.spacingMode) {
case SpacingMode.percent: multiplier = pathLength;
case SpacingMode.proportional: multiplier = pathLength / spacesCount;
default: multiplier = 1;
case SpacingMode.percent:
multiplier = pathLength;
case SpacingMode.proportional:
multiplier = pathLength / spacesCount;
default:
multiplier = 1;
}
var segments = segments;
@ -360,7 +383,8 @@ class PathConstraint extends Constraint<PathConstraint, PathConstraintData, Path
if (closed) {
p %= pathLength;
if (p < 0) p += pathLength;
if (p < 0)
p += pathLength;
curve = 0;
segment = 0;
} else if (p < 0) {
@ -509,10 +533,11 @@ class PathConstraint extends Constraint<PathConstraint, PathConstraintData, Path
}
}
public function sort (skeleton:Skeleton) {
public function sort(skeleton:Skeleton) {
var slotIndex = slot.data.index;
var slotBone = slot.bone;
if (skeleton.skin != null) sortPathSlot(skeleton, skeleton.skin, slotIndex, slotBone);
if (skeleton.skin != null)
sortPathSlot(skeleton, skeleton.skin, slotIndex, slotBone);
if (skeleton.data.defaultSkin != null && skeleton.data.defaultSkin != skeleton.skin)
sortPathSlot(skeleton, skeleton.data.defaultSkin, slotIndex, slotBone);
sortPath(skeleton, slot.pose.attachment, slotBone);
@ -529,15 +554,17 @@ class PathConstraint extends Constraint<PathConstraint, PathConstraintData, Path
bones[i].bone.sorted = true;
}
public function sortPathSlot (skeleton:Skeleton, skin:Skin, slotIndex:Int, slotBone:Bone) {
public function sortPathSlot(skeleton:Skeleton, skin:Skin, slotIndex:Int, slotBone:Bone) {
var entries = skin.getAttachments();
for (entry in entries) {
if (entry.slotIndex == slotIndex) sortPath(skeleton, entry.attachment, slotBone);
if (entry.slotIndex == slotIndex)
sortPath(skeleton, entry.attachment, slotBone);
}
}
private function sortPath (skeleton:Skeleton, attachment:Attachment, slotBone:Bone) {
if (!(Std.isOfType(attachment, PathAttachment))) return;
private function sortPath(skeleton:Skeleton, attachment:Attachment, slotBone:Bone) {
if (!(Std.isOfType(attachment, PathAttachment)))
return;
var pathBones = cast(attachment, PathAttachment).bones;
if (pathBones == null)
skeleton.sortBone(slotBone);
@ -553,7 +580,7 @@ class PathConstraint extends Constraint<PathConstraint, PathConstraintData, Path
}
}
override public function isSourceActive (): Bool {
override public function isSourceActive():Bool {
return slot.bone.active;
}
}

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
@ -51,34 +51,38 @@ class PathConstraintData extends ConstraintData<PathConstraint, PathConstraintPo
/** An offset added to the constrained bone rotation. */
public var offsetRotation:Float = 0;
public function new (name:String) {
public function new(name:String) {
super(name, new PathConstraintPose());
}
public function create (skeleton:Skeleton) {
public function create(skeleton:Skeleton) {
return new PathConstraint(this, skeleton);
}
public function set_slot (slot:SlotData):SlotData {
if (slot == null) throw new SpineException("slot cannot be null.");
public function set_slot(slot:SlotData):SlotData {
if (slot == null)
throw new SpineException("slot cannot be null.");
this.slot = slot;
return slot;
}
public function set_positionMode (positionMode:PositionMode):PositionMode {
if (positionMode == null) throw new SpineException("positionMode cannot be null.");
public function set_positionMode(positionMode:PositionMode):PositionMode {
if (positionMode == null)
throw new SpineException("positionMode cannot be null.");
this.positionMode = positionMode;
return positionMode;
}
public function set_spacingMode (spacingMode:SpacingMode):SpacingMode {
if (spacingMode == null) throw new SpineException("spacingMode cannot be null.");
public function set_spacingMode(spacingMode:SpacingMode):SpacingMode {
if (spacingMode == null)
throw new SpineException("spacingMode cannot be null.");
this.spacingMode = spacingMode;
return spacingMode;
}
public function set_rotateMode (rotateMode:RotateMode):RotateMode {
if (rotateMode == null) throw new SpineException("rotateMode cannot be null.");
public function set_rotateMode(rotateMode:RotateMode):RotateMode {
if (rotateMode == null)
throw new SpineException("rotateMode cannot be null.");
this.rotateMode = rotateMode;
return rotateMode;
}

View File

@ -25,12 +25,11 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
class PathConstraintPose implements Pose<PathConstraintPose> {
/** The position along the path. */
public var position = 0.;
@ -46,8 +45,7 @@ class PathConstraintPose implements Pose<PathConstraintPose> {
/** A percentage (0-1) that controls the mix between the constrained and unconstrained translation Y. */
public var mixY = 0.;
public function new () {
}
public function new() {}
public function set(pose:PathConstraintPose) {
position = pose.position;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
@ -33,10 +33,13 @@ package spine;
class Physics {
/** Physics are not updated or applied. */
public static var none(default, never):Physics = new Physics("none");
/** Physics are reset to the current pose. */
public static var reset(default, never):Physics = new Physics("reset");
/** Physics are updated and the pose from physics is applied. */
public static var update(default, never):Physics = new Physics("update");
/** Physics are not updated but the pose from physics is applied. */
public static var pose(default, never):Physics = new Physics("pose");

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
@ -35,7 +35,6 @@ package spine;
* @see https://esotericsoftware.com/spine-physics-constraints Physics constraints in the Spine User Guide
*/
class PhysicsConstraint extends Constraint<PhysicsConstraint, PhysicsConstraintData, PhysicsConstraintPose> {
/** The bone constrained by this physics constraint. */
public var bone:BonePose = null;
@ -62,9 +61,10 @@ class PhysicsConstraint extends Constraint<PhysicsConstraint, PhysicsConstraintD
public var remaining = 0.;
public var lastTime = 0.;
public function new(data: PhysicsConstraintData, skeleton: Skeleton) {
public function new(data:PhysicsConstraintData, skeleton:Skeleton) {
super(data, new PhysicsConstraintPose(), new PhysicsConstraintPose());
if (skeleton == null) throw new SpineException("skeleton cannot be null.");
if (skeleton == null)
throw new SpineException("skeleton cannot be null.");
bone = skeleton.bones[data.bone.index].constrained;
}
@ -75,7 +75,7 @@ class PhysicsConstraint extends Constraint<PhysicsConstraint, PhysicsConstraintD
return copy;
}
public function reset (skeleton:Skeleton) {
public function reset(skeleton:Skeleton) {
remaining = 0;
lastTime = skeleton.time;
_reset = true;
@ -95,7 +95,7 @@ class PhysicsConstraint extends Constraint<PhysicsConstraint, PhysicsConstraintD
/** Translates the physics constraint so next update(Physics) forces are applied as if the bone moved an additional
* amount in world space. */
public function translate (x:Float, y:Float):Void {
public function translate(x:Float, y:Float):Void {
ux -= x;
uy -= y;
cx -= x;
@ -104,8 +104,10 @@ class PhysicsConstraint extends Constraint<PhysicsConstraint, PhysicsConstraintD
/** Rotates the physics constraint so next update(Physics) forces are applied as if the bone rotated around the
* specified point in world space. */
public function rotate (x:Float, y:Float, degrees:Float):Void {
var r = degrees * MathUtils.degRad, cos = Math.cos(r), sin = Math.sin(r);
public function rotate(x:Float, y:Float, degrees:Float):Void {
var r = degrees * MathUtils.degRad,
cos = Math.cos(r),
sin = Math.sin(r);
var dx = cx - x, dy = cy - y;
translate(dx * cos - dy * sin - dx, dx * sin + dy * cos - dy);
}
@ -114,16 +116,21 @@ class PhysicsConstraint extends Constraint<PhysicsConstraint, PhysicsConstraintD
public function update(skeleton:Skeleton, physics:Physics):Void {
var p = applied;
var mix = p.mix;
if (mix == 0) return;
if (mix == 0)
return;
var x = data.x > 0, y = data.y > 0, rotateOrShearX = data.rotate > 0 || data.shearX > 0, scaleX = data.scaleX > 0;
var x = data.x > 0,
y = data.y > 0,
rotateOrShearX = data.rotate > 0 || data.shearX > 0,
scaleX = data.scaleX > 0;
var l = bone.bone.data.length, t = data.step, z = 0.;
switch (physics) {
case Physics.none:
return;
case Physics.reset, Physics.update:
if (physics == Physics.reset) reset(skeleton);
if (physics == Physics.reset)
reset(skeleton);
var delta = Math.max(skeleton.time - lastTime, 0), aa = remaining;
remaining += delta;
@ -135,8 +142,8 @@ class PhysicsConstraint extends Constraint<PhysicsConstraint, PhysicsConstraintD
ux = bx;
uy = by;
} else {
var a = remaining, i = p.inertia, f = skeleton.data.referenceScale, d = -1., m = 0., e = 0., ax = 0., ay = 0.,
qx = data.limit * delta, qy = qx * Math.abs(skeleton.scaleY);
var a = remaining, i = p.inertia, f = skeleton.data.referenceScale, d = -1., m = 0., e = 0., ax = 0., ay = 0., qx = data.limit * delta,
qy = qx * Math.abs(skeleton.scaleY);
qx *= Math.abs(skeleton.scaleX);
if (x || y) {
if (x) {
@ -174,8 +181,10 @@ class PhysicsConstraint extends Constraint<PhysicsConstraint, PhysicsConstraintD
yLag = yOffset - ys;
}
z = Math.max(0, 1 - a / t);
if (x) bone.worldX += (xOffset - xLag * z) * mix * data.x;
if (y) bone.worldY += (yOffset - yLag * z) * mix * data.y;
if (x)
bone.worldX += (xOffset - xLag * z) * mix * data.x;
if (y)
bone.worldY += (yOffset - yLag * z) * mix * data.y;
}
if (rotateOrShearX || scaleX) {
var ca = Math.atan2(bone.c, bone.a), c = 0., s = 0., mr = 0., dx = cx - bone.worldX, dy = cy - bone.worldY;
@ -198,20 +207,23 @@ class PhysicsConstraint extends Constraint<PhysicsConstraint, PhysicsConstraintD
s = Math.sin(r);
if (scaleX) {
r = l * bone.worldScaleX;
if (r > 0) scaleOffset += (dx * c + dy * s) * i / r;
if (r > 0)
scaleOffset += (dx * c + dy * s) * i / r;
}
} else {
c = Math.cos(ca);
s = Math.sin(ca);
var r = l * bone.worldScaleX - scaleLag * Math.max(0, 1 - aa / t);
if (r > 0) scaleOffset += (dx * c + dy * s) * i / r;
if (r > 0)
scaleOffset += (dx * c + dy * s) * i / r;
}
if (a >= t) {
if (d == -1) {
d = Math.pow(p.damping, 60 * t);
m = t * p.massInverse;
e = p.strength;
var w = f * p.wind, g = f * p.gravity * Bone.yDir;
var w = f * p.wind,
g = f * p.gravity * Bone.yDir;
ax = (w * skeleton.windX + g * skeleton.gravityX) * skeleton.scaleX;
ay = (w * skeleton.windY + g * skeleton.gravityY) * skeleton.scaleY;
}
@ -227,7 +239,8 @@ class PhysicsConstraint extends Constraint<PhysicsConstraint, PhysicsConstraintD
rotateVelocity -= ((ax * s + ay * c) * h + rotateOffset * e) * m;
rotateOffset += rotateVelocity * t;
rotateVelocity *= d;
if (a < t) break;
if (a < t)
break;
var r:Float = rotateOffset * mr + ca;
c = Math.cos(r);
s = Math.sin(r);
@ -245,8 +258,10 @@ class PhysicsConstraint extends Constraint<PhysicsConstraint, PhysicsConstraintD
cy = bone.worldY;
case Physics.pose:
z = Math.max(0, 1 - remaining / t);
if (x) bone.worldX += (xOffset - xLag * z) * mix * data.x;
if (y) bone.worldY += (yOffset - yLag * z) * mix * data.y;
if (x)
bone.worldX += (xOffset - xLag * z) * mix * data.x;
if (y)
bone.worldY += (yOffset - yLag * z) * mix * data.y;
}
if (rotateOrShearX) {
@ -291,7 +306,7 @@ class PhysicsConstraint extends Constraint<PhysicsConstraint, PhysicsConstraintD
bone.modifyWorld(skeleton._update);
}
public function sort (skeleton: Skeleton) {
public function sort(skeleton:Skeleton) {
var bone = bone.bone;
skeleton.sortBone(bone);
skeleton._updateCache.push(this);
@ -299,7 +314,7 @@ class PhysicsConstraint extends Constraint<PhysicsConstraint, PhysicsConstraintD
skeleton.constrained(bone);
}
override public function isSourceActive () {
override public function isSourceActive() {
return bone.bone.active;
}
}

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
@ -33,7 +33,6 @@ package spine;
*
* @see https://esotericsoftware.com/spine-physics-constraints Physics constraints in the Spine User Guide */
class PhysicsConstraintData extends ConstraintData<PhysicsConstraint, PhysicsConstraintPose> {
/** The bone constrained by this physics constraint. */
public var bone:BoneData;
@ -44,8 +43,10 @@ class PhysicsConstraintData extends ConstraintData<PhysicsConstraint, PhysicsCon
public var shearX = 0.;
public var limit = 0.;
public var step = 0.;
/** A percentage (0-1) that controls the mix between the constrained and unconstrained poses. */
public var mix = 0.;
public var inertiaGlobal = false;
public var strengthGlobal = false;
public var dampingGlobal = false;
@ -58,8 +59,7 @@ class PhysicsConstraintData extends ConstraintData<PhysicsConstraint, PhysicsCon
super(name, new PhysicsConstraintPose());
}
public function create (skeleton:Skeleton) {
public function create(skeleton:Skeleton) {
return new PhysicsConstraint(this, skeleton);
}
}

View File

@ -25,26 +25,25 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
/** Stores a pose for a physics constraint. */
class PhysicsConstraintPose implements Pose<PhysicsConstraintPose> {
public var inertia = 0.;
public var strength = 0.;
public var damping = 0.;
public var massInverse = 0.;
public var wind = 0.;
public var gravity = 0.;
/** A percentage (0-1) that controls the mix between the constrained and unconstrained poses. */
public var mix = 0.;
public function new () {
}
public function new() {}
public function set (pose:PhysicsConstraintPose) {
public function set(pose:PhysicsConstraintPose) {
inertia = pose.inertia;
strength = pose.strength;
damping = pose.damping;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;

View File

@ -25,10 +25,10 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
interface Pose<P> {
public function set (pose:P):Void;
}
public function set(pose:P):Void;
}

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
@ -33,15 +33,16 @@ abstract class Posed< //
D:PosedData<P>, //
P:Pose<Any>, //
A:P> {
/** The constraint's setup pose data. */
public final data:D;
public final pose:A;
public final constrained:A;
public var applied:A;
public function new (data:D, pose:A, constrained:A) {
if (data == null) throw new SpineException("data cannot be null.");
public function new(data:D, pose:A, constrained:A) {
if (data == null)
throw new SpineException("data cannot be null.");
this.data = data;
this.pose = pose;
this.constrained = constrained;
@ -49,35 +50,35 @@ abstract class Posed< //
}
/** The constraint's setup pose data. */
public function getData ():D {
public function getData():D {
return data;
}
public function getPose ():P {
public function getPose():P {
return pose;
}
public function getAppliedPose ():A {
public function getAppliedPose():A {
return applied;
}
public function setupPose ():Void {
public function setupPose():Void {
pose.set(data.setup);
}
public function usePose ():Void { // Port: usePose - reference runtime: pose()
public function usePose():Void { // Port: usePose - reference runtime: pose()
applied = pose;
}
public function useConstrained ():Void { // Port: useConstrained - reference runtime: constrained()
public function useConstrained():Void { // Port: useConstrained - reference runtime: constrained()
applied = constrained;
}
public function resetConstrained ():Void { // Port: resetConstrained - reference runtime: reset()
public function resetConstrained():Void { // Port: resetConstrained - reference runtime: reset()
constrained.set(pose);
}
public function toString ():String {
public function toString():String {
return data.name;
}
}

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
@ -33,11 +33,10 @@ abstract class PosedActive< //
D:PosedData<P>, //
P:Pose<Any>, //
A:P> //
extends Posed<D, P, A> {
extends Posed<D, P, A> {
public var active:Bool;
public function new (data:D, pose:A, constrained:A) {
public function new(data:D, pose:A, constrained:A) {
super(data, pose, constrained);
setupPose();
}
@ -49,7 +48,7 @@ abstract class PosedActive< //
* @see Skin.getConstraints()
* @see PosedData.getSkinRequired()
* @see Skeleton.updateCache() */
public function isActive ():Bool {
public function isActive():Bool {
return active;
}
}

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
@ -37,18 +37,19 @@ abstract class PosedData<P:Pose<Any>> {
public final setup:P;
/** When true, `Skeleton.updateWorldTransform(Physics)` only updates this constraint if the `Skeleton.getSkin()`
* contains this constraint.
*
* See `Skin.getConstraints()`. */
* contains this constraint.
*
* See `Skin.getConstraints()`. */
public var skinRequired:Bool;
public function new (name:String, setup:P) {
if (name == null) throw new SpineException("name cannot be null.");
public function new(name:String, setup:P) {
if (name == null)
throw new SpineException("name cannot be null.");
this.name = name;
this.setup = setup;
}
public function toString ():String {
public function toString():String {
return name;
}
}

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
@ -35,6 +35,7 @@ package spine;
class RotateMode {
public static var tangent(default, never):RotateMode = new RotateMode("tangent");
public static var chain(default, never):RotateMode = new RotateMode("chain");
/** When chain scale, constrained bones should all have the same parent. That way when the path constraint scales a bone, it
* doesn't affect other constrained bones. */
public static var chainScale(default, never):RotateMode = new RotateMode("chainScale");

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
@ -35,6 +35,7 @@ class Sequence {
/** Returns a unique ID for this attachment. */
public var id = _nextID++;
public var regions:Array<TextureRegion>;
public var start = 0;
public var digits = 0;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
@ -65,7 +65,7 @@ class Skeleton {
/** The list of bones and constraints, sorted in the order they should be updated, as computed by Skeleton.updateCache(). */
public final _updateCache = new Array<Dynamic>();
private final resetCache = new Array<Posed<Dynamic, Dynamic, Dynamic>> ();
private final resetCache = new Array<Posed<Dynamic, Dynamic, Dynamic>>();
/** The skeleton's current skin. */
public var skin(default, set):Skin = null;
@ -84,14 +84,15 @@ class Skeleton {
public var y:Float = 0;
/** Scales the entire skeleton on the X axis.
*
* Bones that do not inherit scale are still affected by this property. */
*
* Bones that do not inherit scale are still affected by this property. */
public var scaleX:Float = 1;
/** Scales the entire skeleton on the Y axis.
*
* Bones that do not inherit scale are still affected by this property. */
*
* Bones that do not inherit scale are still affected by this property. */
public var scaleY(get, default):Float = 1;
function get_scaleY() {
return scaleY * Bone.yDir;
}
@ -110,7 +111,8 @@ class Skeleton {
/** Creates a new skeleton with the specified skeleton data. */
public function new(data:SkeletonData) {
if (data == null) throw new SpineException("data cannot be null.");
if (data == null)
throw new SpineException("data cannot be null.");
this.data = data;
bones = new Array<Bone>();
@ -138,7 +140,8 @@ class Skeleton {
constraints = new Array<Constraint<Dynamic, Dynamic, Dynamic>>();
for (constraintData in data.constraints) {
var constraint = constraintData.create(this);
if (Std.isOfType(constraint, PhysicsConstraint)) physics.push(cast(constraint, PhysicsConstraint));
if (Std.isOfType(constraint, PhysicsConstraint))
physics.push(cast(constraint, PhysicsConstraint));
constraints.push(constraint);
}
@ -180,7 +183,8 @@ class Skeleton {
var constraint:Constraint<Dynamic, Dynamic, Dynamic> = c;
constraint.active = constraint.isSourceActive()
&& (!constraint.data.skinRequired || (skin != null && contains(skin.constraints, constraint.data)));
if (constraint.active) constraint.sort(this);
if (constraint.active)
constraint.sort(this);
}
for (bone in bones)
@ -201,7 +205,7 @@ class Skeleton {
return list.indexOf(element) != -1;
}
public function constrained (object:Posed<Dynamic, Dynamic, Dynamic>) {
public function constrained(object:Posed<Dynamic, Dynamic, Dynamic>) {
if (object.pose == object.applied) {
object.useConstrained();
resetCache.push(object);
@ -209,9 +213,11 @@ class Skeleton {
}
public function sortBone(bone:Bone):Void {
if (bone.sorted || !bone.active) return;
if (bone.sorted || !bone.active)
return;
var parent = bone.parent;
if (parent != null) sortBone(parent);
if (parent != null)
sortBone(parent);
bone.sorted = true;
_updateCache.push(bone);
}
@ -219,7 +225,8 @@ class Skeleton {
public function sortReset(bones:Array<Bone>):Void {
for (bone in bones) {
if (bone.active) {
if (bone.sorted) sortReset(bone.children);
if (bone.sorted)
sortReset(bone.children);
bone.sorted = false;
}
}
@ -247,8 +254,10 @@ class Skeleton {
/** Sets the bones and constraints to their setup pose values. */
public function setupPoseBones():Void {
for (bone in this.bones) bone.setupPose();
for (constraint in this.constraints) constraint.setupPose();
for (bone in this.bones)
bone.setupPose();
for (constraint in this.constraints)
constraint.setupPose();
}
/** Sets the slots and draw order to their setup pose values. */
@ -270,18 +279,22 @@ class Skeleton {
/** Finds a bone by comparing each bone's name. It is more efficient to cache the results of this method than to call it
* repeatedly. */
public function findBone(boneName:String):Bone {
if (boneName == null) throw new SpineException("boneName cannot be null.");
if (boneName == null)
throw new SpineException("boneName cannot be null.");
for (bone in bones)
if (bone.data.name == boneName) return bone;
if (bone.data.name == boneName)
return bone;
return null;
}
/** @return -1 if the bone was not found. */
public function findBoneIndex(boneName:String):Int {
if (boneName == null) throw new SpineException("boneName cannot be null.");
if (boneName == null)
throw new SpineException("boneName cannot be null.");
var i:Int = 0;
for (bone in bones) {
if (bone.data.name == boneName) return i;
if (bone.data.name == boneName)
return i;
i++;
}
return -1;
@ -290,9 +303,11 @@ class Skeleton {
/** Finds a slot by comparing each slot's name. It is more efficient to cache the results of this method than to call it
* repeatedly. */
public function findSlot(slotName:String):Slot {
if (slotName == null) throw new SpineException("slotName cannot be null.");
if (slotName == null)
throw new SpineException("slotName cannot be null.");
for (slot in slots)
if (slot.data.name == slotName) return slot;
if (slot.data.name == slotName)
return slot;
return null;
}
@ -337,7 +352,8 @@ class Skeleton {
var name:String = slot.data.attachmentName;
if (name != null) {
var attachment:Attachment = newSkin.getAttachment(i, name);
if (attachment != null) slot.pose.attachment = attachment;
if (attachment != null)
slot.pose.attachment = attachment;
}
i++;
}
@ -399,10 +415,13 @@ class Skeleton {
}
public function findConstraint<T:Constraint<Dynamic, Dynamic, Dynamic>>(constraintName:String, type:Class<T>):Null<T> {
if (constraintName == null) throw new SpineException("constraintName cannot be null.");
if (type == null) throw new SpineException("type cannot be null.");
if (constraintName == null)
throw new SpineException("constraintName cannot be null.");
if (type == null)
throw new SpineException("type cannot be null.");
for (constraint in constraints)
if (Std.isOfType(constraint, type) && constraint.data.name == constraintName) return Std.downcast(constraint, type);
if (Std.isOfType(constraint, type) && constraint.data.name == constraintName)
return Std.downcast(constraint, type);
return null;
}
@ -411,7 +430,7 @@ class Skeleton {
/** Returns the axis aligned bounding box (AABB) of the region and mesh attachments for the current pose. Optionally applies
* clipping. */
public function getBounds(clipper: SkeletonClipping = null):Rectangle {
public function getBounds(clipper:SkeletonClipping = null):Rectangle {
var minX = Math.POSITIVE_INFINITY;
var minY = Math.POSITIVE_INFINITY;
var maxX = Math.NEGATIVE_INFINITY;
@ -456,10 +475,12 @@ class Skeleton {
ii += 2;
}
}
if (clipper != null) clipper.clipEnd(slot);
if (clipper != null)
clipper.clipEnd(slot);
}
}
if (clipper != null) clipper.clipEnd();
if (clipper != null)
clipper.clipEnd();
_bounds.x = minX;
_bounds.y = minY;
_bounds.width = maxX - minX;
@ -468,18 +489,18 @@ class Skeleton {
}
/** Increments the skeleton's Skeleton.time. */
public function update (delta:Float):Void {
public function update(delta:Float):Void {
time += delta;
}
/** Calls spine.PhysicsConstraint.translate() for each physics constraint. */
public function physicsTranslate (x:Float, y:Float):Void {
public function physicsTranslate(x:Float, y:Float):Void {
for (physicsConstraint in physics)
physicsConstraint.translate(x, y);
}
/** Calls spine.PhysicsConstraint.rotate() for each physics constraint. */
public function physicsRotate (x:Float, y:Float, degrees:Float):Void {
public function physicsRotate(x:Float, y:Float, degrees:Float):Void {
for (physicsConstraint in physics)
physicsConstraint.rotate(x, y, degrees);
}

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
@ -219,11 +219,13 @@ class SkeletonBinary {
data.setup.color.setFromRgba8888(input.readInt32());
var darkColor = input.readInt32();
if (darkColor != -1) data.setup.darkColor = new Color(0, 0, 0).setFromRgb888(darkColor);
if (darkColor != -1)
data.setup.darkColor = new Color(0, 0, 0).setFromRgb888(darkColor);
data.attachmentName = input.readStringRef();
data.blendMode = BlendMode.values[input.readInt(true)];
if (nonessential) data.visible = input.readBoolean();
if (nonessential)
data.visible = input.readBoolean();
slots.push(data);
}
@ -248,8 +250,10 @@ class SkeletonBinary {
setup.bendDirection = (flags & 4) != 0 ? 1 : -1;
setup.compress = (flags & 8) != 0;
setup.stretch = (flags & 16) != 0;
if ((flags & 32) != 0) setup.mix = (flags & 64) != 0 ? input.readFloat() : 1;
if ((flags & 128) != 0) setup.softness = input.readFloat() * scale;
if ((flags & 32) != 0)
setup.mix = (flags & 64) != 0 ? input.readFloat() : 1;
if ((flags & 128) != 0)
setup.softness = input.readFloat() * scale;
constraints[i] = data;
case CONSTRAINT_TRANSFORM:
var data = new TransformConstraintData(name);
@ -309,20 +313,32 @@ class SkeletonBinary {
froms[ii] = from;
}
flags = input.readByte();
if ((flags & 1) != 0) data.offsets[TransformConstraintData.ROTATION] = input.readFloat();
if ((flags & 2) != 0) data.offsets[TransformConstraintData.X] = input.readFloat() * scale;
if ((flags & 4) != 0) data.offsets[TransformConstraintData.Y] = input.readFloat() * scale;
if ((flags & 8) != 0) data.offsets[TransformConstraintData.SCALEX] = input.readFloat();
if ((flags & 16) != 0) data.offsets[TransformConstraintData.SCALEY] = input.readFloat();
if ((flags & 32) != 0) data.offsets[TransformConstraintData.SHEARY] = input.readFloat();
if ((flags & 1) != 0)
data.offsets[TransformConstraintData.ROTATION] = input.readFloat();
if ((flags & 2) != 0)
data.offsets[TransformConstraintData.X] = input.readFloat() * scale;
if ((flags & 4) != 0)
data.offsets[TransformConstraintData.Y] = input.readFloat() * scale;
if ((flags & 8) != 0)
data.offsets[TransformConstraintData.SCALEX] = input.readFloat();
if ((flags & 16) != 0)
data.offsets[TransformConstraintData.SCALEY] = input.readFloat();
if ((flags & 32) != 0)
data.offsets[TransformConstraintData.SHEARY] = input.readFloat();
flags = input.readByte();
var setup = data.setup;
if ((flags & 1) != 0) setup.mixRotate = input.readFloat();
if ((flags & 2) != 0) setup.mixX = input.readFloat();
if ((flags & 4) != 0) setup.mixY = input.readFloat();
if ((flags & 8) != 0) setup.mixScaleX = input.readFloat();
if ((flags & 16) != 0) setup.mixScaleY = input.readFloat();
if ((flags & 32) != 0) setup.mixShearY = input.readFloat();
if ((flags & 1) != 0)
setup.mixRotate = input.readFloat();
if ((flags & 2) != 0)
setup.mixX = input.readFloat();
if ((flags & 4) != 0)
setup.mixY = input.readFloat();
if ((flags & 8) != 0)
setup.mixScaleX = input.readFloat();
if ((flags & 16) != 0)
setup.mixScaleY = input.readFloat();
if ((flags & 32) != 0)
setup.mixShearY = input.readFloat();
constraints[i] = data;
case CONSTRAINT_PATH:
var data = new PathConstraintData(name);
@ -336,12 +352,15 @@ class SkeletonBinary {
data.positionMode = PositionMode.values[(flags >> 1) & 2];
data.spacingMode = SpacingMode.values[(flags >> 2) & 3];
data.rotateMode = RotateMode.values[(flags >> 4) & 3];
if ((flags & 128) != 0) data.offsetRotation = input.readFloat();
if ((flags & 128) != 0)
data.offsetRotation = input.readFloat();
var setup = data.setup;
setup.position = input.readFloat();
if (data.positionMode == PositionMode.fixed) setup.position *= scale;
if (data.positionMode == PositionMode.fixed)
setup.position *= scale;
setup.spacing = input.readFloat();
if (data.spacingMode == SpacingMode.length || data.spacingMode == SpacingMode.fixed) setup.spacing *= scale;
if (data.spacingMode == SpacingMode.length || data.spacingMode == SpacingMode.fixed)
setup.spacing *= scale;
setup.mixRotate = input.readFloat();
setup.mixX = input.readFloat();
setup.mixY = input.readFloat();
@ -351,11 +370,16 @@ class SkeletonBinary {
data.bone = bones[input.readInt(true)];
var flags = input.readByte();
data.skinRequired = (flags & 1) != 0;
if ((flags & 2) != 0) data.x = input.readFloat();
if ((flags & 4) != 0) data.y = input.readFloat();
if ((flags & 8) != 0) data.rotate = input.readFloat();
if ((flags & 16) != 0) data.scaleX = input.readFloat();
if ((flags & 32) != 0) data.shearX = input.readFloat();
if ((flags & 2) != 0)
data.x = input.readFloat();
if ((flags & 4) != 0)
data.y = input.readFloat();
if ((flags & 8) != 0)
data.rotate = input.readFloat();
if ((flags & 16) != 0)
data.scaleX = input.readFloat();
if ((flags & 32) != 0)
data.shearX = input.readFloat();
data.limit = ((flags & 64) != 0 ? input.readFloat() : 5000) * scale;
data.step = .1 / input.readUnsignedByte();
var setup = data.setup;
@ -366,13 +390,20 @@ class SkeletonBinary {
setup.wind = input.readFloat();
setup.gravity = input.readFloat();
flags = input.readByte();
if ((flags & 1) != 0) data.inertiaGlobal = true;
if ((flags & 2) != 0) data.strengthGlobal = true;
if ((flags & 4) != 0) data.dampingGlobal = true;
if ((flags & 8) != 0) data.massGlobal = true;
if ((flags & 16) != 0) data.windGlobal = true;
if ((flags & 32) != 0) data.gravityGlobal = true;
if ((flags & 64) != 0) data.mixGlobal = true;
if ((flags & 1) != 0)
data.inertiaGlobal = true;
if ((flags & 2) != 0)
data.strengthGlobal = true;
if ((flags & 4) != 0)
data.dampingGlobal = true;
if ((flags & 8) != 0)
data.massGlobal = true;
if ((flags & 16) != 0)
data.windGlobal = true;
if ((flags & 32) != 0)
data.gravityGlobal = true;
if ((flags & 64) != 0)
data.mixGlobal = true;
setup.mix = (flags & 128) != 0 ? input.readFloat() : 1;
constraints[i] = data;
case CONSTRAINT_SLIDER:
@ -381,8 +412,10 @@ class SkeletonBinary {
data.skinRequired = (flags & 1) != 0;
data.loop = (flags & 2) != 0;
data.additive = (flags & 4) != 0;
if ((flags & 8) != 0) data.setup.time = input.readFloat();
if ((flags & 16) != 0) data.setup.mix = (flags & 32) != 0 ? input.readFloat() : 1;
if ((flags & 8) != 0)
data.setup.time = input.readFloat();
if ((flags & 16) != 0)
data.setup.mix = (flags & 32) != 0 ? input.readFloat() : 1;
if ((flags & 64) != 0) {
data.local = (flags & 128) != 0;
data.bone = bones[input.readInt(true)];
@ -392,10 +425,10 @@ class SkeletonBinary {
case 0: data.property = new FromRotate();
case 1:
propertyScale = scale;
data.property = new FromX();
data.property = new FromX();
case 2:
propertyScale = scale;
data.property = new FromY();
data.property = new FromY();
case 3: data.property = new FromScaleX();
case 4: data.property = new FromScaleY();
case 5: data.property = new FromShearY();
@ -409,7 +442,6 @@ class SkeletonBinary {
}
}
// Default skin.
var defaultSkin:Skin = readSkin(input, skeletonData, true, nonessential);
if (defaultSkin != null) {
@ -462,7 +494,7 @@ class SkeletonBinary {
animations[i] = readAnimation(input, input.readString(), skeletonData);
for (i in 0...constraintCount)
if (Std.isOfType(constraints[i], SliderData)){
if (Std.isOfType(constraints[i], SliderData)) {
var data = cast(constraints[i], SliderData);
data.animation = animations[input.readInt(true)];
};
@ -481,7 +513,8 @@ class SkeletonBinary {
} else {
skin = new Skin(input.readString());
if (nonessential) skin.color.setFromRgba8888(input.readInt32());
if (nonessential)
skin.color.setFromRgba8888(input.readInt32());
var n:Int;
var from1 = skeletonData.bones;
@ -622,7 +655,8 @@ class SkeletonBinary {
return mesh;
case AttachmentType.linkedmesh:
path = (flags & 16) != 0 ? input.readStringRef() : name;
if (path == null) throw new SpineException("Path of linked mesh must not be null");
if (path == null)
throw new SpineException("Path of linked mesh must not be null");
color = (flags & 32) != 0 ? input.readInt32() : 0xffffffff;
var sequence = (flags & 64) != 0 ? this.readSequence(input) : null;
var inheritTimelines:Bool = (flags & 128) != 0;
@ -757,11 +791,7 @@ class SkeletonBinary {
var i:Int = 0, n:Int = 0, ii:Int = 0, nn:Int = 0;
var index:Int, slotIndex:Int, timelineType:Int, timelineScale:Float;
var frameCount:Int,
frameLast:Int,
frame:Int,
bezierCount:Int,
bezier:Int;
var frameCount:Int, frameLast:Int, frame:Int, bezierCount:Int, bezier:Int;
var time:Float, time2:Float;
// Slot timelines.
@ -1009,19 +1039,26 @@ class SkeletonBinary {
}
bezierCount = input.readInt(true);
switch (timelineType) {
case BONE_ROTATE: readTimeline(input, timelines, new RotateTimeline(frameCount, bezierCount, boneIndex), 1);
case BONE_ROTATE:
readTimeline(input, timelines, new RotateTimeline(frameCount, bezierCount, boneIndex), 1);
case BONE_TRANSLATE: //
readTimeline2(input, timelines, new TranslateTimeline(frameCount, bezierCount, boneIndex), scale);
case BONE_TRANSLATEX: //
readTimeline(input, timelines, new TranslateXTimeline(frameCount, bezierCount, boneIndex), scale);
case BONE_TRANSLATEY: //
readTimeline(input, timelines, new TranslateYTimeline(frameCount, bezierCount, boneIndex), scale);
case BONE_SCALE: readTimeline2(input, timelines, new ScaleTimeline(frameCount, bezierCount, boneIndex), 1);
case BONE_SCALEX: readTimeline(input, timelines, new ScaleXTimeline(frameCount, bezierCount, boneIndex), 1);
case BONE_SCALEY: readTimeline(input, timelines, new ScaleYTimeline(frameCount, bezierCount, boneIndex), 1);
case BONE_SHEAR: readTimeline2(input, timelines, new ShearTimeline(frameCount, bezierCount, boneIndex), 1);
case BONE_SHEARX: readTimeline(input, timelines, new ShearXTimeline(frameCount, bezierCount, boneIndex), 1);
case BONE_SHEARY: readTimeline(input, timelines, new ShearYTimeline(frameCount, bezierCount, boneIndex), 1);
case BONE_SCALE:
readTimeline2(input, timelines, new ScaleTimeline(frameCount, bezierCount, boneIndex), 1);
case BONE_SCALEX:
readTimeline(input, timelines, new ScaleXTimeline(frameCount, bezierCount, boneIndex), 1);
case BONE_SCALEY:
readTimeline(input, timelines, new ScaleYTimeline(frameCount, bezierCount, boneIndex), 1);
case BONE_SHEAR:
readTimeline2(input, timelines, new ShearTimeline(frameCount, bezierCount, boneIndex), 1);
case BONE_SHEARX:
readTimeline(input, timelines, new ShearXTimeline(frameCount, bezierCount, boneIndex), 1);
case BONE_SHEARY:
readTimeline(input, timelines, new ShearYTimeline(frameCount, bezierCount, boneIndex), 1);
}
}
}
@ -1035,7 +1072,7 @@ class SkeletonBinary {
var flags = input.readByte();
time = input.readFloat();
var mix:Float = (flags & 1) != 0 ? ((flags & 2) != 0 ? input.readFloat() : 1) : 0;
var softness:Float = (flags & 4) != 0 ? input.readFloat() * scale : 0;
var softness:Float = (flags & 4) != 0 ? input.readFloat() * scale : 0;
frame = 0;
bezier = 0;
@ -1046,7 +1083,7 @@ class SkeletonBinary {
flags = input.readByte();
time2 = input.readFloat();
var mix2:Float = (flags & 1) != 0 ? ((flags & 2) != 0 ? input.readFloat() : 1) : 0;
var softness2:Float = (flags & 4) != 0 ? input.readFloat() * scale : 0;
var softness2:Float = (flags & 4) != 0 ? input.readFloat() * scale : 0;
if ((flags & 64) != 0) {
ikTimeline.setStepped(frame);
} else if ((flags & 128) != 0) {
@ -1094,7 +1131,8 @@ class SkeletonBinary {
mixScaleY2:Float = input.readFloat(),
mixShearY2:Float = input.readFloat();
switch (input.readByte()) {
case CURVE_STEPPED: transformTimeline.setStepped(frame);
case CURVE_STEPPED:
transformTimeline.setStepped(frame);
case CURVE_BEZIER:
setBezier(input, transformTimeline, bezier++, frame, 0, time, time2, mixRotate, mixRotate2, 1);
setBezier(input, transformTimeline, bezier++, frame, 1, time, time2, mixX, mixX2, 1);
@ -1122,15 +1160,16 @@ class SkeletonBinary {
index = input.readInt(true);
var data = cast(skeletonData.constraints[index], PathConstraintData);
for (ii in 0...input.readInt(true)) {
var type:Int = input.readByte(), frameCount:Int = input.readInt(true), bezierCount:Int = input.readInt(true);
var type:Int = input.readByte(),
frameCount:Int = input.readInt(true),
bezierCount:Int = input.readInt(true);
switch (type) {
case PATH_POSITION:
readTimeline(input, timelines, new PathConstraintPositionTimeline(frameCount, bezierCount, index),
data.positionMode == PositionMode.fixed ? scale : 1);
case PATH_SPACING:
readTimeline(input, timelines, new PathConstraintSpacingTimeline(frameCount, bezierCount, index),
data.spacingMode == SpacingMode.length
|| data.spacingMode == SpacingMode.fixed ? scale : 1);
readTimeline(input, timelines,
new PathConstraintSpacingTimeline(frameCount, bezierCount, index), data.spacingMode == SpacingMode.length || data.spacingMode == SpacingMode.fixed ? scale : 1);
case PATH_MIX:
var mixTimeline:PathConstraintMixTimeline = new PathConstraintMixTimeline(frameCount, bezierCount, index);
time = input.readFloat();
@ -1172,7 +1211,8 @@ class SkeletonBinary {
for (i in 0...input.readInt(true)) {
var constraintIndex:Int = input.readInt(true) - 1;
for (ii in 0...input.readInt(true)) {
var type:Int = input.readByte(), frameCount:Int = input.readInt(true);
var type:Int = input.readByte(),
frameCount:Int = input.readInt(true);
if (type == PHYSICS_RESET) {
var timeline:PhysicsConstraintResetTimeline = new PhysicsConstraintResetTimeline(frameCount, constraintIndex);
for (frame in 0...frameCount)
@ -1183,14 +1223,22 @@ class SkeletonBinary {
var bezierCount = input.readInt(true);
var timeline:CurveTimeline1;
switch (type) {
case PHYSICS_INERTIA: timeline = new PhysicsConstraintInertiaTimeline(frameCount, bezierCount, constraintIndex);
case PHYSICS_STRENGTH: timeline = new PhysicsConstraintStrengthTimeline(frameCount, bezierCount, constraintIndex);
case PHYSICS_DAMPING: timeline = new PhysicsConstraintDampingTimeline(frameCount, bezierCount, constraintIndex);
case PHYSICS_MASS: timeline = new PhysicsConstraintMassTimeline(frameCount, bezierCount, constraintIndex);
case PHYSICS_WIND: timeline = new PhysicsConstraintWindTimeline(frameCount, bezierCount, constraintIndex);
case PHYSICS_GRAVITY: timeline = new PhysicsConstraintGravityTimeline(frameCount, bezierCount, constraintIndex);
case PHYSICS_MIX: timeline = new PhysicsConstraintMixTimeline(frameCount, bezierCount, constraintIndex);
default: throw new SpineException("Unknown physics timeline type: " + type);
case PHYSICS_INERTIA:
timeline = new PhysicsConstraintInertiaTimeline(frameCount, bezierCount, constraintIndex);
case PHYSICS_STRENGTH:
timeline = new PhysicsConstraintStrengthTimeline(frameCount, bezierCount, constraintIndex);
case PHYSICS_DAMPING:
timeline = new PhysicsConstraintDampingTimeline(frameCount, bezierCount, constraintIndex);
case PHYSICS_MASS:
timeline = new PhysicsConstraintMassTimeline(frameCount, bezierCount, constraintIndex);
case PHYSICS_WIND:
timeline = new PhysicsConstraintWindTimeline(frameCount, bezierCount, constraintIndex);
case PHYSICS_GRAVITY:
timeline = new PhysicsConstraintGravityTimeline(frameCount, bezierCount, constraintIndex);
case PHYSICS_MIX:
timeline = new PhysicsConstraintMixTimeline(frameCount, bezierCount, constraintIndex);
default:
throw new SpineException("Unknown physics timeline type: " + type);
}
readTimeline(input, timelines, timeline, 1);
}
@ -1200,12 +1248,17 @@ class SkeletonBinary {
for (i in 0...input.readInt(true)) {
var index = input.readInt(true);
for (ii in 0...input.readInt(true)) {
var type = input.readByte(), frameCount = input.readInt(true), bezierCount = input.readInt(true);
var type = input.readByte(),
frameCount = input.readInt(true),
bezierCount = input.readInt(true);
var timeline:CurveTimeline1;
switch (type) {
case SLIDER_TIME: timeline = new SliderTimeline(frameCount, bezierCount, index);
case SLIDER_MIX: timeline = new SliderMixTimeline(frameCount, bezierCount, index);
default: throw new SpineException("Unknown slider timeline type: " + type);
case SLIDER_TIME:
timeline = new SliderTimeline(frameCount, bezierCount, index);
case SLIDER_MIX:
timeline = new SliderMixTimeline(frameCount, bezierCount, index);
default:
throw new SpineException("Unknown slider timeline type: " + type);
}
readTimeline(input, timelines, timeline, 1);
}
@ -1350,7 +1403,8 @@ class SkeletonBinary {
event.intValue = input.readInt(false);
event.floatValue = input.readFloat();
event.stringValue = input.readString();
if (event.stringValue == null) event.stringValue = eventData.stringValue;
if (event.stringValue == null)
event.stringValue = eventData.stringValue;
if (event.data.audioPath != null) {
event.volume = input.readFloat();
event.balance = input.readFloat();
@ -1370,9 +1424,7 @@ class SkeletonBinary {
var time:Float = input.readFloat(),
value:Float = input.readFloat() * scale;
var frame:Int = 0,
bezier:Int = 0,
frameLast:Int = timeline.getFrameCount() - 1;
var frame:Int = 0, bezier:Int = 0, frameLast:Int = timeline.getFrameCount() - 1;
while (true) {
timeline.setFrame(frame, time, value);
if (frame == frameLast)
@ -1381,8 +1433,10 @@ class SkeletonBinary {
var time2:Float = input.readFloat(),
value2:Float = input.readFloat() * scale;
switch (input.readByte()) {
case CURVE_STEPPED: timeline.setStepped(frame);
case CURVE_BEZIER: setBezier(input, timeline, bezier++, frame, 0, time, time2, value, value2, scale);
case CURVE_STEPPED:
timeline.setStepped(frame);
case CURVE_BEZIER:
setBezier(input, timeline, bezier++, frame, 0, time, time2, value, value2, scale);
}
time = time2;
value = value2;
@ -1397,9 +1451,7 @@ class SkeletonBinary {
value1:Float = input.readFloat() * scale,
value2:Float = input.readFloat() * scale;
var frame:Int = 0,
bezier:Int = 0,
frameLast:Int = timeline.getFrameCount() - 1;
var frame:Int = 0, bezier:Int = 0, frameLast:Int = timeline.getFrameCount() - 1;
while (true) {
timeline.setFrame(frame, time, value1, value2);
if (frame == frameLast)
@ -1409,7 +1461,8 @@ class SkeletonBinary {
nvalue1:Float = input.readFloat() * scale,
nvalue2:Float = input.readFloat() * scale;
switch (input.readByte()) {
case CURVE_STEPPED: timeline.setStepped(frame);
case CURVE_STEPPED:
timeline.setStepped(frame);
case CURVE_BEZIER:
setBezier(input, timeline, bezier++, frame, 0, time, time2, value1, nvalue1, scale);
setBezier(input, timeline, bezier++, frame, 1, time, time2, value2, nvalue2, scale);

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
@ -48,9 +48,11 @@ class SkeletonClipping {
public function new() {}
public function clipStart(skeleton:Skeleton, slot:Slot, clip:ClippingAttachment):Int {
if (clipAttachment != null) return 0;
if (clipAttachment != null)
return 0;
var n = clip.worldVerticesLength;
if (n < 6) return 0;
if (n < 6)
return 0;
clipAttachment = clip;
clippingPolygon.resize(n);
@ -66,7 +68,8 @@ class SkeletonClipping {
}
public function clipEnd(?slot:Slot):Void {
if (clipAttachment == null || (slot != null && clipAttachment.endSlot != slot.data)) return;
if (clipAttachment == null || (slot != null && clipAttachment.endSlot != slot.data))
return;
clipAttachment = null;
clippingPolygons = null;
clippedVertices.resize(0);
@ -203,7 +206,8 @@ class SkeletonClipping {
var ii:Int = 0;
while (ii < clipOutputLength) {
var x = clipOutputItems[ii], y = clipOutputItems[ii + 1];
var x = clipOutputItems[ii],
y = clipOutputItems[ii + 1];
clippedVerticesItems[s] = x;
clippedVerticesItems[s + 1] = y;
var c0 = x - x3, c1 = y - y3;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
@ -91,6 +91,7 @@ class SkeletonData {
public var hash:String;
// Nonessential.
/** The dopesheet FPS in Spine, or zero if nonessential data was not exported. */
public var fps:Float = 0;
@ -123,9 +124,11 @@ class SkeletonData {
* @param boneName The name of the bone to find.
* @return May be null. */
public function findBone(boneName:String):BoneData {
if (boneName == null) throw new SpineException("boneName cannot be null.");
if (boneName == null)
throw new SpineException("boneName cannot be null.");
for (bone in bones)
if (bone.name == boneName) return bone;
if (bone.name == boneName)
return bone;
return null;
}
@ -149,9 +152,11 @@ class SkeletonData {
* @param slotName The name of the slot to find.
* @return May be null. */
public function findSlot(slotName:String):SlotData {
if (slotName == null) throw new SpineException("slotName cannot be null.");
if (slotName == null)
throw new SpineException("slotName cannot be null.");
for (slot in slots)
if (slot.name == slotName) return slot;
if (slot.name == slotName)
return slot;
return null;
}
@ -162,9 +167,11 @@ class SkeletonData {
* @param skinName The name of the skin to find.
* @return May be null. */
public function findSkin(skinName:String):Skin {
if (skinName == null) throw new SpineException("skinName cannot be null.");
if (skinName == null)
throw new SpineException("skinName cannot be null.");
for (skin in skins)
if (skin.name == skinName) return skin;
if (skin.name == skinName)
return skin;
return null;
}
@ -175,9 +182,11 @@ class SkeletonData {
* @param eventName The name of the event to find.
* @return May be null. */
public function findEvent(eventName:String):EventData {
if (eventName == null) throw new SpineException("eventName cannot be null.");
if (eventName == null)
throw new SpineException("eventName cannot be null.");
for (eventData in events)
if (eventData.name == eventName) return eventData;
if (eventData.name == eventName)
return eventData;
return null;
}
@ -188,17 +197,21 @@ class SkeletonData {
* @param animationName The name of the animation to find.
* @return May be null. */
public function findAnimation(animationName:String):Animation {
if (animationName == null) throw new SpineException("animationName cannot be null.");
if (animationName == null)
throw new SpineException("animationName cannot be null.");
for (animation in animations)
if (animation.name == animationName) return animation;
if (animation.name == animationName)
return animation;
return null;
}
// --- Constraints.
public function findConstraint<T:ConstraintData<Dynamic, Dynamic>>(constraintName:String, type:Class<T>):T {
if (constraintName == null) throw new SpineException("constraintName cannot be null.");
if (type == null) throw new SpineException("type cannot be null.");
if (constraintName == null)
throw new SpineException("constraintName cannot be null.");
if (type == null)
throw new SpineException("type cannot be null.");
for (constraint in constraints) {
if (Std.isOfType(constraint, type) && constraint.name == constraintName)

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
@ -140,7 +140,8 @@ class SkeletonJson {
data.skinRequired = Reflect.hasField(boneMap, "skin") ? cast(Reflect.getProperty(boneMap, "skin"), Bool) : false;
var color:String = Reflect.getProperty(boneMap, "color");
if (color != null) data.color.setFromString(color);
if (color != null)
data.color.setFromString(color);
skeletonData.bones.push(data);
}
@ -150,15 +151,18 @@ class SkeletonJson {
var slotName:String = Reflect.getProperty(slotMap, "name");
var boneName:String = Reflect.getProperty(slotMap, "bone");
var boneData = skeletonData.findBone(boneName);
if (boneData == null) throw new SpineException("Slot bone not found: " + boneName);
if (boneData == null)
throw new SpineException("Slot bone not found: " + boneName);
var data = new SlotData(skeletonData.slots.length, slotName, boneData);
var color:String = Reflect.getProperty(slotMap, "color");
if (color != null) data.setup.color.setFromString(color);
if (color != null)
data.setup.color.setFromString(color);
var dark:String = Reflect.getProperty(slotMap, "dark");
if (dark != null) data.setup.darkColor = new Color(0, 0, 0).setFromString(dark);
if (dark != null)
data.setup.darkColor = new Color(0, 0, 0).setFromString(dark);
data.attachmentName = Reflect.getProperty(slotMap, "attachment");
data.blendMode = Reflect.hasField(slotMap, "blend") ? BlendMode.fromName(Reflect.getProperty(slotMap, "blend")) : BlendMode.normal;
@ -179,20 +183,26 @@ class SkeletonJson {
for (boneName in cast(Reflect.getProperty(constraintMap, "bones"), Array<Dynamic>)) {
var bone = skeletonData.findBone(boneName);
if (bone == null) throw new SpineException("IK constraint bone not found: " + boneName);
if (bone == null)
throw new SpineException("IK constraint bone not found: " + boneName);
data.bones.push(bone);
}
data.target = skeletonData.findBone(Reflect.getProperty(constraintMap, "target"));
if (data.target == null) throw new SpineException("Target bone not found: " + Reflect.getProperty(constraintMap, "target"));
if (data.target == null)
throw new SpineException("Target bone not found: " + Reflect.getProperty(constraintMap, "target"));
data.uniform = (Reflect.hasField(constraintMap, "uniform") && cast(Reflect.getProperty(constraintMap, "uniform"), Bool));
data.uniform = (Reflect.hasField(constraintMap, "uniform")
&& cast(Reflect.getProperty(constraintMap, "uniform"), Bool));
var setup = data.setup;
setup.mix = getFloat(constraintMap, "mix", 1);
setup.softness = getFloat(constraintMap, "softness", 0) * scale;
setup.bendDirection = (!Reflect.hasField(constraintMap, "bendPositive") || cast(Reflect.getProperty(constraintMap, "bendPositive"), Bool)) ? 1 : -1;
setup.compress = (Reflect.hasField(constraintMap, "compress") && cast(Reflect.getProperty(constraintMap, "compress"), Bool));
setup.stretch = (Reflect.hasField(constraintMap, "stretch") && cast(Reflect.getProperty(constraintMap, "stretch"), Bool));
setup.bendDirection = (!Reflect.hasField(constraintMap, "bendPositive")
|| cast(Reflect.getProperty(constraintMap, "bendPositive"), Bool)) ? 1 : -1;
setup.compress = (Reflect.hasField(constraintMap, "compress")
&& cast(Reflect.getProperty(constraintMap, "compress"), Bool));
setup.stretch = (Reflect.hasField(constraintMap, "stretch")
&& cast(Reflect.getProperty(constraintMap, "stretch"), Bool));
skeletonData.constraints.push(data);
case "transform":
@ -201,15 +211,19 @@ class SkeletonJson {
for (boneName in cast(Reflect.getProperty(constraintMap, "bones"), Array<Dynamic>)) {
var bone = skeletonData.findBone(boneName);
if (bone == null) throw new SpineException("Transform constraint bone not found: " + boneName);
if (bone == null)
throw new SpineException("Transform constraint bone not found: " + boneName);
data.bones.push(bone);
}
data.source = skeletonData.findBone(Reflect.getProperty(constraintMap, "source"));
if (data.source == null) throw new SpineException("Transform constraint source bone not found: " + Reflect.getProperty(constraintMap, "source"));
if (data.source == null)
throw new SpineException("Transform constraint source bone not found: " + Reflect.getProperty(constraintMap, "source"));
data.localSource = Reflect.hasField(constraintMap, "localSource") ? cast(Reflect.getProperty(constraintMap, "localSource"), Bool) : false;
data.localTarget = Reflect.hasField(constraintMap, "localTarget") ? cast(Reflect.getProperty(constraintMap, "localTarget"), Bool) : false;
data.localSource = Reflect.hasField(constraintMap,
"localSource") ? cast(Reflect.getProperty(constraintMap, "localSource"), Bool) : false;
data.localTarget = Reflect.hasField(constraintMap,
"localTarget") ? cast(Reflect.getProperty(constraintMap, "localTarget"), Bool) : false;
data.additive = Reflect.hasField(constraintMap, "additive") ? cast(Reflect.getProperty(constraintMap, "additive"), Bool) : false;
data.clamp = Reflect.hasField(constraintMap, "clamp") ? cast(Reflect.getProperty(constraintMap, "clamp"), Bool) : false;
@ -227,31 +241,31 @@ class SkeletonJson {
var to:ToProperty;
switch (name) {
case "rotate": {
rotate = true;
to = new ToRotate();
}
rotate = true;
to = new ToRotate();
}
case "x": {
x = true;
to = new ToX();
toScale = scale;
}
x = true;
to = new ToX();
toScale = scale;
}
case "y": {
y = true;
to = new ToY();
toScale = scale;
}
y = true;
to = new ToY();
toScale = scale;
}
case "scaleX": {
scaleX = true;
to = new ToScaleX();
}
scaleX = true;
to = new ToScaleX();
}
case "scaleY": {
scaleY = true;
to = new ToScaleY();
}
scaleY = true;
to = new ToScaleY();
}
case "shearY": {
shearY = true;
to = new ToShearY();
}
shearY = true;
to = new ToShearY();
}
default: throw new SpineException("Invalid transform constraint to property: " + toEntry.name);
}
to.offset = getFloat(toEntry, "offset", 0) * toScale;
@ -259,7 +273,8 @@ class SkeletonJson {
to.scale = getFloat(toEntry, "scale") * toScale / fromScale;
from.to.push(to);
}
if (from.to.length > 0) data.properties.push(from);
if (from.to.length > 0)
data.properties.push(from);
}
data.offsets[TransformConstraintData.ROTATION] = getFloat(constraintMap, "rotation", 0);
@ -270,12 +285,18 @@ class SkeletonJson {
data.offsets[TransformConstraintData.SHEARY] = getFloat(constraintMap, "shearY", 0);
var setup = data.setup;
if (rotate) setup.mixRotate = getFloat(constraintMap, "mixRotate", 1);
if (x) setup.mixX = getFloat(constraintMap, "mixX", 1);
if (y) setup.mixY = getFloat(constraintMap, "mixY", setup.mixX);
if (scaleX) setup.mixScaleX = getFloat(constraintMap, "mixScaleX", 1);
if (scaleY) setup.mixScaleY = getFloat(constraintMap, "mixScaleY", setup.mixScaleX);
if (shearY) setup.mixShearY = getFloat(constraintMap, "mixShearY", 1);
if (rotate)
setup.mixRotate = getFloat(constraintMap, "mixRotate", 1);
if (x)
setup.mixX = getFloat(constraintMap, "mixX", 1);
if (y)
setup.mixY = getFloat(constraintMap, "mixY", setup.mixX);
if (scaleX)
setup.mixScaleX = getFloat(constraintMap, "mixScaleX", 1);
if (scaleY)
setup.mixScaleY = getFloat(constraintMap, "mixScaleY", setup.mixScaleX);
if (shearY)
setup.mixShearY = getFloat(constraintMap, "mixShearY", 1);
skeletonData.constraints.push(data);
case "path":
@ -284,23 +305,30 @@ class SkeletonJson {
for (boneName in cast(Reflect.getProperty(constraintMap, "bones"), Array<Dynamic>)) {
var bone = skeletonData.findBone(boneName);
if (bone == null) throw new SpineException("Path bone not found: " + boneName);
if (bone == null)
throw new SpineException("Path bone not found: " + boneName);
data.bones.push(bone);
}
var slotName = getString(constraintMap, "slot", "");
data.slot = skeletonData.findSlot(slotName);
if (data.slot == null) throw new SpineException("Path slot not found: " + slotName);
if (data.slot == null)
throw new SpineException("Path slot not found: " + slotName);
data.positionMode = Reflect.hasField(constraintMap, "positionMode") ? PositionMode.fromName(Reflect.getProperty(constraintMap, "positionMode")) : PositionMode.percent;
data.spacingMode = Reflect.hasField(constraintMap, "spacingMode") ? SpacingMode.fromName(Reflect.getProperty(constraintMap, "spacingMode")) : SpacingMode.length;
data.rotateMode = Reflect.hasField(constraintMap, "rotateMode") ? RotateMode.fromName(Reflect.getProperty(constraintMap, "rotateMode")) : RotateMode.tangent;
data.positionMode = Reflect.hasField(constraintMap,
"positionMode") ? PositionMode.fromName(Reflect.getProperty(constraintMap, "positionMode")) : PositionMode.percent;
data.spacingMode = Reflect.hasField(constraintMap,
"spacingMode") ? SpacingMode.fromName(Reflect.getProperty(constraintMap, "spacingMode")) : SpacingMode.length;
data.rotateMode = Reflect.hasField(constraintMap,
"rotateMode") ? RotateMode.fromName(Reflect.getProperty(constraintMap, "rotateMode")) : RotateMode.tangent;
data.offsetRotation = getFloat(constraintMap, "rotation", 0);
var setup = data.setup;
setup.position = getFloat(constraintMap, "position", 0);
if (data.positionMode == PositionMode.fixed) setup.position *= scale;
if (data.positionMode == PositionMode.fixed)
setup.position *= scale;
setup.spacing = getFloat(constraintMap, "spacing", 0);
if (data.spacingMode == SpacingMode.length || data.spacingMode == SpacingMode.fixed) setup.spacing *= scale;
if (data.spacingMode == SpacingMode.length || data.spacingMode == SpacingMode.fixed)
setup.spacing *= scale;
setup.mixRotate = getFloat(constraintMap, "mixRotate", 1);
setup.mixX = getFloat(constraintMap, "mixX", 1);
setup.mixY = getFloat(constraintMap, "mixY", setup.mixX);
@ -312,7 +340,8 @@ class SkeletonJson {
var boneName:String = getString(constraintMap, "bone");
data.bone = skeletonData.findBone(boneName);
if (data.bone == null) throw new SpineException("Physics bone not found: " + boneName);
if (data.bone == null)
throw new SpineException("Physics bone not found: " + boneName);
data.x = getFloat(constraintMap, "x");
data.y = getFloat(constraintMap, "y");
@ -329,12 +358,17 @@ class SkeletonJson {
setup.wind = getFloat(constraintMap, "wind", 0);
setup.gravity = getFloat(constraintMap, "gravity", 0);
setup.mix = getValue(constraintMap, "mix", 1);
data.inertiaGlobal = Reflect.hasField(constraintMap, "inertiaGlobal") ? cast(Reflect.getProperty(constraintMap, "inertiaGlobal"), Bool) : false;
data.strengthGlobal = Reflect.hasField(constraintMap, "strengthGlobal") ? cast(Reflect.getProperty(constraintMap, "strengthGlobal"), Bool) : false;
data.dampingGlobal = Reflect.hasField(constraintMap, "dampingGlobal") ? cast(Reflect.getProperty(constraintMap, "dampingGlobal"), Bool) : false;
data.dampingGlobal = Reflect.hasField(constraintMap, "dampingGlobal") ? cast(Reflect.getProperty(constraintMap, "dampingGlobal"), Bool) : false;
data.inertiaGlobal = Reflect.hasField(constraintMap,
"inertiaGlobal") ? cast(Reflect.getProperty(constraintMap, "inertiaGlobal"), Bool) : false;
data.strengthGlobal = Reflect.hasField(constraintMap,
"strengthGlobal") ? cast(Reflect.getProperty(constraintMap, "strengthGlobal"), Bool) : false;
data.dampingGlobal = Reflect.hasField(constraintMap,
"dampingGlobal") ? cast(Reflect.getProperty(constraintMap, "dampingGlobal"), Bool) : false;
data.dampingGlobal = Reflect.hasField(constraintMap,
"dampingGlobal") ? cast(Reflect.getProperty(constraintMap, "dampingGlobal"), Bool) : false;
data.windGlobal = Reflect.hasField(constraintMap, "windGlobal") ? cast(Reflect.getProperty(constraintMap, "windGlobal"), Bool) : false;
data.gravityGlobal = Reflect.hasField(constraintMap, "gravityGlobal") ? cast(Reflect.getProperty(constraintMap, "gravityGlobal"), Bool) : false;
data.gravityGlobal = Reflect.hasField(constraintMap,
"gravityGlobal") ? cast(Reflect.getProperty(constraintMap, "gravityGlobal"), Bool) : false;
data.mixGlobal = Reflect.hasField(constraintMap, "mixGlobal") ? cast(Reflect.getProperty(constraintMap, "mixGlobal"), Bool) : false;
skeletonData.constraints.push(data);
@ -349,7 +383,8 @@ class SkeletonJson {
var boneName = getString(constraintMap, "bone", null);
if (boneName != null) {
data.bone = skeletonData.findBone(boneName);
if (data.bone == null) throw new SpineException("Slider bone not found: " + boneName);
if (data.bone == null)
throw new SpineException("Slider bone not found: " + boneName);
var property = getString(constraintMap, "property");
data.property = fromProperty(property);
var propertyScale = propertyScale(property, scale);
@ -364,7 +399,6 @@ class SkeletonJson {
}
}
// Skins.
if (Reflect.hasField(root, "skins")) {
for (skinMap in cast(Reflect.getProperty(root, "skins"), Array<Dynamic>)) {
@ -424,7 +458,8 @@ class SkeletonJson {
var slider = cast(Reflect.getProperty(skinMap, "slider"), Array<Dynamic>);
for (ii in 0...slider.length) {
var constraint = skeletonData.findConstraint(slider[ii], SliderData);
if (constraint == null) throw new SpineException("Skin slider constraint not found: " + slider[ii]);
if (constraint == null)
throw new SpineException("Skin slider constraint not found: " + slider[ii]);
skin.constraints.push(constraint);
}
}
@ -495,7 +530,8 @@ class SkeletonJson {
var data = skeletonData.findConstraint(getString(constraintMap, "name"), SliderData);
var animationName = getString(constraintMap, "animation", "");
data.animation = skeletonData.findAnimation(animationName);
if (data.animation == null) throw new SpineException("Slider animation not found: " + animationName);
if (data.animation == null)
throw new SpineException("Slider animation not found: " + animationName);
}
}
}
@ -503,25 +539,34 @@ class SkeletonJson {
return skeletonData;
}
private function fromProperty (type:String): FromProperty {
private function fromProperty(type:String):FromProperty {
var property:FromProperty;
switch (type) {
case "rotate": property = new FromRotate();
case "x": property = new FromX();
case "y": property = new FromY();
case "scaleX": property = new FromScaleX();
case "scaleY": property = new FromScaleY();
case "shearY": property = new FromShearY();
default: throw new SpineException("Invalid from property: " + type);
case "rotate":
property = new FromRotate();
case "x":
property = new FromX();
case "y":
property = new FromY();
case "scaleX":
property = new FromScaleX();
case "scaleY":
property = new FromScaleY();
case "shearY":
property = new FromShearY();
default:
throw new SpineException("Invalid from property: " + type);
};
return property;
}
private function propertyScale (type:String, scale:Float):Float {
private function propertyScale(type:String, scale:Float):Float {
var scaleValue:Float;
switch (type) {
case "x", "y": scaleValue = scale;
default: scaleValue = 1;
case "x", "y":
scaleValue = scale;
default:
scaleValue = 1;
};
return scaleValue;
}
@ -709,7 +754,8 @@ class SkeletonJson {
slotIndex = skeletonData.findSlot(slotName).index;
for (timelineName in Reflect.fields(slotMap)) {
timelineMap = Reflect.field(slotMap, timelineName);
if (timelineMap == null) continue;
if (timelineMap == null)
continue;
switch (timelineName) {
case "attachment":
@ -782,7 +828,8 @@ class SkeletonJson {
}
timelines.push(rgbTimeline);
case "alpha": readTimeline(timelines, timelineMap, new AlphaTimeline(timelineMap.length, timelineMap.length, slotIndex), 0, 1);
case "alpha":
readTimeline(timelines, timelineMap, new AlphaTimeline(timelineMap.length, timelineMap.length, slotIndex), 0, 1);
case "rgba2":
var rgba2Timeline = new RGBA2Timeline(timelineMap.length, timelineMap.length * 7, slotIndex);
@ -862,7 +909,8 @@ class SkeletonJson {
}
timelines.push(rgb2Timeline);
default: throw new SpineException("Invalid timeline type for a slot: " + timelineName + " (" + slotName + ")");
default:
throw new SpineException("Invalid timeline type for a slot: " + timelineName + " (" + slotName + ")");
}
}
}
@ -871,24 +919,36 @@ class SkeletonJson {
var bones = Reflect.getProperty(map, "bones");
for (boneName in Reflect.fields(bones)) {
var boneIndex:Int = skeletonData.findBoneIndex(boneName);
if (boneIndex == -1) throw new SpineException("Bone not found: " + boneName);
if (boneIndex == -1)
throw new SpineException("Bone not found: " + boneName);
var boneMap:Dynamic = Reflect.field(bones, boneName);
for (timelineName in Reflect.fields(boneMap)) {
timelineMap = Reflect.field(boneMap, timelineName);
var frames = timelineMap.length;
if (frames == 0) continue;
if (frames == 0)
continue;
switch (timelineName) {
case "rotate": readTimeline(timelines, timelineMap, new RotateTimeline(frames, frames, boneIndex), 0, 1);
case "translate": readTimeline2(timelines, timelineMap, new TranslateTimeline(frames, frames << 1, boneIndex), "x", "y", 0, scale);
case "translatex": readTimeline(timelines, timelineMap, new TranslateXTimeline(frames, frames, boneIndex), 0, scale);
case "translatey": readTimeline(timelines, timelineMap, new TranslateYTimeline(frames, frames, boneIndex), 0, scale);
case "scale": readTimeline2(timelines, timelineMap, new ScaleTimeline(frames, frames << 1, boneIndex), "x", "y", 1, 1);
case "scalex": readTimeline(timelines, timelineMap, new ScaleXTimeline(frames, frames, boneIndex), 1, 1);
case "scaley": readTimeline(timelines, timelineMap, new ScaleYTimeline(frames, frames, boneIndex), 1, 1);
case "shear": readTimeline2(timelines, timelineMap, new ShearTimeline(frames, frames << 1, boneIndex), "x", "y", 0, 1);
case "shearx": readTimeline(timelines, timelineMap, new ShearXTimeline(frames, frames, boneIndex), 0, 1);
case "sheary": readTimeline(timelines, timelineMap, new ShearYTimeline(frames, frames, boneIndex), 0, 1);
case "rotate":
readTimeline(timelines, timelineMap, new RotateTimeline(frames, frames, boneIndex), 0, 1);
case "translate":
readTimeline2(timelines, timelineMap, new TranslateTimeline(frames, frames << 1, boneIndex), "x", "y", 0, scale);
case "translatex":
readTimeline(timelines, timelineMap, new TranslateXTimeline(frames, frames, boneIndex), 0, scale);
case "translatey":
readTimeline(timelines, timelineMap, new TranslateYTimeline(frames, frames, boneIndex), 0, scale);
case "scale":
readTimeline2(timelines, timelineMap, new ScaleTimeline(frames, frames << 1, boneIndex), "x", "y", 1, 1);
case "scalex":
readTimeline(timelines, timelineMap, new ScaleXTimeline(frames, frames, boneIndex), 1, 1);
case "scaley":
readTimeline(timelines, timelineMap, new ScaleYTimeline(frames, frames, boneIndex), 1, 1);
case "shear":
readTimeline2(timelines, timelineMap, new ShearTimeline(frames, frames << 1, boneIndex), "x", "y", 0, 1);
case "shearx":
readTimeline(timelines, timelineMap, new ShearXTimeline(frames, frames, boneIndex), 0, 1);
case "sheary":
readTimeline(timelines, timelineMap, new ShearYTimeline(frames, frames, boneIndex), 0, 1);
case "inherit":
var timeline = new InheritTimeline(frames, boneIndex);
for (frame in 0...frames) {
@ -896,7 +956,8 @@ class SkeletonJson {
timeline.setFrame(frame, getFloat(aFrame, "time"), Inherit.fromName(getValue(aFrame, "inherit", "Normal")));
}
timelines.push(timeline);
default: throw new SpineException("Invalid timeline type for a bone: " + timelineName + " (" + boneName + ")");
default:
throw new SpineException("Invalid timeline type for a bone: " + timelineName + " (" + boneName + ")");
}
}
}
@ -906,12 +967,13 @@ class SkeletonJson {
for (ikConstraintName in Reflect.fields(iks)) {
timelineMap = Reflect.field(iks, ikConstraintName);
keyMap = timelineMap[0];
if (keyMap == null) continue;
if (keyMap == null)
continue;
var constraint = skeletonData.findConstraint(ikConstraintName, IkConstraintData);
if (constraint == null) throw new SpineException("IK constraint not found: " + ikConstraintName);
var timeline = new IkConstraintTimeline(timelineMap.length, timelineMap.length << 1,
skeletonData.constraints.indexOf(constraint));
if (constraint == null)
throw new SpineException("IK constraint not found: " + ikConstraintName);
var timeline = new IkConstraintTimeline(timelineMap.length, timelineMap.length << 1, skeletonData.constraints.indexOf(constraint));
time = getFloat(keyMap, "time");
var mix:Float = getFloat(keyMap, "mix", 1);
@ -955,15 +1017,18 @@ class SkeletonJson {
for (transformName in Reflect.fields(transforms)) {
timelineMap = Reflect.field(transforms, transformName);
keyMap = timelineMap[0];
if (keyMap == null) continue;
if (keyMap == null)
continue;
var constraint = skeletonData.findConstraint(transformName, TransformConstraintData);
if (constraint == null) throw new SpineException("Transform constraint not found: " + transformName);
var timeline = new TransformConstraintTimeline(timelineMap.length, timelineMap.length * 6,
skeletonData.constraints.indexOf(constraint));
if (constraint == null)
throw new SpineException("Transform constraint not found: " + transformName);
var timeline = new TransformConstraintTimeline(timelineMap.length, timelineMap.length * 6, skeletonData.constraints.indexOf(constraint));
var time = getFloat(keyMap, "time", 0);
var mixRotate = getFloat(keyMap, "mixRotate", 1);
var mixX = getFloat(keyMap, "mixX", 1), mixY = getFloat(keyMap, "mixY", mixX);
var mixScaleX:Float = getFloat(keyMap, "mixScaleX", 1), mixScaleY:Float = getFloat(keyMap, "mixScaleY", 1);
var mixX = getFloat(keyMap, "mixX", 1),
mixY = getFloat(keyMap, "mixY", mixX);
var mixScaleX:Float = getFloat(keyMap, "mixScaleX", 1),
mixScaleY:Float = getFloat(keyMap, "mixScaleY", 1);
var mixShearY:Float = getFloat(keyMap, "mixShearY", 1);
frame = 0;
@ -978,8 +1043,10 @@ class SkeletonJson {
var time2 = getFloat(nextMap, "time", 0);
var mixRotate2 = getFloat(nextMap, "mixRotate", 1);
var mixX2 = getFloat(nextMap, "mixX", 1), mixY2 = getFloat(nextMap, "mixY", mixX2);
var mixScaleX2:Float = getFloat(nextMap, "mixScaleX", 1), mixScaleY2:Float = getFloat(nextMap, "mixScaleY", 1);
var mixX2 = getFloat(nextMap, "mixX", 1),
mixY2 = getFloat(nextMap, "mixY", mixX2);
var mixScaleX2:Float = getFloat(nextMap, "mixScaleX", 1),
mixScaleY2:Float = getFloat(nextMap, "mixScaleY", 1);
var mixShearY2:Float = getFloat(nextMap, "mixShearY", 1);
var curve = keyMap.curve;
if (curve != null) {
@ -1009,14 +1076,16 @@ class SkeletonJson {
var paths:Dynamic = Reflect.getProperty(map, "path");
for (pathName in Reflect.fields(paths)) {
var constraint = skeletonData.findConstraint(pathName, PathConstraintData);
if (constraint == null) throw new SpineException("Path constraint not found: " + pathName);
if (constraint == null)
throw new SpineException("Path constraint not found: " + pathName);
var index = skeletonData.constraints.indexOf(constraint);
var pathMap:Dynamic = Reflect.field(paths, pathName);
for (timelineName in Reflect.fields(pathMap)) {
timelineMap = Reflect.field(pathMap, timelineName);
keyMap = timelineMap[0];
if (keyMap == null) continue;
if (keyMap == null)
continue;
switch (timelineName) {
case "position":
@ -1024,8 +1093,8 @@ class SkeletonJson {
readTimeline(timelines, timelineMap, timeline, 0, constraint.positionMode == PositionMode.fixed ? scale : 1);
case "spacing":
var timeline = new PathConstraintSpacingTimeline(timelineMap.length, timelineMap.length, index);
readTimeline(timelines, timelineMap, timeline, 0,
constraint.spacingMode == SpacingMode.length || constraint.spacingMode == SpacingMode.fixed ? scale : 1);
readTimeline(timelines, timelineMap, timeline,
0, constraint.spacingMode == SpacingMode.length || constraint.spacingMode == SpacingMode.fixed ? scale : 1);
case "mix":
var timeline = new PathConstraintMixTimeline(timelineMap.length, timelineMap.length * 3, index);
var time = getFloat(keyMap, "time");
@ -1072,18 +1141,20 @@ class SkeletonJson {
var index = -1;
if (physicsName.length > 0) {
var constraint = skeletonData.findConstraint(physicsName, PhysicsConstraintData);
if (constraint == null) throw new SpineException("Physics constraint not found: " + physicsName);
if (constraint == null)
throw new SpineException("Physics constraint not found: " + physicsName);
index = skeletonData.constraints.indexOf(constraint);
}
var physicsMap:Dynamic = Reflect.field(physics, physicsName);
for (timelineName in Reflect.fields(physicsMap)) {
timelineMap = Reflect.field(physicsMap, timelineName);
keyMap = timelineMap[0];
if (keyMap == null) continue;
if (keyMap == null)
continue;
var frames = timelineMap.length;
var timeline: CurveTimeline1;
var timeline:CurveTimeline1;
var defaultValue = 0.;
switch (timelineName) {
case "reset":
@ -1092,17 +1163,25 @@ class SkeletonJson {
resetTimeline.setFrame(frame, getFloat(keyMap, "time"));
timelines.push(resetTimeline);
continue;
case "inertia": timeline = new PhysicsConstraintInertiaTimeline(frames, frames, index);
case "strength": timeline = new PhysicsConstraintStrengthTimeline(frames, frames, index);
case "damping": timeline = new PhysicsConstraintDampingTimeline(frames, frames, index);
case "mass": timeline = new PhysicsConstraintMassTimeline(frames, frames, index);
case "wind": timeline = new PhysicsConstraintWindTimeline(frames, frames, index);
case "gravity": timeline = new PhysicsConstraintGravityTimeline(frames, frames, index);
case "mix": {
defaultValue = 1;
timeline = new PhysicsConstraintMixTimeline(frames, frames, index);
}
default: continue;
case "inertia":
timeline = new PhysicsConstraintInertiaTimeline(frames, frames, index);
case "strength":
timeline = new PhysicsConstraintStrengthTimeline(frames, frames, index);
case "damping":
timeline = new PhysicsConstraintDampingTimeline(frames, frames, index);
case "mass":
timeline = new PhysicsConstraintMassTimeline(frames, frames, index);
case "wind":
timeline = new PhysicsConstraintWindTimeline(frames, frames, index);
case "gravity":
timeline = new PhysicsConstraintGravityTimeline(frames, frames, index);
case "mix":
{
defaultValue = 1;
timeline = new PhysicsConstraintMixTimeline(frames, frames, index);
}
default:
continue;
}
readTimeline(timelines, timelineMap, timeline, defaultValue, 1);
}
@ -1112,18 +1191,22 @@ class SkeletonJson {
var sliders:Dynamic = Reflect.getProperty(map, "slider");
for (sliderName in Reflect.fields(sliders)) {
var constraint = skeletonData.findConstraint(sliderName, SliderData);
if (constraint == null) throw new SpineException("Slider not found: " + sliderName);
if (constraint == null)
throw new SpineException("Slider not found: " + sliderName);
var index = skeletonData.constraints.indexOf(constraint);
var timelineMap:Dynamic = Reflect.field(sliders, sliderName);
for (timelineName in Reflect.fields(timelineMap)) {
timelineMap = Reflect.field(timelineMap, timelineName);
keyMap = timelineMap[0];
if (keyMap == null) continue;
if (keyMap == null)
continue;
var frames = timelineMap.length;
switch (timelineName) {
case "time": readTimeline(timelines, keyMap, new SliderTimeline(frames, frames, index), 1, 1);
case "mix": readTimeline(timelines, keyMap, new SliderMixTimeline(frames, frames, index), 1, 1);
case "time":
readTimeline(timelines, keyMap, new SliderTimeline(frames, frames, index), 1, 1);
case "mix":
readTimeline(timelines, keyMap, new SliderMixTimeline(frames, frames, index), 1, 1);
}
}
}
@ -1344,8 +1427,8 @@ class SkeletonJson {
}
}
static private function readTimeline2(timelines:Array<Timeline>, keys:Array<Dynamic>, timeline:BoneTimeline2, name1:String, name2:String, defaultValue:Float,
scale:Float) {
static private function readTimeline2(timelines:Array<Timeline>, keys:Array<Dynamic>, timeline:BoneTimeline2, name1:String, name2:String,
defaultValue:Float, scale:Float) {
var keyMap:Dynamic = keys[0];
var time:Float = getFloat(keyMap, "time");
var value1:Float = getFloat(keyMap, name1, defaultValue) * scale;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
@ -51,13 +51,15 @@ class Skin {
public final color:Color = new Color(0.99607843, 0.61960787, 0.30980393, 1); // fe9e4fff
public function new(name:String) {
if (name == null) throw new SpineException("name cannot be null.");
if (name == null)
throw new SpineException("name cannot be null.");
this.name = name;
}
/** Adds an attachment to the skin for the specified slot index and name. */
public function setAttachment(slotIndex:Int, name:String, attachment:Attachment):Void {
if (attachment == null) throw new SpineException("attachment cannot be null.");
if (attachment == null)
throw new SpineException("attachment cannot be null.");
if (slotIndex >= attachments.length)
attachments.resize(slotIndex + 1);
if (attachments[slotIndex] == null)
@ -218,7 +220,8 @@ class Skin {
var skinAttachment:Attachment = dictionary.get(name);
if (slotAttachment == skinAttachment) {
var attachment:Attachment = getAttachment(slotIndex, name);
if (attachment != null) slot.attachment = attachment;
if (attachment != null)
slot.attachment = attachment;
break;
}
}

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
@ -34,8 +34,10 @@ import spine.attachments.Attachment;
/** Stores an entry in the skin consisting of the slot index and the attachment name. */
class SkinEntry {
public var slotIndex:Int = 0;
/** The name the attachment is associated with, equivalent to the skin placeholder name in the Spine editor. */
public var name:String;
public var attachment:Attachment;
public function new(slotIndex:Int, name:String, attachment:Attachment) {

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
@ -36,36 +36,40 @@ import spine.animation.MixDirection;
import spine.animation.MixBlend;
/** Stores the setup pose for a {@link PhysicsConstraint}.
* <p>
* See <a href="https://esotericsoftware.com/spine-physics-constraints">Physics constraints</a> in the Spine User Guide. */
* <p>
* See <a href="https://esotericsoftware.com/spine-physics-constraints">Physics constraints</a> in the Spine User Guide. */
class Slider extends Constraint<Slider, SliderData, SliderPose> {
static private final offsets:Array<Float> = [for (i in 0...6) .0];
public var bone:Bone;
public function new (data:SliderData, skeleton:Skeleton) {
public function new(data:SliderData, skeleton:Skeleton) {
super(data, new SliderPose(), new SliderPose());
if (skeleton == null) throw new SpineException("skeleton cannot be null.");
if (skeleton == null)
throw new SpineException("skeleton cannot be null.");
if (data.bone != null) bone = skeleton.bones[data.bone.index];
if (data.bone != null)
bone = skeleton.bones[data.bone.index];
}
public function copy (skeleton:Skeleton) {
public function copy(skeleton:Skeleton) {
var copy = new Slider(data, skeleton);
copy.pose.set(pose);
return copy;
}
public function update (skeleton:Skeleton, physics:Physics) {
public function update(skeleton:Skeleton, physics:Physics) {
var p = applied;
if (p.mix == 0) return;
if (p.mix == 0)
return;
var animation = data.animation;
if (bone != null) {
if (!bone.active) return;
if (data.local) bone.applied.validateLocalTransform(skeleton);
p.time = data.offset
+ (data.property.value(skeleton, bone.applied, data.local, offsets) - data.property.offset) * data.scale;
if (!bone.active)
return;
if (data.local)
bone.applied.validateLocalTransform(skeleton);
p.time = data.offset + (data.property.value(skeleton, bone.applied, data.local, offsets) - data.property.offset) * data.scale;
if (data.loop)
p.time = animation.duration + (p.time % animation.duration);
else
@ -78,12 +82,12 @@ class Slider extends Constraint<Slider, SliderData, SliderPose> {
while (i < n)
bones[indices[i++]].applied.modifyLocal(skeleton);
animation.apply(skeleton, p.time, p.time, data.loop, null, p.mix, data.additive ? MixBlend.add : MixBlend.replace,
MixDirection.mixIn, true);
animation.apply(skeleton, p.time, p.time, data.loop, null, p.mix, data.additive ? MixBlend.add : MixBlend.replace, MixDirection.mixIn, true);
}
function sort (skeleton:Skeleton) {
if (bone != null && !data.local) skeleton.sortBone(bone);
function sort(skeleton:Skeleton) {
if (bone != null && !data.local)
skeleton.sortBone(bone);
skeleton._updateCache.push(this);
var bones = skeleton.bones;

View File

@ -1,5 +1,3 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated April 5, 2025. Replaces all prior versions.
@ -27,16 +25,16 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
package spine;
import spine.TransformConstraintData.FromProperty;
import spine.animation.Animation;
/** Stores the setup pose for a PhysicsConstraint.
*
* See <a href="https://esotericsoftware.com/spine-physics-constraints">Physics constraints</a> in the Spine User Guide. */
*
* See <a href="https://esotericsoftware.com/spine-physics-constraints">Physics constraints</a> in the Spine User Guide. */
class SliderData extends ConstraintData<Slider, SliderPose> {
public var animation:Animation;
public var additive = false;
@ -47,11 +45,11 @@ class SliderData extends ConstraintData<Slider, SliderPose> {
public var offset = 0.;
public var local = false;
public function new (name:String) {
public function new(name:String) {
super(name, new SliderPose());
}
public function create (skeleton:Skeleton) {
public function create(skeleton:Skeleton) {
return new Slider(this, skeleton);
}
}

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
@ -34,11 +34,10 @@ class SliderPose implements Pose<SliderPose> {
public var time = 0.;
public var mix = 0.;
public function new () {
}
public function new() {}
public function set (pose:SliderPose) {
public function set(pose:SliderPose) {
time = pose.time;
mix = pose.mix;
}
}
}

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
@ -36,17 +36,17 @@ import spine.attachments.VertexAttachment;
* state for an attachment. State cannot be stored in an attachment itself because attachments are stateless and may be shared
* across multiple skeletons. */
class Slot extends Posed<SlotData, SlotPose, SlotPose> {
public var skeleton:Skeleton;
/** The bone this slot belongs to. */
public var bone:Bone;
public var attachmentState:Int ;
public var attachmentState:Int;
public function new(data:SlotData, skeleton:Skeleton) {
super(data, new SlotPose(), new SlotPose());
if (skeleton == null) throw new SpineException("skeleton cannot be null.");
if (skeleton == null)
throw new SpineException("skeleton cannot be null.");
this.skeleton = skeleton;
bone = skeleton.bones[data.boneData.index];
if (data.setup.darkColor != null) {
@ -59,8 +59,10 @@ class Slot extends Posed<SlotData, SlotPose, SlotPose> {
/** Copy method. */
public function copy(slot:Slot, bone:Bone, skeleton:Skeleton):Slot {
var copy = new Slot(slot.data, skeleton);
if (bone == null) throw new SpineException("bone cannot be null.");
if (skeleton == null) throw new SpineException("skeleton cannot be null.");
if (bone == null)
throw new SpineException("bone cannot be null.");
if (skeleton == null)
throw new SpineException("skeleton cannot be null.");
this.bone = bone;
if (data.setup.darkColor != null) {
pose.darkColor = new Color(1, 1, 1, 1);
@ -73,7 +75,8 @@ class Slot extends Posed<SlotData, SlotPose, SlotPose> {
/** Sets this slot to the setup pose. */
override public function setupPose():Void {
pose.color.setFromColor(data.setup.color);
if (pose.darkColor != null) pose.darkColor.setFromColor(data.setup.darkColor);
if (pose.darkColor != null)
pose.darkColor.setFromColor(data.setup.darkColor);
pose.sequenceIndex = data.setup.sequenceIndex;
if (data.attachmentName == null) {
pose.attachment = null;

View File

@ -25,13 +25,12 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
/** Stores the setup pose for a spine.Slot. */
class SlotData extends PosedData<SlotPose> {
/** The index of the slot in spine.Skeleton.getSlots(). */
public final index:Int;
@ -45,13 +44,16 @@ class SlotData extends PosedData<SlotPose> {
public var blendMode:BlendMode = BlendMode.normal;
// Nonessential.
/** False if the slot was hidden in Spine and nonessential data was exported. Does not affect runtime rendering. */
public var visible:Bool = true;
public function new(index:Int, name:String, boneData:BoneData) {
super(name, new SlotPose());
if (index < 0) throw new SpineException("index must be >= 0.");
if (boneData == null) throw new SpineException("boneData cannot be null.");
if (index < 0)
throw new SpineException("index must be >= 0.");
if (boneData == null)
throw new SpineException("boneData cannot be null.");
this.index = index;
this.boneData = boneData;
}

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
@ -33,49 +33,52 @@ import spine.attachments.Attachment;
import spine.attachments.VertexAttachment;
/** Stores a slot's pose. Slots organize attachments for {@link Skeleton#drawOrder} purposes and provide a place to store state
* for an attachment. State cannot be stored in an attachment itself because attachments are stateless and may be shared across
* multiple skeletons. */
* for an attachment. State cannot be stored in an attachment itself because attachments are stateless and may be shared across
* multiple skeletons. */
class SlotPose implements Pose<SlotPose> {
/** The color used to tint the slot's attachment. If SlotData.darkColor is set, this is used as the light color for two
* color tinting. */
* color tinting. */
public final color:Color = new Color(1, 1, 1, 1);
/** The dark color used to tint the slot's attachment for two color tinting, or null if two color tinting is not used. The dark
* color's alpha is not used. */
* color's alpha is not used. */
public var darkColor:Color = null;
public var attachment(default, set):Attachment; // Not used in setup pose.
/** The index of the texture region to display when the slot's attachment has a spine.attachments.Sequence. -1 represents the
* Sequence.getSetupIndex(). */
* Sequence.getSetupIndex(). */
public var sequenceIndex = -1;
/** Values to deform the slot's attachment. For an unweighted mesh, the entries are local positions for each vertex. For a
* weighted mesh, the entries are an offset for each vertex which will be added to the mesh's local vertex positions.
* @see spine.attachments.VertexAttachment.computeWorldVertices()
* @see spine.animation.DeformTimeline */
* weighted mesh, the entries are an offset for each vertex which will be added to the mesh's local vertex positions.
* @see spine.attachments.VertexAttachment.computeWorldVertices()
* @see spine.animation.DeformTimeline */
public var deform:Array<Float> = new Array<Float>();
public function new () {
}
public function new() {}
public function set (pose:SlotPose):Void {
if (pose == null) throw new SpineException("pose cannot be null.");
public function set(pose:SlotPose):Void {
if (pose == null)
throw new SpineException("pose cannot be null.");
color.setFromColor(pose.color);
if (darkColor != null) darkColor.setFromColor(pose.darkColor);
if (darkColor != null)
darkColor.setFromColor(pose.darkColor);
attachment = pose.attachment;
sequenceIndex = pose.sequenceIndex;
deform.resize(0);
for (e in pose.deform) deform.push(e);
for (e in pose.deform)
deform.push(e);
}
/** Sets the slot's attachment and, if the attachment changed, resets sequenceIndex and clears the deform.
* The deform is not cleared if the old attachment has the same spine.attachments.VertexAttachment.timelineAttachment as the
* specified attachment. */
* The deform is not cleared if the old attachment has the same spine.attachments.VertexAttachment.timelineAttachment as the
* specified attachment. */
public function set_attachment(attachmentNew:Attachment):Attachment {
if (attachment == attachmentNew) return attachment;
if (!Std.isOfType(attachmentNew, VertexAttachment) || !Std.isOfType(attachment, VertexAttachment)
if (attachment == attachmentNew)
return attachment;
if (!Std.isOfType(attachmentNew, VertexAttachment)
|| !Std.isOfType(attachment, VertexAttachment)
|| cast(attachmentNew, VertexAttachment).timelineAttachment != cast(attachment, VertexAttachment).timelineAttachment) {
deform = new Array<Float>();
}
@ -83,5 +86,4 @@ class SlotPose implements Pose<SlotPose> {
sequenceIndex = -1;
return attachment;
}
}
}

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
@ -34,7 +34,6 @@ package spine;
*
* @see https://esotericsoftware.com/spine-transform-constraints Transform constraints in the Spine User Guide */
class TransformConstraint extends Constraint<TransformConstraint, TransformConstraintData, TransformConstraintPose> {
/** The bones that will be modified by this transform constraint. */
public final bones:Array<BonePose>;
@ -43,7 +42,8 @@ class TransformConstraint extends Constraint<TransformConstraint, TransformConst
public function new(data:TransformConstraintData, skeleton:Skeleton) {
super(data, new TransformConstraintPose(), new TransformConstraintPose());
if (skeleton == null) throw new SpineException("skeleton cannot be null.");
if (skeleton == null)
throw new SpineException("skeleton cannot be null.");
bones = new Array<BonePose>();
for (boneData in data.bones)
@ -60,12 +60,17 @@ class TransformConstraint extends Constraint<TransformConstraint, TransformConst
/** Applies the constraint to the constrained bones. */
public function update(skeleton:Skeleton, physics:Physics):Void {
var p = applied;
if (p.mixRotate == 0 && p.mixX == 0 && p.mixY == 0 && p.mixScaleX == 0 && p.mixScaleY == 0 && p.mixShearY == 0) return;
if (p.mixRotate == 0 && p.mixX == 0 && p.mixY == 0 && p.mixScaleX == 0 && p.mixScaleY == 0 && p.mixShearY == 0)
return;
var localSource = data.localSource, localTarget = data.localTarget, additive = data.additive, clamp = data.clamp;
var localSource = data.localSource,
localTarget = data.localTarget,
additive = data.additive,
clamp = data.clamp;
var offsets = data.offsets;
var source = this.source.applied;
if (localSource) source.validateLocalTransform(skeleton);
if (localSource)
source.validateLocalTransform(skeleton);
var fromItems = data.properties;
var fn = data.properties.length, update = skeleton.update;
var bones = this.bones;
@ -103,8 +108,9 @@ class TransformConstraint extends Constraint<TransformConstraint, TransformConst
}
}
public function sort (skeleton:Skeleton) {
if (!data.localSource) skeleton.sortBone(source);
public function sort(skeleton:Skeleton) {
if (!data.localSource)
skeleton.sortBone(source);
var bones = this.bones;
var boneCount = this.bones.length;
var worldTarget = !data.localTarget;
@ -122,7 +128,7 @@ class TransformConstraint extends Constraint<TransformConstraint, TransformConst
bones[i].bone.sorted = worldTarget;
}
override public function isSourceActive () {
override public function isSourceActive() {
return source.active;
}
}

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
@ -68,99 +68,104 @@ class TransformConstraintData extends ConstraintData<TransformConstraint, Transf
/** An offset added to the constrained bone rotation. */
public var offsetRotation:Float = 0;
/** An offset added to the constrained bone X translation. */
public var offsetX:Float = 0;
/** An offset added to the constrained bone Y translation. */
public var offsetY:Float = 0;
/** An offset added to the constrained bone scaleX. */
public var offsetScaleX:Float = 0;
/** An offset added to the constrained bone scaleY. */
public var offsetScaleY:Float = 0;
/** An offset added to the constrained bone shearY. */
public var offsetShearY:Float = 0;
public var relative:Bool = false;
public var local:Bool = false;
public function new (name:String) {
public function new(name:String) {
super(name, new TransformConstraintPose());
}
public function create (skeleton:Skeleton) {
public function create(skeleton:Skeleton) {
return new TransformConstraint(this, skeleton);
}
public function set_source (source:BoneData):BoneData {
if (source == null) throw new SpineException("source cannot be null.");
public function set_source(source:BoneData):BoneData {
if (source == null)
throw new SpineException("source cannot be null.");
this.source = source;
return source;
}
/** An offset added to the constrained bone rotation. */
public function getOffsetRotation ():Float {
public function getOffsetRotation():Float {
return offsets[TransformConstraintData.ROTATION];
}
public function setOffsetRotation (offsetRotation:Float):Float {
public function setOffsetRotation(offsetRotation:Float):Float {
offsets[TransformConstraintData.ROTATION] = offsetRotation;
return offsetRotation;
}
/** An offset added to the constrained bone X translation. */
public function getOffsetX ():Float {
public function getOffsetX():Float {
return offsets[TransformConstraintData.X];
}
public function setOffsetX (offsetX:Float):Float {
public function setOffsetX(offsetX:Float):Float {
offsets[TransformConstraintData.X] = offsetX;
return offsetX;
}
/** An offset added to the constrained bone Y translation. */
public function getOffsetY ():Float {
public function getOffsetY():Float {
return offsets[TransformConstraintData.Y];
}
public function setOffsetY (offsetY:Float):Float {
public function setOffsetY(offsetY:Float):Float {
offsets[TransformConstraintData.Y] = offsetY;
return offsetY;
}
/** An offset added to the constrained bone scaleX. */
public function getOffsetScaleX ():Float {
public function getOffsetScaleX():Float {
return offsets[TransformConstraintData.SCALEX];
}
public function setOffsetScaleX (offsetScaleX:Float):Float {
public function setOffsetScaleX(offsetScaleX:Float):Float {
offsets[TransformConstraintData.SCALEX] = offsetScaleX;
return offsetScaleX;
}
/** An offset added to the constrained bone scaleY. */
public function getOffsetScaleY ():Float {
public function getOffsetScaleY():Float {
return offsets[TransformConstraintData.SCALEY];
}
public function setOffsetScaleY (offsetScaleY:Float):Float {
public function setOffsetScaleY(offsetScaleY:Float):Float {
offsets[TransformConstraintData.SCALEY] = offsetScaleY;
return offsetScaleY;
}
/** An offset added to the constrained bone shearY. */
public function getOffsetShearY ():Float {
public function getOffsetShearY():Float {
return offsets[TransformConstraintData.SHEARY];
}
public function setOffsetShearY (offsetShearY:Float):Float {
public function setOffsetShearY(offsetShearY:Float):Float {
offsets[TransformConstraintData.SHEARY] = offsetShearY;
return offsetShearY;
}
}
/** Source property for a {@link TransformConstraint}. */
abstract class FromProperty {
public function new () {
}
public function new() {}
/** The value of this property that corresponds to ToProperty.offset. */
public var offset:Float;
@ -169,13 +174,12 @@ abstract class FromProperty {
public final to = new Array<ToProperty>();
/** Reads this property from the specified bone. */
abstract public function value (skeleton:Skeleton, source:BonePose, local:Bool, offsets:Array<Float>):Float;
abstract public function value(skeleton:Skeleton, source:BonePose, local:Bool, offsets:Array<Float>):Float;
}
/** Constrained property for a TransformConstraint. */
abstract class ToProperty {
public function new () {
}
public function new() {}
/** The value of this property that corresponds to FromProperty.offset. */
public var offset:Float;
@ -187,36 +191,43 @@ abstract class ToProperty {
public var scale:Float;
/** Reads the mix for this property from the specified pose. */
abstract public function mix (pose:TransformConstraintPose):Float;
abstract public function mix(pose:TransformConstraintPose):Float;
/** Applies the value to this property. */
abstract public function apply (skeleton:Skeleton, pose:TransformConstraintPose, bone:BonePose, value:Float, local:Bool, additive:Bool):Void;
abstract public function apply(skeleton:Skeleton, pose:TransformConstraintPose, bone:BonePose, value:Float, local:Bool, additive:Bool):Void;
}
class FromRotate extends FromProperty {
public function value (skeleton:Skeleton, source:BonePose, local:Bool, offsets:Array<Float>):Float {
if (local) return source.rotation + offsets[TransformConstraintData.ROTATION];
public function value(skeleton:Skeleton, source:BonePose, local:Bool, offsets:Array<Float>):Float {
if (local)
return source.rotation + offsets[TransformConstraintData.ROTATION];
var sx = skeleton.scaleX, sy = skeleton.scaleY;
var value = Math.atan2(source.c / sy, source.a / sx) * MathUtils.radDeg
+ ((source.a * source.d - source.b * source.c) * sx * sy > 0 ? offsets[TransformConstraintData.ROTATION] : -offsets[TransformConstraintData.ROTATION]);
if (value < 0) value += 360;
+ ((source.a * source.d - source.b * source.c) * sx * sy > 0 ? offsets[TransformConstraintData.ROTATION] :
-offsets[TransformConstraintData.ROTATION]);
if (value < 0)
value += 360;
return value;
}
}
class ToRotate extends ToProperty {
public function mix (pose:TransformConstraintPose):Float {
public function mix(pose:TransformConstraintPose):Float {
return pose.mixRotate;
}
public function apply (skeleton:Skeleton, pose:TransformConstraintPose, bone:BonePose, value:Float, local:Bool, additive:Bool):Void {
public function apply(skeleton:Skeleton, pose:TransformConstraintPose, bone:BonePose, value:Float, local:Bool, additive:Bool):Void {
if (local)
bone.rotation += (additive ? value : value - bone.rotation) * pose.mixRotate;
else {
var sx = skeleton.scaleX, sy = skeleton.scaleY, ix = 1 / sx, iy = 1 / sy;
var a = bone.a * ix, b = bone.b * ix, c = bone.c * iy, d = bone.d * iy;
var a = bone.a * ix,
b = bone.b * ix,
c = bone.c * iy,
d = bone.d * iy;
value *= MathUtils.degRad;
if (!additive) value -= Math.atan2(c, a);
if (!additive)
value -= Math.atan2(c, a);
if (value > MathUtils.PI)
value -= MathUtils.PI2;
else if (value < -MathUtils.PI) //
@ -232,65 +243,66 @@ class ToRotate extends ToProperty {
}
class FromX extends FromProperty {
public function value (skeleton:Skeleton, source:BonePose, local:Bool, offsets:Array<Float>):Float {
return local
? source.x + offsets[TransformConstraintData.X]
: (offsets[TransformConstraintData.X] * source.a + offsets[TransformConstraintData.Y] * source.b + source.worldX) / skeleton.scaleX;
public function value(skeleton:Skeleton, source:BonePose, local:Bool, offsets:Array<Float>):Float {
return local ? source.x + offsets[TransformConstraintData.X] : (offsets[TransformConstraintData.X] * source.a
+ offsets[TransformConstraintData.Y] * source.b + source.worldX) / skeleton.scaleX;
}
}
class ToX extends ToProperty {
public function mix (pose:TransformConstraintPose):Float {
public function mix(pose:TransformConstraintPose):Float {
return pose.mixX;
}
public function apply (skeleton:Skeleton, pose:TransformConstraintPose, bone:BonePose, value:Float, local:Bool, additive:Bool):Void {
public function apply(skeleton:Skeleton, pose:TransformConstraintPose, bone:BonePose, value:Float, local:Bool, additive:Bool):Void {
if (local)
bone.x += (additive ? value : value - bone.x) * pose.mixX;
else {
if (!additive) value -= bone.worldX / skeleton.scaleX;
if (!additive)
value -= bone.worldX / skeleton.scaleX;
bone.worldX += value * pose.mixX * skeleton.scaleX;
}
}
}
class FromY extends FromProperty {
public function value (skeleton:Skeleton, source:BonePose, local:Bool, offsets:Array<Float>):Float {
return local
? source.y + offsets[TransformConstraintData.Y]
: (offsets[TransformConstraintData.X] * source.c + offsets[TransformConstraintData.Y] * source.d + source.worldY) / skeleton.scaleY;
public function value(skeleton:Skeleton, source:BonePose, local:Bool, offsets:Array<Float>):Float {
return local ? source.y + offsets[TransformConstraintData.Y] : (offsets[TransformConstraintData.X] * source.c
+ offsets[TransformConstraintData.Y] * source.d + source.worldY) / skeleton.scaleY;
}
}
class ToY extends ToProperty {
public function mix (pose:TransformConstraintPose):Float {
public function mix(pose:TransformConstraintPose):Float {
return pose.mixY;
}
public function apply (skeleton:Skeleton, pose:TransformConstraintPose, bone:BonePose, value:Float, local:Bool, additive:Bool):Void {
public function apply(skeleton:Skeleton, pose:TransformConstraintPose, bone:BonePose, value:Float, local:Bool, additive:Bool):Void {
if (local)
bone.y += (additive ? value : value - bone.y) * pose.mixY;
else {
if (!additive) value -= bone.worldY / skeleton.scaleY;
if (!additive)
value -= bone.worldY / skeleton.scaleY;
bone.worldY += value * pose.mixY * skeleton.scaleY;
}
}
}
class FromScaleX extends FromProperty {
public function value (skeleton:Skeleton, source:BonePose, local:Bool, offsets:Array<Float>):Float {
if (local) return source.scaleX + offsets[TransformConstraintData.SCALEX];
public function value(skeleton:Skeleton, source:BonePose, local:Bool, offsets:Array<Float>):Float {
if (local)
return source.scaleX + offsets[TransformConstraintData.SCALEX];
var a = source.a / skeleton.scaleX, c = source.c / skeleton.scaleY;
return Math.sqrt(a * a + c * c) + offsets[TransformConstraintData.SCALEX];
}
}
class ToScaleX extends ToProperty {
public function mix (pose:TransformConstraintPose):Float {
public function mix(pose:TransformConstraintPose):Float {
return pose.mixScaleX;
}
public function apply (skeleton:Skeleton, pose:TransformConstraintPose, bone:BonePose, value:Float, local:Bool, additive:Bool):Void {
public function apply(skeleton:Skeleton, pose:TransformConstraintPose, bone:BonePose, value:Float, local:Bool, additive:Bool):Void {
if (local) {
if (additive)
bone.scaleX *= 1 + (value - 1) * pose.mixScaleX;
@ -301,7 +313,9 @@ class ToScaleX extends ToProperty {
bone.a *= s;
bone.c *= s;
} else {
var a = bone.a / skeleton.scaleX, c = bone.c / skeleton.scaleY, s = Math.sqrt(a * a + c * c);
var a = bone.a / skeleton.scaleX,
c = bone.c / skeleton.scaleY,
s = Math.sqrt(a * a + c * c);
if (s != 0) {
s = 1 + (value - s) * pose.mixScaleX / s;
bone.a *= s;
@ -312,19 +326,20 @@ class ToScaleX extends ToProperty {
}
class FromScaleY extends FromProperty {
public function value (skeleton:Skeleton, source:BonePose, local:Bool, offsets:Array<Float>):Float {
if (local) return source.scaleY + offsets[TransformConstraintData.SCALEY];
public function value(skeleton:Skeleton, source:BonePose, local:Bool, offsets:Array<Float>):Float {
if (local)
return source.scaleY + offsets[TransformConstraintData.SCALEY];
var b = source.b / skeleton.scaleX, d = source.d / skeleton.scaleY;
return Math.sqrt(b * b + d * d) + offsets[TransformConstraintData.SCALEY];
}
}
class ToScaleY extends ToProperty {
public function mix (pose:TransformConstraintPose):Float {
public function mix(pose:TransformConstraintPose):Float {
return pose.mixScaleY;
}
public function apply (skeleton:Skeleton, pose:TransformConstraintPose, bone:BonePose, value:Float, local:Bool, additive:Bool):Void {
public function apply(skeleton:Skeleton, pose:TransformConstraintPose, bone:BonePose, value:Float, local:Bool, additive:Bool):Void {
if (local) {
if (additive)
bone.scaleY *= 1 + (value - 1) * pose.mixScaleY;
@ -335,7 +350,9 @@ class ToScaleY extends ToProperty {
bone.b *= s;
bone.d *= s;
} else {
var b = bone.b / skeleton.scaleX, d = bone.d / skeleton.scaleY, s = Math.sqrt(b * b + d * d);
var b = bone.b / skeleton.scaleX,
d = bone.d / skeleton.scaleY,
s = Math.sqrt(b * b + d * d);
if (s != 0) {
s = 1 + (value - s) * pose.mixScaleY / s;
bone.b *= s;
@ -346,25 +363,33 @@ class ToScaleY extends ToProperty {
}
class FromShearY extends FromProperty {
public function value (skeleton:Skeleton, source:BonePose, local:Bool, offsets:Array<Float>):Float {
if (local) return source.shearY + offsets[TransformConstraintData.SHEARY];
public function value(skeleton:Skeleton, source:BonePose, local:Bool, offsets:Array<Float>):Float {
if (local)
return source.shearY + offsets[TransformConstraintData.SHEARY];
var sx = 1 / skeleton.scaleX, sy = 1 / skeleton.scaleY;
return (Math.atan2(source.d * sy, source.b * sx) - Math.atan2(source.c * sy, source.a * sx))
* MathUtils.radDeg - 90 + offsets[TransformConstraintData.SHEARY];
return (Math.atan2(source.d * sy, source.b * sx)
- Math.atan2(source.c * sy, source.a * sx)) * MathUtils.radDeg
- 90
+ offsets[TransformConstraintData.SHEARY];
}
}
class ToShearY extends ToProperty {
public function mix (pose:TransformConstraintPose):Float {
public function mix(pose:TransformConstraintPose):Float {
return pose.mixShearY;
}
public function apply (skeleton:Skeleton, pose:TransformConstraintPose, bone:BonePose, value:Float, local:Bool, additive:Bool):Void {
public function apply(skeleton:Skeleton, pose:TransformConstraintPose, bone:BonePose, value:Float, local:Bool, additive:Bool):Void {
if (local) {
if (!additive) value -= bone.shearY;
if (!additive)
value -= bone.shearY;
bone.shearY += value * pose.mixShearY;
} else {
var sx = skeleton.scaleX, sy = skeleton.scaleY, b = bone.b / sx, d = bone.d / sy, by = Math.atan2(d, b);
var sx = skeleton.scaleX,
sy = skeleton.scaleY,
b = bone.b / sx,
d = bone.d / sy,
by = Math.atan2(d, b);
value = (value + 90) * MathUtils.degRad;
if (additive)
value -= MathUtils.PI / 2;

View File

@ -25,35 +25,33 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;
/** Stores a pose for a transform constraint. */
class TransformConstraintPose implements Pose<TransformConstraintPose> {
/** A percentage (0-1) that controls the mix between the constrained and unconstrained rotation. */
public var mixRotate = 0.;
/** A percentage (0-1) that controls the mix between the constrained and unconstrained translation X. */
public var mixX = 0.;
/** A percentage (0-1) that controls the mix between the constrained and unconstrained translation Y. */
public var mixY = 0.;
/** A percentage (0-1) that controls the mix between the constrained and unconstrained scale X. */
public var mixScaleX = 0.;
/** A percentage (0-1) that controls the mix between the constrained and unconstrained scale Y. */
public var mixScaleY = 0.;
/** A percentage (0-1) that controls the mix between the constrained and unconstrained shear Y. */
/** A percentage (0-1) that controls the mix between the constrained and unconstrained shear Y. */
public var mixShearY = 0.;
public function new () {
}
public function new() {}
public function set (pose:TransformConstraintPose) {
public function set(pose:TransformConstraintPose) {
mixRotate = pose.mixRotate;
mixX = pose.mixX;
mixY = pose.mixY;
@ -61,5 +59,4 @@ class TransformConstraintPose implements Pose<TransformConstraintPose> {
mixScaleY = pose.mixScaleY;
mixShearY = pose.mixShearY;
}
}
}

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine.animation;
@ -55,11 +55,11 @@ class AlphaTimeline extends CurveTimeline1 implements SlotTimeline {
return slotIndex;
}
public function apply(skeleton:Skeleton, lastTime:Float, time:Float, events:Array<Event>, alpha:Float,
blend:MixBlend, direction:MixDirection, appliedPose:Bool) {
public function apply(skeleton:Skeleton, lastTime:Float, time:Float, events:Array<Event>, alpha:Float, blend:MixBlend, direction:MixDirection,
appliedPose:Bool) {
var slot = skeleton.slots[slotIndex];
if (!slot.bone.active) return;
if (!slot.bone.active)
return;
var color = (appliedPose ? slot.applied : slot.pose).color;
if (time < frames[0]) {

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine.animation;
@ -36,12 +36,11 @@ import spine.Skeleton;
/** Stores a list of timelines to animate a skeleton's pose over time. */
class Animation {
/** The animation's name, which is unique across all animations in the skeleton. */
public final name:String;
/** The duration of the animation in seconds, which is usually the highest time of all frames in the timeline. The duration is
* used to know when it has completed and when it should loop back to the start. */
* used to know when it has completed and when it should loop back to the start. */
public var duration:Float = 0;
public var timelines:Array<Timeline>;
@ -49,7 +48,8 @@ class Animation {
public final bones:Array<Int>;
public function new(name:String, timelines:Array<Timeline>, duration:Float) {
if (name == null) throw new SpineException("name cannot be null.");
if (name == null)
throw new SpineException("name cannot be null.");
this.name = name;
this.duration = duration;
var n = timelines.length << 1;
@ -59,7 +59,8 @@ class Animation {
}
public function setTimelines(timelines:Array<Timeline>) {
if (timelines == null) throw new SpineException("timelines cannot be null.");
if (timelines == null)
throw new SpineException("timelines cannot be null.");
this.timelines = timelines;
timelineIds.clear();
@ -67,7 +68,8 @@ class Animation {
var boneSet = new IntMap<Bool>();
for (timeline in timelines) {
var ids:Array<String> = timeline.propertyIds;
for (id in ids) timelineIds.set(id, true);
for (id in ids)
timelineIds.set(id, true);
if (Std.isOfType(timeline, BoneTimeline)) {
var boneTimeline = cast(timeline, BoneTimeline);
var boneIndex = boneTimeline.getBoneIndex();
@ -108,13 +110,15 @@ class Animation {
* @param blend Controls how mixing is applied when alpha < 1.
* @param direction Indicates whether the timelines are mixing in or out. Used by timelines which perform instant transitions,
* such as DrawOrderTimeline or AttachmentTimeline. */
public function apply(skeleton:Skeleton, lastTime:Float, time:Float, loop:Bool, events:Array<Event>, alpha:Float, blend:MixBlend,
direction:MixDirection, appliedPose:Bool):Void {
if (skeleton == null) throw new SpineException("skeleton cannot be null.");
public function apply(skeleton:Skeleton, lastTime:Float, time:Float, loop:Bool, events:Array<Event>, alpha:Float, blend:MixBlend, direction:MixDirection,
appliedPose:Bool):Void {
if (skeleton == null)
throw new SpineException("skeleton cannot be null.");
if (loop && duration != 0) {
time %= duration;
if (lastTime > 0) lastTime %= duration;
if (lastTime > 0)
lastTime %= duration;
}
for (timeline in timelines) {

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine.animation;
@ -47,12 +47,14 @@ class AnimationState {
* Result: Mix from the current pose to the timeline pose.
*/
public static inline var SUBSEQUENT:Int = 0;
/**
* 1) This is the first timeline to set this property.
* 2) The next track entry applied after this one does not have a timeline to set this property.
* Result: Mix from the setup pose to the timeline pose.
*/
public static inline var FIRST:Int = 1;
/**
* 1) A previously applied timeline has set this property.
* 2) The next track entry to be applied does have a timeline to set this property.
@ -61,6 +63,7 @@ class AnimationState {
* animations that key the same property. A subsequent timeline will set this property using a mix.
*/
public static inline var HOLD_SUBSEQUENT:Int = 2;
/**
* 1) This is the first timeline to set this property.
* 2) The next track entry to be applied does have a timeline to set this property.
@ -69,6 +72,7 @@ class AnimationState {
* that key the same property. A subsequent timeline will set this property using a mix.
*/
public static inline var HOLD_FIRST:Int = 3;
/**
* 1) This is the first timeline to set this property.
* 2) The next track entry to be applied does have a timeline to set this property.
@ -82,6 +86,7 @@ class AnimationState {
* out position.
*/
public static inline var HOLD_MIX:Int = 4;
public static inline var SETUP:Int = 1;
public static inline var CURRENT:Int = 2;
@ -203,7 +208,8 @@ class AnimationState {
// Mixing is complete for all entries before the from entry or the mix is instantaneous.
if (from.totalAlpha == 0 || to.mixDuration == 0) {
to.mixingFrom = from.mixingFrom;
if (from.mixingFrom != null) from.mixingFrom.mixingTo = to;
if (from.mixingFrom != null)
from.mixingFrom.mixingTo = to;
to.interruptAlpha = from.interruptAlpha;
queue.end(from);
}
@ -256,7 +262,8 @@ class AnimationState {
var timelineCount:Int = timelines.length;
var timeline:Timeline;
if ((i == 0 && alpha == 1) || blend == MixBlend.add) {
if (i == 0) attachments = true;
if (i == 0)
attachments = true;
for (timeline in timelines) {
if (Std.isOfType(timeline, AttachmentTimeline)) {
applyAttachmentTimeline(cast(timeline, AttachmentTimeline), skeleton, applyTime, blend, attachments);
@ -276,8 +283,8 @@ class AnimationState {
var timeline:Timeline = timelines[ii];
var timelineBlend:MixBlend = timelineMode[ii] == SUBSEQUENT ? blend : MixBlend.setup;
if (!shortestRotation && Std.isOfType(timeline, RotateTimeline)) {
this.applyRotateTimeline(cast(timeline, RotateTimeline), skeleton, applyTime, alpha, timelineBlend, current.timelinesRotation, ii << 1,
firstFrame);
this.applyRotateTimeline(cast(timeline, RotateTimeline), skeleton, applyTime, alpha, timelineBlend, current.timelinesRotation,
ii << 1, firstFrame);
} else if (Std.isOfType(timeline, AttachmentTimeline)) {
this.applyAttachmentTimeline(cast(timeline, AttachmentTimeline), skeleton, applyTime, blend, attachments);
} else {
@ -387,7 +394,8 @@ class AnimationState {
if (!shortestRotation && Std.isOfType(timeline, RotateTimeline)) {
applyRotateTimeline(cast(timeline, RotateTimeline), skeleton, applyTime, alpha, timelineBlend, from.timelinesRotation, i << 1, firstFrame);
} else if (Std.isOfType(timeline, AttachmentTimeline)) {
applyAttachmentTimeline(cast(timeline, AttachmentTimeline), skeleton, applyTime, timelineBlend, attachments && alpha >= from.alphaAttachmentThreshold);
applyAttachmentTimeline(cast(timeline, AttachmentTimeline), skeleton, applyTime,
timelineBlend, attachments && alpha >= from.alphaAttachmentThreshold);
} else {
if (drawOrder && Std.isOfType(timeline, DrawOrderTimeline) && timelineBlend == MixBlend.setup)
direction = MixDirection.mixIn;
@ -534,7 +542,8 @@ class AnimationState {
}
} else
complete = animationTime >= animationEnd && entry.animationLast < animationEnd;
if (complete) queue.complete(entry);
if (complete)
queue.complete(entry);
// Queue events after complete.
while (i < n) {
@ -699,11 +708,13 @@ class AnimationState {
if (last == null) {
setCurrent(trackIndex, entry, true);
queue.drain();
if (delay < 0) delay = 0;
if (delay < 0)
delay = 0;
} else {
last.next = entry;
entry.previous = last;
if (delay <= 0) delay = Math.max(delay + last.getTrackComplete() - entry.mixDuration, 0);
if (delay <= 0)
delay = Math.max(delay + last.getTrackComplete() - entry.mixDuration, 0);
}
entry.delay = delay;
@ -753,7 +764,8 @@ class AnimationState {
*/
public function addEmptyAnimation(trackIndex:Int, mixDuration:Float, delay:Float):TrackEntry {
var entry:TrackEntry = addAnimation(trackIndex, emptyAnimation, false, delay);
if (delay <= 0) entry.delay = Math.max(entry.delay + entry.mixDuration - mixDuration, 0);
if (delay <= 0)
entry.delay = Math.max(entry.delay + entry.mixDuration - mixDuration, 0);
entry.mixDuration = mixDuration;
entry.trackEnd = mixDuration;
return entry;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine.animation;

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine.animation;
@ -63,17 +63,19 @@ class AttachmentTimeline extends Timeline implements SlotTimeline {
attachmentNames[frame] = attachmentName;
}
public function apply(skeleton:Skeleton, lastTime:Float, time:Float, events:Array<Event>, alpha:Float,
blend:MixBlend, direction:MixDirection, appliedPose:Bool) {
public function apply(skeleton:Skeleton, lastTime:Float, time:Float, events:Array<Event>, alpha:Float, blend:MixBlend, direction:MixDirection,
appliedPose:Bool) {
var slot = skeleton.slots[slotIndex];
if (!slot.bone.active) return;
if (!slot.bone.active)
return;
var pose = appliedPose ? slot.applied : slot.pose;
if (direction == MixDirection.mixOut) {
if (blend == MixBlend.setup) setAttachment(skeleton, pose, slot.data.attachmentName);
if (blend == MixBlend.setup)
setAttachment(skeleton, pose, slot.data.attachmentName);
} else if (time < frames[0]) {
if (blend == MixBlend.setup || blend == MixBlend.first) setAttachment(skeleton, pose, slot.data.attachmentName);
if (blend == MixBlend.setup || blend == MixBlend.first)
setAttachment(skeleton, pose, slot.data.attachmentName);
} else
setAttachment(skeleton, pose, attachmentNames[Timeline.search1(frames, time)]);
}

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine.animation;

View File

@ -25,11 +25,11 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine.animation;
package spine.animation;
abstract class BoneTimeline1 extends CurveTimeline1 implements BoneTimeline {
abstract class BoneTimeline1 extends CurveTimeline1 implements BoneTimeline {
public final boneIndex:Int;
public function new(frameCount:Int, bezierCount:Int, boneIndex:Int, property:Property) {
@ -37,16 +37,16 @@
this.boneIndex = boneIndex;
}
public function getBoneIndex () {
public function getBoneIndex() {
return boneIndex;
}
public function apply (skeleton: Skeleton, lastTime:Float, time:Float, events:Array<Event>, alpha:Float, blend:MixBlend,
direction:MixDirection, appliedPose:Bool) {
public function apply(skeleton:Skeleton, lastTime:Float, time:Float, events:Array<Event>, alpha:Float, blend:MixBlend, direction:MixDirection,
appliedPose:Bool) {
var bone = skeleton.bones[boneIndex];
if (bone.active) apply1(appliedPose ? bone.applied : bone.pose, bone.data.setup, time, alpha, blend, direction);
if (bone.active)
apply1(appliedPose ? bone.applied : bone.pose, bone.data.setup, time, alpha, blend, direction);
}
abstract function apply1 (pose:BoneLocal, setup:BoneLocal, time:Float, alpha:Float, blend:MixBlend, direction:MixDirection):Void;
abstract function apply1(pose:BoneLocal, setup:BoneLocal, time:Float, alpha:Float, blend:MixBlend, direction:MixDirection):Void;
}

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine.animation;
@ -57,16 +57,16 @@ abstract class BoneTimeline2 extends CurveTimeline implements BoneTimeline {
frames[frame + VALUE2] = value2;
}
public function getBoneIndex () {
public function getBoneIndex() {
return boneIndex;
}
public function apply (skeleton: Skeleton, lastTime:Float, time:Float, events:Array<Event>, alpha:Float, blend:MixBlend,
direction:MixDirection, appliedPose:Bool) {
public function apply(skeleton:Skeleton, lastTime:Float, time:Float, events:Array<Event>, alpha:Float, blend:MixBlend, direction:MixDirection,
appliedPose:Bool) {
var bone = skeleton.bones[boneIndex];
if (bone.active) apply1(appliedPose ? bone.applied : bone.pose, bone.data.setup, time, alpha, blend, direction);
if (bone.active)
apply1(appliedPose ? bone.applied : bone.pose, bone.data.setup, time, alpha, blend, direction);
}
abstract function apply1 (pose:BoneLocal, setup:BoneLocal, time:Float, alpha:Float, blend:MixBlend, direction:MixDirection):Void;
abstract function apply1(pose:BoneLocal, setup:BoneLocal, time:Float, alpha:Float, blend:MixBlend, direction:MixDirection):Void;
}

View File

@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
*****************************************************************************/
package spine.animation;

Some files were not shown because too many files have changed in this diff Show More