mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-10 09:08:42 +08:00
[haxe][starling] SkeletonSprite scale is connected to skeleton scale.
This commit is contained in:
parent
5990697d6e
commit
d29eb5fa99
@ -31,7 +31,6 @@ package flixelExamples;
|
||||
|
||||
import flixel.text.FlxText;
|
||||
import flixel.math.FlxPoint;
|
||||
import spine.Skin;
|
||||
import flixel.ui.FlxButton;
|
||||
import flixel.FlxG;
|
||||
import spine.flixel.SkeletonSprite;
|
||||
|
||||
@ -29,7 +29,6 @@
|
||||
|
||||
package flixelExamples;
|
||||
|
||||
import spine.Skin;
|
||||
import flixel.ui.FlxButton;
|
||||
import flixel.FlxG;
|
||||
import spine.flixel.SkeletonSprite;
|
||||
|
||||
@ -29,7 +29,6 @@
|
||||
|
||||
package flixelExamples;
|
||||
|
||||
import spine.Skin;
|
||||
import flixel.ui.FlxButton;
|
||||
import flixel.FlxG;
|
||||
import spine.flixel.SkeletonSprite;
|
||||
|
||||
@ -29,7 +29,6 @@
|
||||
|
||||
package flixelExamples;
|
||||
|
||||
import spine.Skin;
|
||||
import flixel.ui.FlxButton;
|
||||
import flixel.FlxG;
|
||||
import spine.flixel.SkeletonSprite;
|
||||
|
||||
@ -29,7 +29,6 @@
|
||||
|
||||
package flixelExamples;
|
||||
|
||||
import spine.Skin;
|
||||
import flixel.ui.FlxButton;
|
||||
import flixel.FlxG;
|
||||
import spine.flixel.SkeletonSprite;
|
||||
|
||||
@ -29,7 +29,6 @@
|
||||
|
||||
package flixelExamples;
|
||||
|
||||
import spine.Skin;
|
||||
import flixel.ui.FlxButton;
|
||||
import flixel.FlxG;
|
||||
import spine.flixel.SkeletonSprite;
|
||||
|
||||
@ -29,6 +29,7 @@
|
||||
|
||||
package starlingExamples;
|
||||
|
||||
import spine.boundsprovider.SkinsAndAnimationBoundsProvider;
|
||||
import starlingExamples.Scene.SceneManager;
|
||||
import openfl.utils.Assets;
|
||||
import spine.SkeletonData;
|
||||
@ -49,11 +50,12 @@ class BasicExample extends Scene {
|
||||
var animationStateData = new AnimationStateData(skeletondata);
|
||||
animationStateData.defaultMix = 0.25;
|
||||
|
||||
var skeletonSprite = new SkeletonSprite(skeletondata, animationStateData);
|
||||
var bounds = skeletonSprite.skeleton.getBounds();
|
||||
skeletonSprite.scale = Starling.current.stage.stageWidth / bounds.width * 0.5;
|
||||
var skeletonSprite = new SkeletonSprite(skeletondata, animationStateData, new SkinsAndAnimationBoundsProvider("walk"));
|
||||
var bounds = skeletonSprite.bounds;
|
||||
skeletonSprite.scale = Starling.current.stage.stageWidth * .8 / bounds.width;
|
||||
|
||||
skeletonSprite.x = Starling.current.stage.stageWidth / 2;
|
||||
skeletonSprite.y = Starling.current.stage.stageHeight * 0.9;
|
||||
skeletonSprite.y = Starling.current.stage.stageHeight * 0.95;
|
||||
|
||||
skeletonSprite.state.setAnimationByName(0, "walk", true);
|
||||
|
||||
|
||||
@ -29,7 +29,6 @@
|
||||
|
||||
package starlingExamples;
|
||||
|
||||
import spine.BlendMode;
|
||||
import starlingExamples.Scene.SceneManager;
|
||||
import openfl.utils.Assets;
|
||||
import spine.SkeletonData;
|
||||
@ -60,8 +59,6 @@ class CelestialCircusExample extends Scene {
|
||||
|
||||
skeletonSprite = new SkeletonSprite(skeletondata, animationStateData);
|
||||
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 / 1.5;
|
||||
@ -84,7 +81,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, movement.y);
|
||||
}
|
||||
} else {
|
||||
var sceneTouch = e.getTouch(this);
|
||||
|
||||
@ -55,7 +55,6 @@ class CloudPotExample extends Scene {
|
||||
|
||||
var skeletonSprite = new SkeletonSprite(skeletondata, animationStateData);
|
||||
skeletonSprite.skeleton.updateWorldTransform(Physics.update);
|
||||
var bounds = skeletonSprite.skeleton.getBounds();
|
||||
|
||||
skeletonSprite.scale = 0.2;
|
||||
skeletonSprite.x = Starling.current.stage.stageWidth / 2;
|
||||
|
||||
@ -59,7 +59,7 @@ class ControlBonesExample extends Scene {
|
||||
|
||||
skeletonSprite = new SkeletonSprite(skeletondata, animationStateData);
|
||||
|
||||
var bounds = skeletonSprite.skeleton.getBounds();
|
||||
var bounds = skeletonSprite.bounds;
|
||||
skeletonSprite.scale = Starling.current.stage.stageWidth / bounds.width * 0.25;
|
||||
skeletonSprite.x = Starling.current.stage.stageWidth / 2;
|
||||
skeletonSprite.y = Starling.current.stage.stageHeight * 0.9;
|
||||
@ -79,6 +79,7 @@ class ControlBonesExample extends Scene {
|
||||
"front-leg-ik-target",
|
||||
];
|
||||
|
||||
skeletonSprite.advanceTime(0);
|
||||
for (boneName in controlBoneNames) {
|
||||
var bone = skeletonSprite.skeleton.findBone(boneName);
|
||||
var point = [bone.applied.worldX, bone.applied.worldY];
|
||||
|
||||
@ -29,7 +29,6 @@
|
||||
|
||||
package starlingExamples;
|
||||
|
||||
import spine.animation.TrackEntry;
|
||||
import starlingExamples.Scene.SceneManager;
|
||||
import openfl.utils.Assets;
|
||||
import spine.SkeletonData;
|
||||
|
||||
@ -29,6 +29,7 @@
|
||||
|
||||
package starlingExamples;
|
||||
|
||||
import spine.boundsprovider.SkinsAndAnimationBoundsProvider;
|
||||
import spine.Skin;
|
||||
import starlingExamples.Scene.SceneManager;
|
||||
import openfl.utils.Assets;
|
||||
@ -50,7 +51,7 @@ class MixAndMatchExample extends Scene {
|
||||
var animationStateData = new AnimationStateData(data);
|
||||
animationStateData.defaultMix = 0.25;
|
||||
|
||||
var skeletonSprite = new SkeletonSprite(data, animationStateData);
|
||||
var skeletonSprite = new SkeletonSprite(data, animationStateData, new SkinsAndAnimationBoundsProvider("dance", ["full-skins/boy"]));
|
||||
var customSkin = new Skin("custom");
|
||||
var skinBase = data.findSkin("skin-base");
|
||||
customSkin.addSkin(skinBase);
|
||||
@ -64,7 +65,7 @@ class MixAndMatchExample extends Scene {
|
||||
customSkin.addSkin(data.findSkin("accessories/hat-red-yellow"));
|
||||
skeletonSprite.skeleton.skin = customSkin;
|
||||
|
||||
var bounds = skeletonSprite.skeleton.getBounds();
|
||||
var bounds = skeletonSprite.bounds;
|
||||
skeletonSprite.scale = Starling.current.stage.stageHeight / bounds.height * 0.5;
|
||||
skeletonSprite.x = Starling.current.stage.stageWidth / 2;
|
||||
skeletonSprite.y = Starling.current.stage.stageHeight * 0.9;
|
||||
|
||||
@ -50,7 +50,7 @@ class SequenceExample extends Scene {
|
||||
animationStateData.defaultMix = 0.25;
|
||||
|
||||
var skeletonSprite = new SkeletonSprite(skeletondata, animationStateData);
|
||||
var bounds = skeletonSprite.skeleton.getBounds();
|
||||
var bounds = skeletonSprite.bounds;
|
||||
skeletonSprite.scale = Starling.current.stage.stageWidth / bounds.width * 0.5;
|
||||
skeletonSprite.x = Starling.current.stage.stageWidth / 2;
|
||||
skeletonSprite.y = Starling.current.stage.stageHeight * 0.5;
|
||||
|
||||
@ -55,7 +55,6 @@ class SnowglobeExample extends Scene {
|
||||
|
||||
var skeletonSprite = new SkeletonSprite(skeletondata, animationStateData);
|
||||
skeletonSprite.skeleton.updateWorldTransform(Physics.update);
|
||||
var bounds = skeletonSprite.skeleton.getBounds();
|
||||
|
||||
skeletonSprite.scale = 0.15;
|
||||
skeletonSprite.x = Starling.current.stage.stageWidth / 2;
|
||||
|
||||
@ -51,7 +51,7 @@ class TankExample extends Scene {
|
||||
animationStateData.defaultMix = 0.25;
|
||||
|
||||
var skeletonSprite = new SkeletonSprite(skeletondata, animationStateData);
|
||||
var bounds = skeletonSprite.skeleton.getBounds();
|
||||
var bounds = skeletonSprite.bounds;
|
||||
skeletonSprite.scale = Starling.current.stage.stageWidth / bounds.width;
|
||||
skeletonSprite.x = Starling.current.stage.stageWidth / 2;
|
||||
skeletonSprite.y = Starling.current.stage.stageHeight * 0.5;
|
||||
|
||||
@ -1,79 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated April 5, 2025. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2025, Esoteric Software LLC
|
||||
*
|
||||
* Integration of the Spine Runtimes into software or otherwise creating
|
||||
* derivative works of the Spine Runtimes is permitted under the terms and
|
||||
* conditions of Section 2 of the Spine Editor License Agreement:
|
||||
* http://esotericsoftware.com/spine-editor-license
|
||||
*
|
||||
* Otherwise, it is permitted to integrate the Spine Runtimes into software
|
||||
* or otherwise create derivative works of the Spine Runtimes (collectively,
|
||||
* "Products"), provided that each user of the Products must obtain their own
|
||||
* Spine Editor license and redistribution of the Products in any form must
|
||||
* include this license and copyright notice.
|
||||
*
|
||||
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
|
||||
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
|
||||
* 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;
|
||||
|
||||
import starlingExamples.Scene.SceneManager;
|
||||
import openfl.utils.Assets;
|
||||
import spine.SkeletonData;
|
||||
import spine.animation.AnimationStateData;
|
||||
import spine.atlas.TextureAtlas;
|
||||
import spine.starling.SkeletonSprite;
|
||||
import spine.starling.StarlingTextureLoader;
|
||||
import starling.core.Starling;
|
||||
import starling.events.TouchEvent;
|
||||
import starling.events.TouchPhase;
|
||||
|
||||
class Test extends Scene {
|
||||
var loadBinary = true;
|
||||
|
||||
public function load():Void {
|
||||
background.color = 0xaaaaaaff;
|
||||
|
||||
var atlas = new TextureAtlas(Assets.getText("assets/avatar.spine_atlas"), new StarlingTextureLoader("assets/avatar.spine_atlas"));
|
||||
var skeletondata = SkeletonData.from(loadBinary ? Assets.getBytes("assets/avatar.skel") : Assets.getText("assets/avatar.json"), atlas);
|
||||
var animationStateData = new AnimationStateData(skeletondata);
|
||||
animationStateData.defaultMix = 0.25;
|
||||
|
||||
var skeletonSprite = new SkeletonSprite(skeletondata, animationStateData);
|
||||
var bounds = skeletonSprite.skeleton.getBounds();
|
||||
skeletonSprite.scale = Starling.current.stage.stageWidth / bounds.width * 0.2;
|
||||
skeletonSprite.x = Starling.current.stage.stageWidth / 2;
|
||||
skeletonSprite.y = Starling.current.stage.stageHeight * 0.9;
|
||||
|
||||
for (i in 0...skeletondata.animations.length) {
|
||||
skeletonSprite.state.addAnimation(0, skeletondata.animations[i], false, 0);
|
||||
}
|
||||
|
||||
addChild(skeletonSprite);
|
||||
juggler.add(skeletonSprite);
|
||||
|
||||
addText("Click anywhere for next scene");
|
||||
|
||||
addEventListener(TouchEvent.TOUCH, onTouch);
|
||||
}
|
||||
|
||||
public function onTouch(e:TouchEvent) {
|
||||
var touch = e.getTouch(this);
|
||||
trace(touch);
|
||||
if (touch != null && touch.phase == TouchPhase.ENDED) {
|
||||
SceneManager.getInstance().switchScene(new SequenceExample());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -53,7 +53,7 @@ class VineExample extends Scene {
|
||||
|
||||
var skeletonSprite = new SkeletonSprite(skeletondata, animationStateData);
|
||||
skeletonSprite.skeleton.updateWorldTransform(Physics.none);
|
||||
var bounds = skeletonSprite.skeleton.getBounds();
|
||||
var bounds = skeletonSprite.bounds;
|
||||
skeletonSprite.scale = Starling.current.stage.stageWidth / bounds.width / 10;
|
||||
skeletonSprite.x = Starling.current.stage.stageWidth / 2;
|
||||
skeletonSprite.y = Starling.current.stage.stageHeight * 0.5;
|
||||
|
||||
@ -2,9 +2,9 @@
|
||||
<project>
|
||||
|
||||
<meta title="spine-haxe-example" package="spine" version="4.2.0" company="Esoteric Software" />
|
||||
<!-- <app main="Main" path="export" file="SpineHaxeExample" /> -->
|
||||
<app main="Main" path="export" file="SpineHaxeExample" />
|
||||
<!-- <app main="MainStarling" path="export" file="SpineHaxeExample" /> -->
|
||||
<app main="MainFlixel" path="export" file="SpineHaxeExample" />
|
||||
<!-- <app main="MainFlixel" path="export" file="SpineHaxeExample" /> -->
|
||||
<window allow-high-dpi="true" />
|
||||
|
||||
<haxelib name="openfl" />
|
||||
|
||||
@ -36,7 +36,6 @@ import openfl.geom.Matrix;
|
||||
import openfl.geom.Point;
|
||||
import openfl.geom.Rectangle as OpenFlRectangle;
|
||||
import spine.Bone;
|
||||
import spine.Rectangle;
|
||||
import spine.Skeleton;
|
||||
import spine.SkeletonClipping;
|
||||
import spine.SkeletonData;
|
||||
@ -264,12 +263,12 @@ class SkeletonSprite extends DisplayObject implements IAnimatable {
|
||||
_boundsPoint[0] = __bounds.x;
|
||||
_boundsPoint[1] = __bounds.y;
|
||||
skeletonToHaxeWorldCoordinates(_boundsPoint);
|
||||
out.setTo(_boundsPoint[0], _boundsPoint[1], __bounds.width * scaleX, __bounds.height * scaleX);
|
||||
out.setTo(_boundsPoint[0], _boundsPoint[1], __bounds.width, __bounds.height);
|
||||
} else {
|
||||
getTransformationMatrix(targetSpace, _tempMatrix);
|
||||
out.setTo(__bounds.x, __bounds.y, __bounds.width, __bounds.height);
|
||||
MatrixUtil.transformCoords(_tempMatrix, out.x, out.y, _tempPoint);
|
||||
out.setTo(_tempPoint.x, _tempPoint.y, out.width * scaleX, out.height * scaleY);
|
||||
out.setTo(_tempPoint.x, _tempPoint.y, out.width, out.height);
|
||||
}
|
||||
|
||||
return out;
|
||||
@ -286,6 +285,35 @@ class SkeletonSprite extends DisplayObject implements IAnimatable {
|
||||
return _smoothing;
|
||||
}
|
||||
|
||||
override function get_scaleX():Float {
|
||||
return skeleton.scaleX;
|
||||
}
|
||||
|
||||
override function set_scaleX(value:Float):Float {
|
||||
skeleton.scaleX = value;
|
||||
calculateBounds();
|
||||
return skeleton.scaleX;
|
||||
}
|
||||
|
||||
override function get_scaleY():Float {
|
||||
return skeleton.scaleY * Bone.yDir;
|
||||
}
|
||||
|
||||
override function set_scaleY(value:Float):Float {
|
||||
skeleton.scaleY = value;
|
||||
calculateBounds();
|
||||
return value;
|
||||
}
|
||||
|
||||
override function get_scale():Float {
|
||||
return skeleton.scaleX;
|
||||
}
|
||||
|
||||
override function set_scale(value:Float):Float {
|
||||
scaleY = value;
|
||||
return scaleX = value;
|
||||
}
|
||||
|
||||
public function advanceTime(time:Float):Void {
|
||||
state.update(time);
|
||||
state.apply(skeleton);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user