[as3][starling] Added VertexEffect and implementations plus support for Starling. See #898

This commit is contained in:
badlogic 2017-06-27 14:25:02 +02:00
parent 7361358121
commit 943b4f98a7
16 changed files with 436 additions and 9 deletions

View File

@ -17,12 +17,14 @@
* Added `ClippingAttachment`, additional method `newClippingAttachment` in `AttachmentLoader` interface. * Added `ClippingAttachment`, additional method `newClippingAttachment` in `AttachmentLoader` interface.
* `AnimationState#apply` returns boolean indicating if any timeline was applied or not. * `AnimationState#apply` returns boolean indicating if any timeline was applied or not.
* `Animation#apply` and `Timeline#apply`` now take enums `MixPose` and `MixDirection` instead of booleans * `Animation#apply` and `Timeline#apply`` now take enums `MixPose` and `MixDirection` instead of booleans
* Added `VertexEffect` and implementations `JitterEffect` and `SwirlEffect`. Allows you to modify vertices before they are submitted for drawing. See Starling changes.
### Starling ### Starling
* Fixed renderer to work with 3.6 changes. * Fixed renderer to work with 3.6 changes.
* Added support for two color tinting. * Added support for two color tinting.
* Added support for clipping. * Added support for clipping.
* Added support for rotated regions in texture atlas loaded via StarlingAtlasAttachmentLoader. * Added support for rotated regions in texture atlas loaded via StarlingAtlasAttachmentLoader.
* Added support for vertex effects. See `RaptorExample.as`
## C ## C
* **Breaking changes** * **Breaking changes**

View File

@ -1,10 +1,18 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
encoding//src/spine/Interpolation.as=UTF-8
encoding//src/spine/MathUtils.as=UTF-8
encoding//src/spine/SkeletonClipping.as=UTF-8 encoding//src/spine/SkeletonClipping.as=UTF-8
encoding//src/spine/SkeletonJson.as=UTF-8 encoding//src/spine/SkeletonJson.as=UTF-8
encoding//src/spine/Triangulator.as=UTF-8 encoding//src/spine/Triangulator.as=UTF-8
encoding//src/spine/Vertex.as=UTF-8
encoding//src/spine/VertexEffect.as=UTF-8
encoding//src/spine/animation/MixDirection.as=UTF-8 encoding//src/spine/animation/MixDirection.as=UTF-8
encoding//src/spine/animation/MixPose.as=UTF-8 encoding//src/spine/animation/MixPose.as=UTF-8
encoding//src/spine/animation/TwoColorTimeline.as=UTF-8 encoding//src/spine/animation/TwoColorTimeline.as=UTF-8
encoding//src/spine/attachments/ClippingAttachment.as=UTF-8 encoding//src/spine/attachments/ClippingAttachment.as=UTF-8
encoding//src/spine/attachments/PointAttachment.as=UTF-8 encoding//src/spine/attachments/PointAttachment.as=UTF-8
encoding//src/spine/interpolation/Pow.as=UTF-8
encoding//src/spine/interpolation/PowOut.as=UTF-8
encoding//src/spine/vertexeffects/JitterEffect.as=UTF-8
encoding//src/spine/vertexeffects/SwirlEffect.as=UTF-8
encoding/<project>=UTF-8 encoding/<project>=UTF-8

View File

