|
@@ -39,6 +39,7 @@ namespace Spine {
|
|
protected SkeletonRenderer skeletonRenderer;
|
|
protected SkeletonRenderer skeletonRenderer;
|
|
private MouseState lastMouseState;
|
|
private MouseState lastMouseState;
|
|
protected Boolean mouseClicked = false;
|
|
protected Boolean mouseClicked = false;
|
|
|
|
+ protected Point mousePos;
|
|
|
|
|
|
public Screen (Example game) {
|
|
public Screen (Example game) {
|
|
this.game = game;
|
|
this.game = game;
|
|
@@ -50,6 +51,7 @@ namespace Spine {
|
|
MouseState state = Mouse.GetState();
|
|
MouseState state = Mouse.GetState();
|
|
mouseClicked = lastMouseState.LeftButton == ButtonState.Pressed && state.LeftButton == ButtonState.Released;
|
|
mouseClicked = lastMouseState.LeftButton == ButtonState.Pressed && state.LeftButton == ButtonState.Released;
|
|
lastMouseState = state;
|
|
lastMouseState = state;
|
|
|
|
+ mousePos = lastMouseState.Position;
|
|
}
|
|
}
|
|
|
|
|
|
public abstract void Render (float deltaTime);
|
|
public abstract void Render (float deltaTime);
|
|
@@ -89,8 +91,8 @@ namespace Spine {
|
|
// Update the animation state and apply the animations
|
|
// Update the animation state and apply the animations
|
|
// to the skeleton
|
|
// to the skeleton
|
|
state.Update(deltaTime);
|
|
state.Update(deltaTime);
|
|
- state.Apply(skeleton);
|
|
|
|
skeleton.Update(deltaTime);
|
|
skeleton.Update(deltaTime);
|
|
|
|
+ state.Apply(skeleton);
|
|
|
|
|
|
// Update the transformations of bones and other parts of the skeleton
|
|
// Update the transformations of bones and other parts of the skeleton
|
|
skeleton.UpdateWorldTransform(Skeleton.Physics.Update);
|
|
skeleton.UpdateWorldTransform(Skeleton.Physics.Update);
|
|
@@ -143,8 +145,8 @@ namespace Spine {
|
|
|
|
|
|
public override void Render (float deltaTime) {
|
|
public override void Render (float deltaTime) {
|
|
state.Update(deltaTime);
|
|
state.Update(deltaTime);
|
|
- state.Apply(skeleton);
|
|
|
|
skeleton.Update(deltaTime);
|
|
skeleton.Update(deltaTime);
|
|
|
|
+ state.Apply(skeleton);
|
|
|
|
|
|
skeleton.UpdateWorldTransform(Skeleton.Physics.Update);
|
|
skeleton.UpdateWorldTransform(Skeleton.Physics.Update);
|
|
|
|
|
|
@@ -201,8 +203,8 @@ namespace Spine {
|
|
|
|
|
|
public override void Render (float deltaTime) {
|
|
public override void Render (float deltaTime) {
|
|
state.Update(deltaTime);
|
|
state.Update(deltaTime);
|
|
- state.Apply(skeleton);
|
|
|
|
skeleton.Update(deltaTime);
|
|
skeleton.Update(deltaTime);
|
|
|
|
+ state.Apply(skeleton);
|
|
|
|
|
|
skeleton.UpdateWorldTransform(Skeleton.Physics.Update);
|
|
skeleton.UpdateWorldTransform(Skeleton.Physics.Update);
|
|
|
|
|
|
@@ -213,7 +215,7 @@ namespace Spine {
|
|
skeletonRenderer.Draw(skeleton);
|
|
skeletonRenderer.Draw(skeleton);
|
|
skeletonRenderer.End();
|
|
skeletonRenderer.End();
|
|
|
|
|
|
- if (mouseClicked) game.currentScreen = new MixAndMatchScreen(game);
|
|
|
|
|
|
+ if (mouseClicked) game.currentScreen = new PhysicsScreenCelestial(game);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -262,10 +264,10 @@ namespace Spine {
|
|
|
|
|
|
public override void Render (float deltaTime) {
|
|
public override void Render (float deltaTime) {
|
|
state.Update(deltaTime);
|
|
state.Update(deltaTime);
|
|
- state.Apply(skeleton);
|
|
|
|
skeleton.Update(deltaTime);
|
|
skeleton.Update(deltaTime);
|
|
|
|
+ state.Apply(skeleton);
|
|
|
|
|
|
- skeleton.UpdateWorldTransform(Skeleton.Physics.Pose);
|
|
|
|
|
|
+ skeleton.UpdateWorldTransform(Skeleton.Physics.Update);
|
|
|
|
|
|
game.GraphicsDevice.Clear(Color.Black);
|
|
game.GraphicsDevice.Clear(Color.Black);
|
|
((BasicEffect)skeletonRenderer.Effect).Projection = Matrix.CreateOrthographicOffCenter(0, game.GraphicsDevice.Viewport.Width, game.GraphicsDevice.Viewport.Height, 0, 1, 0);
|
|
((BasicEffect)skeletonRenderer.Effect).Projection = Matrix.CreateOrthographicOffCenter(0, game.GraphicsDevice.Viewport.Width, game.GraphicsDevice.Viewport.Height, 0, 1, 0);
|
|
@@ -278,6 +280,110 @@ namespace Spine {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// The physics screen Cloud Pot demonstrates Physics Constraints introduced in Spine 4.2
|
|
|
|
+ /// using the cloud-pot skeleton.
|
|
|
|
+ /// </summary>
|
|
|
|
+ internal class PhysicsScreenCloudPot : Screen {
|
|
|
|
+ Atlas atlas;
|
|
|
|
+ Skeleton skeleton;
|
|
|
|
+ AnimationState state;
|
|
|
|
+
|
|
|
|
+ public PhysicsScreenCloudPot (Example game) : base(game) {
|
|
|
|
+ atlas = new Atlas("data/cloud-pot.atlas", new XnaTextureLoader(game.GraphicsDevice));
|
|
|
|
+
|
|
|
|
+ SkeletonBinary binary = new SkeletonBinary(atlas);
|
|
|
|
+ binary.Scale = 0.15f;
|
|
|
|
+ SkeletonData skeletonData = binary.ReadSkeletonData("data/cloud-pot.skel");
|
|
|
|
+
|
|
|
|
+ skeleton = new Skeleton(skeletonData);
|
|
|
|
+ AnimationStateData stateData = new AnimationStateData(skeleton.Data);
|
|
|
|
+ state = new AnimationState(stateData);
|
|
|
|
+
|
|
|
|
+ skeleton.X = game.GraphicsDevice.Viewport.Width / 2;
|
|
|
|
+ skeleton.Y = game.GraphicsDevice.Viewport.Height * 2f / 3f;
|
|
|
|
+
|
|
|
|
+ state.SetAnimation(0, "playing-in-the-rain", true);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public override void Render (float deltaTime) {
|
|
|
|
+ Vector2 position = mousePos.ToVector2();
|
|
|
|
+ skeleton.X = position.X;
|
|
|
|
+ skeleton.Y = position.Y;
|
|
|
|
+
|
|
|
|
+ state.Update(deltaTime);
|
|
|
|
+ skeleton.Update(deltaTime);
|
|
|
|
+ // Note: if you are not directly modifying skeleton.X or .Y, you can apply external
|
|
|
|
+ // physics movement via the following line:
|
|
|
|
+ // skeleton.PhysicsTranslate(externalPositionDelta.x, externalPositionDelta.y);
|
|
|
|
+
|
|
|
|
+ state.Apply(skeleton);
|
|
|
|
+ skeleton.UpdateWorldTransform(Skeleton.Physics.Update);
|
|
|
|
+
|
|
|
|
+ game.GraphicsDevice.Clear(Color.Black);
|
|
|
|
+ ((BasicEffect)skeletonRenderer.Effect).Projection = Matrix.CreateOrthographicOffCenter(0, game.GraphicsDevice.Viewport.Width, game.GraphicsDevice.Viewport.Height, 0, 1, 0);
|
|
|
|
+
|
|
|
|
+ skeletonRenderer.Begin();
|
|
|
|
+ skeletonRenderer.Draw(skeleton);
|
|
|
|
+ skeletonRenderer.End();
|
|
|
|
+
|
|
|
|
+ if (mouseClicked) game.currentScreen = new MixAndMatchScreen(game);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// The physics screen Celestial demonstrates Physics Constraints introduced in Spine 4.2
|
|
|
|
+ /// using the celestial-circus skeleton.
|
|
|
|
+ /// </summary>
|
|
|
|
+ internal class PhysicsScreenCelestial : Screen {
|
|
|
|
+ Atlas atlas;
|
|
|
|
+ Skeleton skeleton;
|
|
|
|
+ AnimationState state;
|
|
|
|
+ Vector2 previousPosition;
|
|
|
|
+
|
|
|
|
+ public PhysicsScreenCelestial (Example game) : base(game) {
|
|
|
|
+ atlas = new Atlas("data/celestial-circus.atlas", new XnaTextureLoader(game.GraphicsDevice));
|
|
|
|
+
|
|
|
|
+ SkeletonJson json = new SkeletonJson(atlas);
|
|
|
|
+ json.Scale = 0.15f;
|
|
|
|
+ SkeletonData skeletonData = json.ReadSkeletonData("data/celestial-circus-pro.json");
|
|
|
|
+
|
|
|
|
+ skeleton = new Skeleton(skeletonData);
|
|
|
|
+ AnimationStateData stateData = new AnimationStateData(skeleton.Data);
|
|
|
|
+ state = new AnimationState(stateData);
|
|
|
|
+
|
|
|
|
+ skeleton.X = game.GraphicsDevice.Viewport.Width / 2;
|
|
|
|
+ skeleton.Y = game.GraphicsDevice.Viewport.Height * 2f / 3f;
|
|
|
|
+
|
|
|
|
+ state.SetAnimation(0, "swing", true);
|
|
|
|
+ state.SetAnimation(1, "eyeblink", true);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public override void Render (float deltaTime) {
|
|
|
|
+ Vector2 position = mousePos.ToVector2();
|
|
|
|
+ skeleton.X = position.X;
|
|
|
|
+ skeleton.Y = position.Y;
|
|
|
|
+
|
|
|
|
+ state.Update(deltaTime);
|
|
|
|
+ skeleton.Update(deltaTime);
|
|
|
|
+ // Note: if you are not directly modifying skeleton.X or .Y, you can apply external
|
|
|
|
+ // physics movement via the following line:
|
|
|
|
+ // skeleton.PhysicsTranslate(externalPositionDelta.x, externalPositionDelta.y);
|
|
|
|
+
|
|
|
|
+ state.Apply(skeleton);
|
|
|
|
+ skeleton.UpdateWorldTransform(Skeleton.Physics.Update);
|
|
|
|
+
|
|
|
|
+ game.GraphicsDevice.Clear(Color.Black);
|
|
|
|
+ ((BasicEffect)skeletonRenderer.Effect).Projection = Matrix.CreateOrthographicOffCenter(0, game.GraphicsDevice.Viewport.Width, game.GraphicsDevice.Viewport.Height, 0, 1, 0);
|
|
|
|
+
|
|
|
|
+ skeletonRenderer.Begin();
|
|
|
|
+ skeletonRenderer.Draw(skeleton);
|
|
|
|
+ skeletonRenderer.End();
|
|
|
|
+
|
|
|
|
+ if (mouseClicked) game.currentScreen = new PhysicsScreenCloudPot(game);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
public class Example : Microsoft.Xna.Framework.Game {
|
|
public class Example : Microsoft.Xna.Framework.Game {
|
|
GraphicsDeviceManager graphics;
|
|
GraphicsDeviceManager graphics;
|
|
public Screen currentScreen;
|
|
public Screen currentScreen;
|
|
@@ -292,7 +398,7 @@ namespace Spine {
|
|
}
|
|
}
|
|
|
|
|
|
protected override void LoadContent () {
|
|
protected override void LoadContent () {
|
|
- currentScreen = new MixAndMatchScreen(this);
|
|
|
|
|
|
+ currentScreen = new PhysicsScreenCelestial(this);
|
|
}
|
|
}
|
|
|
|
|
|
protected override void Update (GameTime gameTime) {
|
|
protected override void Update (GameTime gameTime) {
|