[monogame] Adjusted monogame examples to 4.2 physics, added new example screens.

This commit is contained in:
Harald Csaszar 2024-03-29 17:08:35 +01:00
parent 36a1a1742b
commit ff4cfbaa05
25 changed files with 4341 additions and 19 deletions

View File

@ -39,6 +39,7 @@ namespace Spine {
protected SkeletonRenderer skeletonRenderer;
private MouseState lastMouseState;
protected Boolean mouseClicked = false;
protected Point mousePos;
public Screen (Example game) {
this.game = game;
@ -50,6 +51,7 @@ namespace Spine {
MouseState state = Mouse.GetState();
mouseClicked = lastMouseState.LeftButton == ButtonState.Pressed && state.LeftButton == ButtonState.Released;
lastMouseState = state;
mousePos = lastMouseState.Position;
}
public abstract void Render (float deltaTime);
@ -89,8 +91,8 @@ namespace Spine {
// Update the animation state and apply the animations
// to the skeleton
state.Update(deltaTime);
state.Apply(skeleton);
skeleton.Update(deltaTime);
state.Apply(skeleton);
// Update the transformations of bones and other parts of the skeleton
skeleton.UpdateWorldTransform(Skeleton.Physics.Update);
@ -143,8 +145,8 @@ namespace Spine {
public override void Render (float deltaTime) {
state.Update(deltaTime);
state.Apply(skeleton);
skeleton.Update(deltaTime);
state.Apply(skeleton);
skeleton.UpdateWorldTransform(Skeleton.Physics.Update);
@ -201,8 +203,8 @@ namespace Spine {
public override void Render (float deltaTime) {
state.Update(deltaTime);
state.Apply(skeleton);
skeleton.Update(deltaTime);
state.Apply(skeleton);
skeleton.UpdateWorldTransform(Skeleton.Physics.Update);
@ -213,7 +215,7 @@ namespace Spine {
skeletonRenderer.Draw(skeleton);
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) {
state.Update(deltaTime);
state.Apply(skeleton);
skeleton.Update(deltaTime);
state.Apply(skeleton);
skeleton.UpdateWorldTransform(Skeleton.Physics.Pose);
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);
@ -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 {
GraphicsDeviceManager graphics;
public Screen currentScreen;
@ -292,7 +398,7 @@ namespace Spine {
}
protected override void LoadContent () {
currentScreen = new MixAndMatchScreen(this);
currentScreen = new PhysicsScreenCelestial(this);
}
protected override void Update (GameTime gameTime) {

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,168 @@
celestial-circus.png
size: 1024, 1024
filter: Linear, Linear
scale: 0.5
arm-back-down
bounds: 944, 3, 48, 103
arm-front-down
bounds: 241, 56, 45, 98
bench
bounds: 2, 94, 237, 60
body-bottom
bounds: 674, 8, 193, 156
rotate: 90
collar
bounds: 822, 352, 59, 33
ear
bounds: 997, 185, 25, 35
eye-back-shadow
bounds: 1004, 978, 18, 12
eye-front-shadow
bounds: 1004, 992, 30, 18
rotate: 90
eye-reflex-back
bounds: 822, 341, 10, 9
eye-reflex-front
bounds: 525, 699, 13, 9
rotate: 90
eye-white-back
bounds: 956, 963, 16, 20
eye-white-front
bounds: 551, 179, 28, 22
eyelashes-down-back
bounds: 980, 325, 14, 7
rotate: 90
eyelashes-down-front
bounds: 979, 1003, 19, 8
rotate: 90
eyelashes-top-back
bounds: 997, 118, 23, 12
rotate: 90
eyelashes-top-front
bounds: 956, 985, 37, 21
rotate: 90
feathers-front
bounds: 2, 2, 90, 108
rotate: 90
fringe-middle-back
bounds: 980, 222, 42, 65
fringe-side-back
bounds: 944, 222, 34, 117
fringe-side-front
bounds: 989, 289, 33, 116
hair-back-1
bounds: 289, 2, 166, 383
rotate: 90
hair-back-2
bounds: 887, 341, 100, 356
hair-back-4
bounds: 832, 11, 110, 328
hair-hat-shadow
bounds: 944, 108, 112, 51
rotate: 90
hat-front
bounds: 112, 22, 121, 70
leg-front
bounds: 554, 699, 323, 400
rotate: 90
logo-brooch
bounds: 505, 170, 20, 31
mouth
bounds: 279, 26, 28, 8
rotate: 90
nose
bounds: 279, 15, 8, 9
nose-highlight
bounds: 551, 171, 5, 6
nose-shadow
bounds: 834, 341, 9, 10
rotate: 90
pupil-back
bounds: 505, 699, 13, 18
rotate: 90
pupil-front
bounds: 112, 5, 15, 22
rotate: 90
rope-back
bounds: 989, 407, 13, 615
rope-front
bounds: 989, 407, 13, 615
skirt
bounds: 2, 714, 550, 308
sock-bow
bounds: 235, 14, 42, 40
spine-logo-body
bounds: 997, 143, 16, 40
star-big
bounds: 527, 171, 22, 30
star-medium
bounds: 1015, 173, 7, 10
star-small
bounds: 674, 2, 4, 6
rotate: 90
underskirt
bounds: 2, 156, 556, 285
rotate: 90
underskirt-back
bounds: 289, 170, 542, 214
rotate: 90
wing-back
bounds: 505, 203, 182, 315
rotate: 90
wing-front
bounds: 505, 387, 380, 310
celestial-circus_2.png
size: 1024, 1024
filter: Linear, Linear
scale: 0.5
arm-back-up
bounds: 490, 683, 104, 145
rotate: 90
arm-front-up
bounds: 162, 23, 96, 145
body-top
bounds: 2, 2, 158, 166
chest
bounds: 744, 878, 130, 117
cloud-back
bounds: 490, 789, 252, 206
cloud-front
bounds: 2, 170, 406, 245
rotate: 90
face
bounds: 876, 879, 116, 128
rotate: 90
feathers-back
bounds: 266, 578, 57, 57
fringe-middle-front
bounds: 260, 105, 75, 63
glove-bottom-back
bounds: 325, 584, 64, 51
glove-bottom-front
bounds: 391, 585, 59, 61
rotate: 90
hair-back-3
bounds: 249, 241, 87, 335
hair-back-5
bounds: 378, 646, 110, 349
hair-back-6
bounds: 266, 637, 110, 358
hand-back
bounds: 573, 622, 75, 59
hand-front
bounds: 637, 712, 67, 75
hat-back
bounds: 260, 23, 80, 56
rotate: 90
head-back
bounds: 744, 768, 128, 108
jabot
bounds: 249, 170, 88, 69
leg-back
bounds: 2, 578, 262, 417
neck
bounds: 338, 511, 49, 71
rope-front-bottom
bounds: 490, 628, 53, 81
rotate: 90

Binary file not shown.

After

Width:  |  Height:  |  Size: 703 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 461 KiB

View File

@ -0,0 +1,85 @@
cloud-pot.png
size: 1024, 512
filter: Linear, Linear
scale: 0.5
cloud-base-1
bounds: 2, 300, 233, 210
cloud-base-10
bounds: 214, 113, 97, 101
cloud-base-2
bounds: 2, 90, 210, 208
cloud-base-3
bounds: 237, 346, 175, 164
cloud-base-4
bounds: 414, 347, 176, 163
cloud-base-5
bounds: 313, 89, 145, 125
cloud-base-6
bounds: 744, 374, 161, 136
cloud-base-7
bounds: 592, 361, 150, 149
cloud-base-8
bounds: 237, 216, 154, 128
cloud-base-9
bounds: 907, 402, 107, 108
cloud-cheeks
bounds: 2, 9, 218, 79
cloud-eyes-closed
bounds: 744, 350, 132, 22
cloud-eyes-open
bounds: 592, 333, 133, 26
cloud-eyes-reflex
bounds: 393, 224, 120, 17
rotate: 90
cloud-mouth-closed
bounds: 907, 374, 49, 16
cloud-mouth-open
bounds: 222, 15, 59, 35
leaf-big
bounds: 214, 218, 20, 49
leaf-small
bounds: 958, 373, 17, 30
rotate: 90
petal-1
bounds: 283, 2, 26, 18
petal-2
bounds: 283, 22, 28, 17
rotate: 90
petal-3
bounds: 214, 269, 29, 21
rotate: 90
pot-base
bounds: 222, 52, 76, 59
pot-eyes-closed
bounds: 878, 363, 46, 9
pot-eyes-open
bounds: 222, 2, 40, 11
pot-mouth-open
bounds: 990, 374, 14, 16
pot-mouth-pouty
bounds: 300, 93, 18, 10
rotate: 90
pot-mouth-smile
bounds: 300, 77, 14, 10
rotate: 90
pot-mouth-smile-big
bounds: 878, 352, 20, 9
rain-blue
bounds: 926, 360, 12, 18
rotate: 90
rain-color
bounds: 264, 4, 9, 17
rotate: 90
rain-green
bounds: 900, 349, 12, 18
rotate: 90
rain-white
bounds: 727, 337, 12, 22
rain-white-reflex
bounds: 2, 2, 5, 10
rotate: 90
stem
bounds: 907, 392, 8, 105
rotate: 90
stem-end
bounds: 300, 62, 13, 13

Binary file not shown.

After

Width:  |  Height:  |  Size: 330 KiB

View File

@ -1,7 +1,7 @@
{
"skeleton": {
"hash": "fKr+fe4rKEk",
"spine": "4.2.43-beta",
"spine": "4.2.56-beta",
"x": -152.5,
"y": -151,
"width": 305,

Binary file not shown.

Before

Width:  |  Height:  |  Size: 359 KiB

After

Width:  |  Height:  |  Size: 364 KiB

View File

@ -1,7 +1,7 @@
{
"skeleton": {
"hash": "4fumZThfQpw",
"spine": "4.2.43-beta",
"spine": "4.2.56-beta",
"x": -240.58,
"y": -3.38,
"width": 410.36,
@ -98,7 +98,7 @@
"rotation": -90.56,
"x": -51.95,
"y": -259.13,
"transform": "noRotationOrReflection",
"inherit": "noRotationOrReflection",
"color": "d130ffff",
"icon": "ik"
},
@ -516,7 +516,7 @@
"rotation": -90.56,
"x": 38.54,
"y": -259.75,
"transform": "noRotationOrReflection",
"inherit": "noRotationOrReflection",
"color": "d130ffff",
"icon": "ik"
},

Binary file not shown.

Before

Width:  |  Height:  |  Size: 341 KiB

After

Width:  |  Height:  |  Size: 338 KiB

View File

@ -1,7 +1,7 @@
{
"skeleton": {
"hash": "FwuU0d2nzEU",
"spine": "4.2.43-beta",
"spine": "4.2.56-beta",
"x": -809.16,
"y": -73.54,
"width": 1287.65,
@ -90,7 +90,7 @@
"rotation": -133.55,
"x": 232.68,
"y": 245.85,
"transform": "noScale",
"inherit": "noScale",
"color": "ff3f00ff"
},
{
@ -174,7 +174,7 @@
"rotation": -6.14,
"x": 84.5,
"y": -0.35,
"transform": "noRotationOrReflection",
"inherit": "noRotationOrReflection",
"color": "e07800ff"
},
{
@ -193,7 +193,7 @@
"rotation": 27.78,
"x": -0.03,
"y": 0.05,
"transform": "noRotationOrReflection",
"inherit": "noRotationOrReflection",
"color": "e07800ff"
},
{ "name": "spineboy-back-foot-target", "parent": "saddle", "x": -30.44, "y": -100.08, "color": "ff3f00ff" },
@ -231,7 +231,7 @@
"rotation": 11.66,
"x": 25.68,
"y": -0.77,
"transform": "noScale",
"inherit": "noScale",
"color": "e7ff00ff"
},
{
@ -364,7 +364,7 @@
"y": -0.02,
"scaleX": 0.731,
"scaleY": 0.823,
"transform": "onlyTranslation",
"inherit": "onlyTranslation",
"color": "15ff00ff"
},
{
@ -395,7 +395,7 @@
"y": -2.77,
"scaleX": 1.0004,
"scaleY": 1.0004,
"transform": "onlyTranslation",
"inherit": "onlyTranslation",
"color": "14ff00ff"
},
{ "name": "spineboy-front-foot-target", "parent": "saddle", "x": -50.71, "y": -96.93, "color": "ff3f00ff" },

View File

@ -0,0 +1,205 @@
snowglobe.png
size: 1024, 1024
filter: Linear, Linear
scale: 0.5
arm-down-r
bounds: 884, 129, 76, 53
arm-up-l
bounds: 718, 23, 49, 114
rotate: 90
arm-up-r
bounds: 867, 69, 58, 104
rotate: 90
blue-present-base
bounds: 884, 883, 126, 139
eye-reflex-l
bounds: 991, 347, 12, 13
eye-reflex-r
bounds: 867, 129, 10, 12
rotate: 90
eye-white-l
bounds: 987, 697, 35, 43
eye-white-r
bounds: 560, 2, 34, 48
eyelashes-l
bounds: 982, 2, 32, 40
gift-base
bounds: 884, 335, 125, 105
rotate: 90
gift-decoration
bounds: 518, 2, 48, 40
rotate: 90
globe-borders
bounds: 2, 141, 880, 881
glove-l
bounds: 982, 44, 40, 61
glove-shadow-l
bounds: 991, 403, 28, 57
glove-shadow-r
bounds: 960, 204, 38, 62
rotate: 90
green-present-base
bounds: 138, 13, 126, 139
rotate: 90
hair-front
bounds: 884, 590, 150, 101
rotate: 90
hair-side
bounds: 995, 574, 27, 53
hair-strand-2
bounds: 987, 629, 26, 66
hair-strand-5
bounds: 690, 7, 25, 47
hair-strand-6
bounds: 995, 507, 14, 35
head-base
bounds: 2, 4, 134, 135
leg-down-l
bounds: 596, 3, 92, 51
leg-up-l
bounds: 718, 74, 65, 147
rotate: 90
leg-up-l-fuzzy
bounds: 834, 2, 73, 65
leg-up-r
bounds: 576, 56, 83, 140
rotate: 90
leg-up-r-fuzzy
bounds: 909, 2, 65, 71
rotate: 90
mouth
bounds: 991, 362, 39, 13
rotate: 90
neck-scarf
bounds: 279, 25, 142, 114
nose
bounds: 995, 488, 17, 14
rotate: 90
nose-shadow
bounds: 299, 8, 15, 15
red-present-base
bounds: 884, 742, 126, 139
scarf-end-l
bounds: 884, 462, 126, 109
rotate: 90
scarf-end-r
bounds: 423, 52, 151, 87
scarf-ribbon-middle-r
bounds: 960, 244, 62, 89
scarf-shadow
bounds: 884, 184, 149, 74
rotate: 90
shoe-l
bounds: 973, 107, 49, 95
shoe-r
bounds: 423, 6, 44, 93
rotate: 90
shoelace
bounds: 279, 2, 21, 18
rotate: 90
snow
bounds: 995, 544, 27, 28
string
bounds: 138, 6, 5, 53
rotate: 90
snowglobe_2.png
size: 1024, 1024
filter: Linear, Linear
scale: 0.5
arm-down-l
bounds: 884, 579, 56, 54
arm-down-l-fuzzy
bounds: 884, 635, 57, 59
arm-down-r-fuzzy
bounds: 884, 696, 61, 66
blue-present-decoration
bounds: 884, 216, 41, 40
green-present-decoration
bounds: 884, 216, 41, 40
ear-l
bounds: 884, 527, 55, 50
ear-r
bounds: 291, 94, 45, 66
rotate: 90
eyelashes-r
bounds: 2, 2, 32, 47
rotate: 90
globe-texture-strong
bounds: 2, 141, 880, 881
glove-fingers-l
bounds: 884, 361, 39, 51
glove-fingers-r
bounds: 884, 469, 41, 56
glove-r
bounds: 76, 36, 44, 65
rotate: 90
hair-strand-1
bounds: 359, 102, 37, 65
rotate: 90
hair-strand-3
bounds: 884, 414, 40, 53
hair-strand-4
bounds: 939, 893, 37, 69
iris-l
bounds: 884, 173, 40, 41
iris-r
bounds: 143, 39, 40, 41
leg-down-r
bounds: 2, 36, 72, 103
pupil-l
bounds: 51, 2, 32, 32
pupil-r
bounds: 85, 2, 32, 32
red-present-decoration
bounds: 426, 99, 41, 40
scarf-pompom-l
bounds: 884, 309, 50, 46
rotate: 90
scarf-pompom-r
bounds: 884, 258, 49, 47
rotate: 90
scarf-ribbon-bottom-l
bounds: 884, 856, 106, 53
rotate: 90
scarf-ribbon-bottom-r
bounds: 76, 82, 105, 57
scarf-ribbon-middle-l
bounds: 884, 764, 63, 90
scarf-ribbon-top-l
bounds: 884, 964, 105, 58
scarf-ribbon-top-r
bounds: 183, 86, 106, 53
snowglobe_3.png
size: 1024, 1024
filter: Linear, Linear
scale: 0.5
globe-texture
bounds: 2, 2, 880, 881
snowglobe_4.png
size: 1024, 1024
filter: Linear, Linear
scale: 0.5
elf-shadow
bounds: 2, 2, 395, 158
globe-reflections
bounds: 2, 162, 646, 835
globe-shadow
bounds: 650, 77, 920, 366
rotate: 90
hat
bounds: 399, 7, 153, 221
rotate: 90
snowglobe_5.png
size: 1024, 1024
filter: Linear, Linear
scale: 0.5
body
bounds: 710, 569, 139, 151
globe-base-back
bounds: 2, 2, 606, 258
globe-base-front
bounds: 2, 262, 706, 458

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1010 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 560 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 523 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 411 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 240 KiB

After

Width:  |  Height:  |  Size: 241 KiB

View File

@ -1,7 +1,7 @@
{
"skeleton": {
"hash": "nW5DL2uoEfA",
"spine": "4.2.43-beta",
"spine": "4.2.56-beta",
"x": -5852.65,
"y": -348.5,
"width": 7202.61,

Binary file not shown.

Before

Width:  |  Height:  |  Size: 458 KiB

After

Width:  |  Height:  |  Size: 463 KiB