@ -0,0 +1,41 @@
/******************************************************************************
* Spine Runtimes Software License v2.5
*
* Copyright (c) 2013-2016, Esoteric Software
* All rights reserved.
*
* You are granted a perpetual, non-exclusive, non-sublicensable, and
* non-transferable license to use, install, execute, and perform the Spine
* Runtimes software and derivative works solely for personal or internal
* use. Without the written permission of Esoteric Software (see Section 2 of
* the Spine Software License Agreement), you may not (a) modify, translate,
* adapt, or develop new applications using the Spine Runtimes or otherwise
* create derivative works or improvements of the Spine Runtimes or (b) remove,
* delete, alter, or obscure any trademarks or any copyright, trademark, patent,
* or other intellectual property or proprietary rights notices on or in the
* Software, including any copy thereof. Redistributions in binary or source
* form must include this license and terms.
*
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "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 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 THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
package spine {
public class Interpolation {
protected function applyInternal (a : Number) : Number {
return a;
}
public function apply (start : Number, end : Number, a : Number) : Number {
return start + (end - start) * applyInternal(a);
}
}
}

View File

@ -52,5 +52,16 @@ package spine {
static public function signum(value : Number) : Number { static public function signum(value : Number) : Number {
return value > 0 ? 1 : value < 0 ? -1 : 0; return value > 0 ? 1 : value < 0 ? -1 : 0;
} }
static public function randomTriangular(min : Number, max : Number) : Number {
return randomTriangularWith(min, max, (min + max) * 0.5);
}
static public function randomTriangularWith(min : Number, max : Number, mode : Number) : Number {
var u : Number = Math.random();
var d : Number = max - min;
if (u <= (mode - min) / d) return min + Math.sqrt(u * d * (mode - min));
return max - Math.sqrt((1 - u) * d * (max - mode));
}
} }
} }

View File

@ -0,0 +1,43 @@
/******************************************************************************
* Spine Runtimes Software License v2.5
*
* Copyright (c) 2013-2016, Esoteric Software
* All rights reserved.
*
* You are granted a perpetual, non-exclusive, non-sublicensable, and
* non-transferable license to use, install, execute, and perform the Spine
* Runtimes software and derivative works solely for personal or internal
* use. Without the written permission of Esoteric Software (see Section 2 of
* the Spine Software License Agreement), you may not (a) modify, translate,
* adapt, or develop new applications using the Spine Runtimes or otherwise
* create derivative works or improvements of the Spine Runtimes or (b) remove,
* delete, alter, or obscure any trademarks or any copyright, trademark, patent,
* or other intellectual property or proprietary rights notices on or in the
* Software, including any copy thereof. Redistributions in binary or source
* form must include this license and terms.
*
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "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 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 THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
package spine {
/**
* @author badlogic
*/
public class Vertex {
public var x : Number;
public var y : Number;
public var u : Number;
public var v : Number;
public var light : Color = new spine.Color(0, 0, 0);
public var dark : Color = new spine.Color(0, 0, 0);
}
}

View File

