mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 15:24:55 +08:00
[haxe] Apply fixes to target hl (HashLink).
This commit is contained in:
parent
67d38adebf
commit
264ac86456
@ -25,73 +25,72 @@
|
||||
* 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;
|
||||
|
||||
import openfl.events.Event;
|
||||
import starling.events.Event as StarlingEvent;
|
||||
import flixelExamples.FlixelState;
|
||||
import starlingExamples.BasicExample;
|
||||
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,58 +115,60 @@ 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 {
|
||||
starlingSingleton = new Starling(starling.display.Sprite, stage, new Rectangle(0, 0, 800, 600));
|
||||
starlingSingleton.supportHighResolutions = true;
|
||||
starlingSingleton.addEventListener(Event.ROOT_CREATED, onStarlingRootCreated);
|
||||
}
|
||||
starlingSingleton.addEventListener(StarlingEvent.ROOT_CREATED, onStarlingRootCreated);
|
||||
}
|
||||
|
||||
private function onStarlingRootCreated(event:Event):Void {
|
||||
private function onStarlingRootCreated(event:StarlingEvent):Void {
|
||||
destroyUI();
|
||||
starlingSingleton.removeEventListener(Event.ROOT_CREATED, onStarlingRootCreated);
|
||||
starlingSingleton.removeEventListener(StarlingEvent.ROOT_CREATED, onStarlingRootCreated);
|
||||
starlingSingleton.start();
|
||||
Starling.current.stage.stageWidth = 800;
|
||||
Starling.current.stage.stageHeight = 600;
|
||||
Starling.current.stage.color = 0x000000;
|
||||
|
||||
SceneManager.getInstance().switchScene(new BasicExample());
|
||||
|
||||
@ -25,10 +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;
|
||||
|
||||
import haxe.DynamicAccess;
|
||||
import Reflect;
|
||||
import haxe.Json;
|
||||
import spine.animation.AlphaTimeline;
|
||||
@ -134,8 +135,7 @@ class SkeletonJson {
|
||||
boneData.scaleY = getFloat(boneMap, "scaleY", 1);
|
||||
boneData.shearX = getFloat(boneMap, "shearX");
|
||||
boneData.shearY = getFloat(boneMap, "shearY");
|
||||
boneData.inherit = Reflect.hasField(boneMap,
|
||||
"inherit") ? Inherit.fromName(Reflect.getProperty(boneMap, "inherit")) : Inherit.normal;
|
||||
boneData.inherit = Reflect.hasField(boneMap, "inherit") ? Inherit.fromName(Reflect.getProperty(boneMap, "inherit")) : Inherit.normal;
|
||||
boneData.skinRequired = Reflect.hasField(boneMap, "skin") ? cast(Reflect.getProperty(boneMap, "skin"), Bool) : false;
|
||||
|
||||
var color:String = Reflect.getProperty(boneMap, "color");
|
||||
@ -312,12 +312,17 @@ class SkeletonJson {
|
||||
physicsData.wind = getFloat(constraintMap, "wind");
|
||||
physicsData.gravity = getFloat(constraintMap, "gravity");
|
||||
physicsData.mix = getValue(constraintMap, "mix", 1);
|
||||
physicsData.inertiaGlobal = Reflect.hasField(constraintMap, "inertiaGlobal") ? cast(Reflect.getProperty(constraintMap, "inertiaGlobal"), Bool) : false;
|
||||
physicsData.strengthGlobal = Reflect.hasField(constraintMap, "strengthGlobal") ? cast(Reflect.getProperty(constraintMap, "strengthGlobal"), Bool) : false;
|
||||
physicsData.dampingGlobal = Reflect.hasField(constraintMap, "dampingGlobal") ? cast(Reflect.getProperty(constraintMap, "dampingGlobal"), Bool) : false;
|
||||
physicsData.dampingGlobal = Reflect.hasField(constraintMap, "dampingGlobal") ? cast(Reflect.getProperty(constraintMap, "dampingGlobal"), Bool) : false;
|
||||
physicsData.inertiaGlobal = Reflect.hasField(constraintMap,
|
||||
"inertiaGlobal") ? cast(Reflect.getProperty(constraintMap, "inertiaGlobal"), Bool) : false;
|
||||
physicsData.strengthGlobal = Reflect.hasField(constraintMap,
|
||||
"strengthGlobal") ? cast(Reflect.getProperty(constraintMap, "strengthGlobal"), Bool) : false;
|
||||
physicsData.dampingGlobal = Reflect.hasField(constraintMap,
|
||||
"dampingGlobal") ? cast(Reflect.getProperty(constraintMap, "dampingGlobal"), Bool) : false;
|
||||
physicsData.dampingGlobal = Reflect.hasField(constraintMap,
|
||||
"dampingGlobal") ? cast(Reflect.getProperty(constraintMap, "dampingGlobal"), Bool) : false;
|
||||
physicsData.windGlobal = Reflect.hasField(constraintMap, "windGlobal") ? cast(Reflect.getProperty(constraintMap, "windGlobal"), Bool) : false;
|
||||
physicsData.gravityGlobal = Reflect.hasField(constraintMap, "gravityGlobal") ? cast(Reflect.getProperty(constraintMap, "gravityGlobal"), Bool) : false;
|
||||
physicsData.gravityGlobal = Reflect.hasField(constraintMap,
|
||||
"gravityGlobal") ? cast(Reflect.getProperty(constraintMap, "gravityGlobal"), Bool) : false;
|
||||
physicsData.mixGlobal = Reflect.hasField(constraintMap, "mixGlobal") ? cast(Reflect.getProperty(constraintMap, "mixGlobal"), Bool) : false;
|
||||
|
||||
skeletonData.physicsConstraints.push(physicsData);
|
||||
@ -419,7 +424,7 @@ class SkeletonJson {
|
||||
// Events.
|
||||
var events:Dynamic = Reflect.getProperty(root, "events");
|
||||
for (eventName in Reflect.fields(events)) {
|
||||
var eventMap:Map<String, Dynamic> = Reflect.field(events, eventName);
|
||||
var eventMap:DynamicAccess<Dynamic> = Reflect.field(events, eventName);
|
||||
var eventData:EventData = new EventData(eventName);
|
||||
eventData.intValue = getInt(eventMap, "int");
|
||||
eventData.floatValue = getFloat(eventMap, "float");
|
||||
@ -517,7 +522,7 @@ class SkeletonJson {
|
||||
var box:BoundingBoxAttachment = attachmentLoader.newBoundingBoxAttachment(skin, name);
|
||||
if (box == null)
|
||||
return null;
|
||||
readVertices(map, box, Std.parseInt(Reflect.field(map, "vertexCount")) << 1);
|
||||
readVertices(map, box, getInt(map, "vertexCount", 0) << 1);
|
||||
return box;
|
||||
case AttachmentType.path:
|
||||
var path:PathAttachment = attachmentLoader.newPathAttachment(skin, name);
|
||||
@ -525,11 +530,10 @@ class SkeletonJson {
|
||||
return null;
|
||||
path.closed = Reflect.hasField(map, "closed") ? cast(Reflect.field(map, "closed"), Bool) : false;
|
||||
path.constantSpeed = Reflect.hasField(map, "constantSpeed") ? cast(Reflect.field(map, "constantSpeed"), Bool) : true;
|
||||
var vertexCount:Int = Std.parseInt(Reflect.field(map, "vertexCount"));
|
||||
readVertices(map, path, vertexCount << 1);
|
||||
readVertices(map, path, getInt(map, "vertexCount", 0) << 1);
|
||||
var lengths:Array<Float> = new Array<Float>();
|
||||
for (curves in cast(Reflect.field(map, "lengths"), Array<Dynamic>)) {
|
||||
lengths.push(Std.parseFloat(curves) * scale);
|
||||
lengths.push(curves * scale);
|
||||
}
|
||||
path.lengths = lengths;
|
||||
return path;
|
||||
@ -556,8 +560,7 @@ class SkeletonJson {
|
||||
throw new SpineException("Clipping end slot not found: " + end);
|
||||
clip.endSlot = slot;
|
||||
}
|
||||
var vertexCount:Int = getInt(map, "vertexCount", 0);
|
||||
readVertices(map, clip, vertexCount << 1);
|
||||
readVertices(map, clip, getInt(map, "vertexCount", 0) << 1);
|
||||
color = Reflect.getProperty(map, "color");
|
||||
if (color != null) {
|
||||
clip.color.setFromString(color);
|
||||
@ -1035,22 +1038,22 @@ class SkeletonJson {
|
||||
}
|
||||
|
||||
var timeline:PhysicsConstraintTimeline;
|
||||
if (timelineName == "inertia")
|
||||
timeline = new PhysicsConstraintInertiaTimeline(frames, frames, constraintIndex);
|
||||
else if (timelineName == "strength")
|
||||
timeline = new PhysicsConstraintStrengthTimeline(frames, frames, constraintIndex);
|
||||
else if (timelineName == "damping")
|
||||
timeline = new PhysicsConstraintDampingTimeline(frames, frames, constraintIndex);
|
||||
else if (timelineName == "mass")
|
||||
timeline = new PhysicsConstraintMassTimeline(frames, frames, constraintIndex);
|
||||
else if (timelineName == "wind")
|
||||
timeline = new PhysicsConstraintWindTimeline(frames, frames, constraintIndex);
|
||||
else if (timelineName == "gravity")
|
||||
timeline = new PhysicsConstraintGravityTimeline(frames, frames, constraintIndex);
|
||||
else if (timelineName == "mix") //
|
||||
timeline = new PhysicsConstraintMixTimeline(frames, frames, constraintIndex);
|
||||
else
|
||||
continue;
|
||||
if (timelineName == "inertia")
|
||||
timeline = new PhysicsConstraintInertiaTimeline(frames, frames, constraintIndex);
|
||||
else if (timelineName == "strength")
|
||||
timeline = new PhysicsConstraintStrengthTimeline(frames, frames, constraintIndex);
|
||||
else if (timelineName == "damping")
|
||||
timeline = new PhysicsConstraintDampingTimeline(frames, frames, constraintIndex);
|
||||
else if (timelineName == "mass")
|
||||
timeline = new PhysicsConstraintMassTimeline(frames, frames, constraintIndex);
|
||||
else if (timelineName == "wind")
|
||||
timeline = new PhysicsConstraintWindTimeline(frames, frames, constraintIndex);
|
||||
else if (timelineName == "gravity")
|
||||
timeline = new PhysicsConstraintGravityTimeline(frames, frames, constraintIndex);
|
||||
else if (timelineName == "mix") //
|
||||
timeline = new PhysicsConstraintMixTimeline(frames, frames, constraintIndex);
|
||||
else
|
||||
continue;
|
||||
timelines.push(readTimeline(timelineMap, timeline, 0, 1));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user