mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
Updated MonoGame example
This commit is contained in:
parent
dfb8861de4
commit
c11309893f
@ -29,15 +29,9 @@
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Audio;
|
|
||||||
using Microsoft.Xna.Framework.Content;
|
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using Microsoft.Xna.Framework.Input;
|
using Microsoft.Xna.Framework.Input;
|
||||||
using Microsoft.Xna.Framework.Media;
|
|
||||||
using Spine;
|
|
||||||
|
|
||||||
namespace Spine {
|
namespace Spine {
|
||||||
public class Example : Microsoft.Xna.Framework.Game {
|
public class Example : Microsoft.Xna.Framework.Game {
|
||||||
@ -50,7 +44,7 @@ namespace Spine {
|
|||||||
|
|
||||||
private string assetsFolder = "data/";
|
private string assetsFolder = "data/";
|
||||||
|
|
||||||
public Example () {
|
public Example() {
|
||||||
IsMouseVisible = true;
|
IsMouseVisible = true;
|
||||||
|
|
||||||
graphics = new GraphicsDeviceManager(this);
|
graphics = new GraphicsDeviceManager(this);
|
||||||
@ -59,56 +53,51 @@ namespace Spine {
|
|||||||
graphics.PreferredBackBufferHeight = 600;
|
graphics.PreferredBackBufferHeight = 600;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Initialize () {
|
|
||||||
// TODO: Add your initialization logic here
|
|
||||||
|
|
||||||
base.Initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void LoadContent() {
|
protected override void LoadContent() {
|
||||||
// Two color tint effect, comment line 76 to disable
|
// Two color tint effect, comment line 80 to disable
|
||||||
var spineEffect = Content.Load<Effect>("Content\\SpineEffect");
|
var spineEffect = Content.Load<Effect>("Content\\SpineEffect");
|
||||||
spineEffect.Parameters["World"].SetValue(Matrix.Identity);
|
spineEffect.Parameters["World"].SetValue(Matrix.Identity);
|
||||||
spineEffect.Parameters["View"].SetValue(Matrix.CreateLookAt(new Vector3(0.0f, 0.0f, 1.0f), Vector3.Zero, Vector3.Up));
|
spineEffect.Parameters["View"].SetValue(Matrix.CreateLookAt(new Vector3(0.0f, 0.0f, 1.0f), Vector3.Zero, Vector3.Up));
|
||||||
|
|
||||||
skeletonRenderer = new SkeletonRenderer(GraphicsDevice);
|
skeletonRenderer = new SkeletonRenderer(GraphicsDevice);
|
||||||
skeletonRenderer.PremultipliedAlpha = true;
|
skeletonRenderer.PremultipliedAlpha = false;
|
||||||
skeletonRenderer.Effect = spineEffect;
|
skeletonRenderer.Effect = spineEffect;
|
||||||
|
|
||||||
// String name = "spineboy";
|
// String name = "spineboy-ess";
|
||||||
// String name = "goblins-mesh";
|
// String name = "goblins-pro";
|
||||||
// String name = "raptor";
|
// String name = "raptor-pro";
|
||||||
// String name = "tank";
|
// String name = "tank-pro";
|
||||||
// String name = "coin";
|
String name = "coin-pro";
|
||||||
String name = "TwoColorTest";
|
String atlasName = name.Replace("-pro", "").Replace("-ess", "");
|
||||||
bool binaryData = true;
|
bool binaryData = false;
|
||||||
|
|
||||||
Atlas atlas = new Atlas(assetsFolder + name + ".atlas", new XnaTextureLoader(GraphicsDevice));
|
Atlas atlas = new Atlas(assetsFolder + atlasName + ".atlas", new XnaTextureLoader(GraphicsDevice));
|
||||||
|
|
||||||
float scale = 1;
|
float scale = 1;
|
||||||
if (name == "spineboy") scale = 0.6f;
|
if (name == "spineboy-ess") scale = 0.6f;
|
||||||
if (name == "raptor") scale = 0.5f;
|
if (name == "raptor-pro") scale = 0.5f;
|
||||||
if (name == "tank") scale = 0.3f;
|
if (name == "tank-pro") scale = 0.3f;
|
||||||
if (name == "TwoColorTest") scale = 0.5f;
|
if (name == "coin-pro") scale = 1;
|
||||||
|
|
||||||
SkeletonData skeletonData;
|
SkeletonData skeletonData;
|
||||||
if (binaryData) {
|
if (binaryData) {
|
||||||
SkeletonBinary binary = new SkeletonBinary(atlas);
|
SkeletonBinary binary = new SkeletonBinary(atlas);
|
||||||
binary.Scale = scale;
|
binary.Scale = scale;
|
||||||
skeletonData = binary.ReadSkeletonData(assetsFolder + name + ".skel");
|
skeletonData = binary.ReadSkeletonData(assetsFolder + name + ".skel");
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
SkeletonJson json = new SkeletonJson(atlas);
|
SkeletonJson json = new SkeletonJson(atlas);
|
||||||
json.Scale = scale;
|
json.Scale = scale;
|
||||||
skeletonData = json.ReadSkeletonData(assetsFolder + name + ".json");
|
skeletonData = json.ReadSkeletonData(assetsFolder + name + ".json");
|
||||||
}
|
}
|
||||||
skeleton = new Skeleton(skeletonData);
|
skeleton = new Skeleton(skeletonData);
|
||||||
if (name == "goblins-mesh") skeleton.SetSkin("goblin");
|
if (name == "goblins-pro") skeleton.SetSkin("goblin");
|
||||||
|
|
||||||
// Define mixing between animations.
|
// Define mixing between animations.
|
||||||
AnimationStateData stateData = new AnimationStateData(skeleton.Data);
|
AnimationStateData stateData = new AnimationStateData(skeleton.Data);
|
||||||
state = new AnimationState(stateData);
|
state = new AnimationState(stateData);
|
||||||
|
|
||||||
if (name == "spineboy") {
|
if (name == "spineboy-ess") {
|
||||||
stateData.SetMix("run", "jump", 0.2f);
|
stateData.SetMix("run", "jump", 0.2f);
|
||||||
stateData.SetMix("jump", "run", 0.4f);
|
stateData.SetMix("jump", "run", 0.4f);
|
||||||
|
|
||||||
@ -123,41 +112,36 @@ namespace Spine {
|
|||||||
entry.End += End; // Event handling for queued animations.
|
entry.End += End; // Event handling for queued animations.
|
||||||
state.AddAnimation(0, "run", true, 0);
|
state.AddAnimation(0, "run", true, 0);
|
||||||
}
|
}
|
||||||
else if (name == "raptor") {
|
else if (name == "raptor-pro") {
|
||||||
state.SetAnimation(0, "walk", true);
|
state.SetAnimation(0, "walk", true);
|
||||||
state.AddAnimation(1, "gungrab", false, 2);
|
state.AddAnimation(1, "gungrab", false, 2);
|
||||||
}
|
}
|
||||||
else if (name == "coin") {
|
else if (name == "coin-pro") {
|
||||||
state.SetAnimation(0, "rotate", true);
|
state.SetAnimation(0, "rotate", true);
|
||||||
}
|
}
|
||||||
else if (name == "tank") {
|
else if (name == "tank-pro") {
|
||||||
state.SetAnimation(0, "drive", true);
|
state.SetAnimation(0, "drive", true);
|
||||||
}
|
}
|
||||||
else if (name == "TwoColorTest") {
|
else {
|
||||||
state.SetAnimation(0, "animation", true);
|
|
||||||
} else {
|
|
||||||
state.SetAnimation(0, "walk", true);
|
state.SetAnimation(0, "walk", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
skeleton.X = 400 + (name == "tank" ? 300: 0);
|
skeleton.X = 400 + (name == "tank-pro" ? 300 : 0);
|
||||||
skeleton.Y = 580 + (name == "TwoColorTest" ? -300 : 0);
|
skeleton.Y = GraphicsDevice.Viewport.Height;
|
||||||
skeleton.UpdateWorldTransform();
|
skeleton.UpdateWorldTransform();
|
||||||
|
|
||||||
headSlot = skeleton.FindSlot("head");
|
headSlot = skeleton.FindSlot("head");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void UnloadContent () {
|
protected override void Update(GameTime gameTime) {
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Update (GameTime gameTime) {
|
|
||||||
base.Update(gameTime);
|
base.Update(gameTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Draw (GameTime gameTime) {
|
protected override void Draw(GameTime gameTime) {
|
||||||
GraphicsDevice.Clear(Color.Black);
|
GraphicsDevice.Clear(Color.Black);
|
||||||
|
|
||||||
state.Update(gameTime.ElapsedGameTime.Milliseconds / 1000f);
|
state.Update(gameTime.ElapsedGameTime.Milliseconds / 1000f);
|
||||||
state.Apply(skeleton);
|
state.Apply(skeleton);
|
||||||
skeleton.UpdateWorldTransform();
|
skeleton.UpdateWorldTransform();
|
||||||
if (skeletonRenderer.Effect is BasicEffect) {
|
if (skeletonRenderer.Effect is BasicEffect) {
|
||||||
((BasicEffect)skeletonRenderer.Effect).Projection = Matrix.CreateOrthographicOffCenter(0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, 1, 0);
|
((BasicEffect)skeletonRenderer.Effect).Projection = Matrix.CreateOrthographicOffCenter(0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, 1, 0);
|
||||||
@ -186,19 +170,19 @@ namespace Spine {
|
|||||||
base.Draw(gameTime);
|
base.Draw(gameTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Start (TrackEntry entry) {
|
public void Start(TrackEntry entry) {
|
||||||
Console.WriteLine(entry + ": start");
|
Console.WriteLine(entry + ": start");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void End (TrackEntry entry) {
|
public void End(TrackEntry entry) {
|
||||||
Console.WriteLine(entry + ": end");
|
Console.WriteLine(entry + ": end");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Complete (TrackEntry entry) {
|
public void Complete(TrackEntry entry) {
|
||||||
Console.WriteLine(entry + ": complete ");
|
Console.WriteLine(entry + ": complete ");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Event (TrackEntry entry, Event e) {
|
public void Event(TrackEntry entry, Event e) {
|
||||||
Console.WriteLine(entry + ": event " + e);
|
Console.WriteLine(entry + ": event " + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user