@ -0,0 +1,39 @@
/******************************************************************************
* Spine Runtimes Software License v2.5
*
* Copyright (c) 2013-2016, Esoteric Software
* All rights reserved.
*
* You are granted a perpetual, non-exclusive, non-sublicensable, and
* non-transferable license to use, install, execute, and perform the Spine
* Runtimes software and derivative works solely for personal or internal
* use. Without the written permission of Esoteric Software (see Section 2 of
* the Spine Software License Agreement), you may not (a) modify, translate,
* adapt, or develop new applications using the Spine Runtimes or otherwise
* create derivative works or improvements of the Spine Runtimes or (b) remove,
* delete, alter, or obscure any trademarks or any copyright, trademark, patent,
* or other intellectual property or proprietary rights notices on or in the
* Software, including any copy thereof. Redistributions in binary or source
* form must include this license and terms.
*
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "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 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 THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
package spine {
public interface VertexEffect {
function begin(skeleton : Skeleton) : void;
function transform(vertex : Vertex) : void;
function end() : void;
}
}

View File

@ -0,0 +1,46 @@
/******************************************************************************
* Spine Runtimes Software License v2.5
*
* Copyright (c) 2013-2016, Esoteric Software
* All rights reserved.
*
* You are granted a perpetual, non-exclusive, non-sublicensable, and
* non-transferable license to use, install, execute, and perform the Spine
* Runtimes software and derivative works solely for personal or internal
* use. Without the written permission of Esoteric Software (see Section 2 of
* the Spine Software License Agreement), you may not (a) modify, translate,
* adapt, or develop new applications using the Spine Runtimes or otherwise
* create derivative works or improvements of the Spine Runtimes or (b) remove,
* delete, alter, or obscure any trademarks or any copyright, trademark, patent,
* or other intellectual property or proprietary rights notices on or in the
* Software, including any copy thereof. Redistributions in binary or source
* form must include this license and terms.
*
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "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 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 THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
package spine.interpolation {
import spine.Interpolation;
public class Pow extends Interpolation {
protected var power : Number;
public function Pow(power : Number) {
this.power = power;
}
protected override function applyInternal(a : Number) : Number {
if (a <= 0.5) return Math.pow(a * 2, power) / 2;
return Math.pow((a - 1) * 2, power) / (power % 2 == 0 ? -2 : 2) + 1;
}
}
}

View File

@ -0,0 +1,41 @@
/******************************************************************************
* Spine Runtimes Software License v2.5
*
* Copyright (c) 2013-2016, Esoteric Software
* All rights reserved.
*
* You are granted a perpetual, non-exclusive, non-sublicensable, and
* non-transferable license to use, install, execute, and perform the Spine
* Runtimes software and derivative works solely for personal or internal
* use. Without the written permission of Esoteric Software (see Section 2 of
* the Spine Software License Agreement), you may not (a) modify, translate,
* adapt, or develop new applications using the Spine Runtimes or otherwise
* create derivative works or improvements of the Spine Runtimes or (b) remove,
* delete, alter, or obscure any trademarks or any copyright, trademark, patent,
* or other intellectual property or proprietary rights notices on or in the
* Software, including any copy thereof. Redistributions in binary or source
* form must include this license and terms.
*
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "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 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 THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
package spine.interpolation {
public class PowOut extends Pow {
public function PowOut(power : Number) {
super(power);
}
protected override function applyInternal(a : Number) : Number {
return Math.pow(a - 1, power) * (power % 2 == 0 ? -1 : 1) + 1;
}
}
}

View File

@ -0,0 +1,57 @@
/******************************************************************************
* Spine Runtimes Software License v2.5
*
* Copyright (c) 2013-2016, Esoteric Software
* All rights reserved.
*
* You are granted a perpetual, non-exclusive, non-sublicensable, and
* non-transferable license to use, install, execute, and perform the Spine
* Runtimes software and derivative works solely for personal or internal
* use. Without the written permission of Esoteric Software (see Section 2 of
* the Spine Software License Agreement), you may not (a) modify, translate,
* adapt, or develop new applications using the Spine Runtimes or otherwise
* create derivative works or improvements of the Spine Runtimes or (b) remove,
* delete, alter, or obscure any trademarks or any copyright, trademark, patent,
* or other intellectual property or proprietary rights notices on or in the
* Software, including any copy thereof. Redistributions in binary or source
* form must include this license and terms.
*
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "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 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 THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
package spine.vertexeffects {
import spine.MathUtils;
import spine.Skeleton;
import spine.Vertex;
import spine.VertexEffect;
public class JitterEffect implements VertexEffect {
public var jitterX : Number;
public var jitterY : Number;
public function JitterEffect(jitterX: Number, jitterY: Number) {
this.jitterX = jitterX;
this.jitterY = jitterY;
}
public function begin(skeleton : Skeleton) : void {
}
public function transform(vertex : Vertex) : void {
vertex.x += MathUtils.randomTriangular(-jitterX, jitterY);
vertex.y += MathUtils.randomTriangular(-jitterX, jitterY);
}
public function end() : void {
}
}
}

View File

@ -0,0 +1,84 @@
/******************************************************************************
* Spine Runtimes Software License v2.5
*
* Copyright (c) 2013-2016, Esoteric Software
* All rights reserved.
*
* You are granted a perpetual, non-exclusive, non-sublicensable, and
* non-transferable license to use, install, execute, and perform the Spine
* Runtimes software and derivative works solely for personal or internal
* use. Without the written permission of Esoteric Software (see Section 2 of
* the Spine Software License Agreement), you may not (a) modify, translate,
* adapt, or develop new applications using the Spine Runtimes or otherwise
* create derivative works or improvements of the Spine Runtimes or (b) remove,
* delete, alter, or obscure any trademarks or any copyright, trademark, patent,
* or other intellectual property or proprietary rights notices on or in the
* Software, including any copy thereof. Redistributions in binary or source
* form must include this license and terms.
*
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "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 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 THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
package spine.vertexeffects {
import spine.interpolation.Pow;
import spine.MathUtils;
import spine.Interpolation;
import spine.Skeleton;
import spine.Vertex;
import spine.VertexEffect;
public class SwirlEffect implements VertexEffect {
private var worldX : Number, worldY : Number, _radius : Number = 0, _angle : Number = 0;
private var _interpolation : Interpolation;
private var _centerX : Number = 0, _centerY : Number = 0;
public function SwirlEffect(radius : Number) {
this._interpolation = new Pow(2);;
this._radius = radius;
}
public function begin(skeleton : Skeleton) : void {
worldX = skeleton.x + _centerX;
worldY = skeleton.y + _centerY;
}
public function transform(vertex : Vertex) : void {
var x : Number = vertex.x - worldX;
var y : Number = vertex.y - worldY;
var dist : Number = Math.sqrt(x * x + y * y);
if (dist < radius) {
var theta : Number = interpolation.apply(0, angle, (radius - dist) / radius);
var cos : Number = Math.cos(theta), sin : Number = Math.sin(theta);
vertex.x = cos * x - sin * y + worldX;
vertex.y = sin * x + cos * y + worldY;
}
}
public function end() : void {
}
public function get radius () : Number { return _radius; }
public function set radius (radius : Number) : void { _radius = radius; }
public function get angle () : Number { return _angle; }
public function set angle (angle : Number) : void { _angle = angle * MathUtils.degRad; }
public function get centerX () : Number { return _centerX; }
public function set centerX (centerX : Number) : void { _centerX = centerX; }
public function get centerY () : Number { return _centerY; }
public function set centerY (centerY : Number) : void { _centerY = centerY; }
public function get interpolation () : Interpolation { return _interpolation; }
public function set interpolation (interpolation : Interpolation) : void { _interpolation = interpolation; }
}
}

View File

@ -29,6 +29,10 @@
*****************************************************************************/ *****************************************************************************/
package spine.examples { package spine.examples {
import spine.interpolation.Pow;
import starling.animation.IAnimatable;
import spine.vertexeffects.SwirlEffect;
import spine.vertexeffects.JitterEffect;
import starling.display.DisplayObjectContainer; import starling.display.DisplayObjectContainer;
import spine.atlas.Atlas; import spine.atlas.Atlas;
import spine.*; import spine.*;
@ -43,7 +47,7 @@ package spine.examples {
import starling.events.TouchEvent; import starling.events.TouchEvent;
import starling.events.TouchPhase; import starling.events.TouchPhase;
public class RaptorExample extends Sprite { public class RaptorExample extends Sprite implements IAnimatable {
[Embed(source = "/raptor-pro.json", mimeType = "application/octet-stream")] [Embed(source = "/raptor-pro.json", mimeType = "application/octet-stream")]
static public const RaptorJson : Class; static public const RaptorJson : Class;
@ -56,6 +60,10 @@ package spine.examples {
private var gunGrabbed : Boolean; private var gunGrabbed : Boolean;
private var gunGrabCount : Number = 0; private var gunGrabCount : Number = 0;
private var swirl : SwirlEffect;
private var swirlTime : Number = 0;
private var pow2 : Interpolation = new Pow(2);
public function RaptorExample() { public function RaptorExample() {
var attachmentLoader : AttachmentLoader; var attachmentLoader : AttachmentLoader;
var spineAtlas : Atlas = new Atlas(new RaptorAtlas(), new StarlingTextureLoader(new RaptorAtlasTexture())); var spineAtlas : Atlas = new Atlas(new RaptorAtlas(), new StarlingTextureLoader(new RaptorAtlasTexture()));
@ -75,8 +83,14 @@ package spine.examples {
skeleton.skeleton.updateWorldTransform(); skeleton.skeleton.updateWorldTransform();
this.setRequiresRedraw(); this.setRequiresRedraw();
// skeleton.vertexEffect = new JitterEffect(10, 10);
swirl = new SwirlEffect(400);
swirl.centerY = -200;
skeleton.vertexEffect = swirl;
addChild(skeleton); addChild(skeleton);
Starling.juggler.add(skeleton); Starling.juggler.add(skeleton);
Starling.juggler.add(this);
addEventListener(TouchEvent.TOUCH, onClick); addEventListener(TouchEvent.TOUCH, onClick);
} }
@ -98,5 +112,12 @@ package spine.examples {
} }
} }
} }
public function advanceTime(time : Number) : void {
swirlTime += time;
var percent : Number = swirlTime % 2;
if (percent > 1) percent = 1 - (percent - 1);
swirl.angle = pow2.apply(-60, 60, percent);
}
} }
} }

View File

@ -39,6 +39,7 @@ package spine.starling {
import spine.attachments.Attachment; import spine.attachments.Attachment;
import spine.attachments.MeshAttachment; import spine.attachments.MeshAttachment;
import spine.attachments.RegionAttachment; import spine.attachments.RegionAttachment;
import spine.VertexEffect;
import starling.display.BlendMode; import starling.display.BlendMode;
import starling.display.DisplayObject; import starling.display.DisplayObject;
@ -64,6 +65,11 @@ package spine.starling {
private static var clipper: SkeletonClipping = new SkeletonClipping(); private static var clipper: SkeletonClipping = new SkeletonClipping();
private static var QUAD_INDICES : Vector.<uint> = new <uint>[0, 1, 2, 2, 3, 0]; private static var QUAD_INDICES : Vector.<uint> = new <uint>[0, 1, 2, 2, 3, 0];
public var vertexEffect : VertexEffect;
private var tempLight : spine.Color = new spine.Color(0, 0, 0);
private var tempDark : spine.Color = new spine.Color(0, 0, 0);
private var tempVertex : spine.Vertex = new spine.Vertex();
public function SkeletonSprite(skeletonData : SkeletonData) { public function SkeletonSprite(skeletonData : SkeletonData) {
Bone.yDown = true; Bone.yDown = true;
_skeleton = new Skeleton(skeletonData); _skeleton = new Skeleton(skeletonData);
@ -87,6 +93,8 @@ package spine.starling {
var indexData : IndexData, indices : Vector.<uint>, vertexData : VertexData; var indexData : IndexData, indices : Vector.<uint>, vertexData : VertexData;
var uvs : Vector.<Number>; var uvs : Vector.<Number>;
if (vertexEffect != null) vertexEffect.begin(skeleton);
for (var i : int = 0, n : int = drawOrder.length; i < n; ++i) { for (var i : int = 0, n : int = drawOrder.length; i < n; ++i) {
var worldVertices : Vector.<Number> = _tempVertices; var worldVertices : Vector.<Number> = _tempVertices;
var slot : Slot = drawOrder[i]; var slot : Slot = drawOrder[i];
@ -172,11 +180,35 @@ package spine.starling {
vertexData = mesh.getVertexData(); vertexData = mesh.getVertexData();
vertexData.numVertices = verticesCount; vertexData.numVertices = verticesCount;
vertexData.colorize("color", rgb, a); if (vertexEffect != null) {
vertexData.colorize("color2", dark); tempLight.r = ((rgb >> 16) & 0xff) / 255.0;
for (ii = 0, iii = 0; ii < verticesCount; ii++, iii += 2) { tempLight.g = ((rgb >> 8) & 0xff) / 255.0;
mesh.setVertexPosition(ii, worldVertices[iii], worldVertices[iii + 1]); tempLight.b = (rgb & 0xff) / 255.0;
mesh.setTexCoords(ii, uvs[iii], uvs[iii + 1]); tempLight.a = a;
tempDark.r = ((dark >> 16) & 0xff) / 255.0;
tempDark.g = ((dark >> 8) & 0xff) / 255.0;
tempDark.b = (dark & 0xff) / 255.0;
tempDark.a = 0;
for (ii = 0, iii = 0; ii < verticesCount; ii++, iii += 2) {
tempVertex.x = worldVertices[iii];
tempVertex.y = worldVertices[iii + 1];
tempVertex.u = uvs[iii];
tempVertex.v = uvs[iii + 1];
tempVertex.light.setFromColor(tempLight);
tempVertex.dark.setFromColor(tempDark);
vertexEffect.transform(tempVertex);
vertexData.colorize("color", Color.rgb(tempVertex.light.r * 255, tempVertex.light.g * 255, tempVertex.light.b * 255), tempVertex.light.a, ii, 1);
vertexData.colorize("color2", Color.rgb(tempVertex.dark.r * 255, tempVertex.dark.g * 255, tempVertex.dark.b * 255), a, ii, 1);
mesh.setVertexPosition(ii, tempVertex.x, tempVertex.y);
mesh.setTexCoords(ii, tempVertex.u, tempVertex.v);
}
} else {
vertexData.colorize("color", rgb, a);
vertexData.colorize("color2", dark);
for (ii = 0, iii = 0; ii < verticesCount; ii++, iii += 2) {
mesh.setVertexPosition(ii, worldVertices[iii], worldVertices[iii + 1]);
mesh.setTexCoords(ii, uvs[iii], uvs[iii + 1]);
}
} }
painter.state.blendMode = blendModes[slot.data.blendMode.ordinal]; painter.state.blendMode = blendModes[slot.data.blendMode.ordinal];
painter.batchMesh(mesh); painter.batchMesh(mesh);
@ -185,6 +217,8 @@ package spine.starling {
} }
painter.state.blendMode = originalBlendMode; painter.state.blendMode = originalBlendMode;
clipper.clipEnd(); clipper.clipEnd();
if (vertexEffect != null) vertexEffect.end();
} }
override public function hitTest(localPoint : Point) : DisplayObject { override public function hitTest(localPoint : Point) : DisplayObject {