Skip to content

Commit

Permalink
[HaCreator] Fixed an issue with spine objects that does not move, not…
Browse files Browse the repository at this point in the history
… animating.

17thEvent\Spine\0
Hotel Maple - Outside the Hotel
  • Loading branch information
lastbattle committed Apr 14, 2021
1 parent c62ebb3 commit 0914d51
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 73 deletions.
42 changes: 23 additions & 19 deletions HaCreator/MapSimulator/MapObjects/FieldObject/BackgroundItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ public class BackgroundItem : BaseDXDrawableItem
public BackgroundItem(int cx, int cy, int rx, int ry, BackgroundType type, int a, bool front, List<IDXObject> frames, bool flip, int screenMode)
: base(frames, flip)
{
this.LastShiftIncreaseX = Environment.TickCount;
this.LastShiftIncreaseY = Environment.TickCount;
int CurTickCount = Environment.TickCount;

this.LastShiftIncreaseX = CurTickCount;
this.LastShiftIncreaseY = CurTickCount;
this.rx = rx;
this.cx = cx;
this.ry = ry;
Expand Down Expand Up @@ -76,8 +78,10 @@ public BackgroundItem(int cx, int cy, int rx, int ry, BackgroundType type, int a
public BackgroundItem(int cx, int cy, int rx, int ry, BackgroundType type, int a, bool front, IDXObject frame0, bool flip, int screenMode)
: base(frame0, flip)
{
this.LastShiftIncreaseX = Environment.TickCount;
this.LastShiftIncreaseY = Environment.TickCount;
int CurTickCount = Environment.TickCount;

this.LastShiftIncreaseX = CurTickCount;
this.LastShiftIncreaseY = CurTickCount;
this.rx = rx;
this.cx = cx;
this.ry = ry;
Expand Down Expand Up @@ -204,44 +208,44 @@ public override void Draw(SpriteBatch sprite, SkeletonMeshRenderer skeletonMeshR
if (((int) mapRenderResolution & screenMode) != screenMode || disabledBackground) // dont draw if the screenMode isnt for this
return;

IDXObject frame = GetCurrFrame(TickCount);
int X = CalculateBackgroundPosX(frame, mapShiftX, centerX, renderWidth, RenderObjectScaling);
int Y = CalculateBackgroundPosY(frame, mapShiftY, centerY, renderHeight, RenderObjectScaling);
int _cx = cx == 0 ? frame.Width : cx;
int _cy = cy == 0 ? frame.Height : cy;
IDXObject drawFrame = GetCurrFrame(TickCount);
int X = CalculateBackgroundPosX(drawFrame, mapShiftX, centerX, renderWidth, RenderObjectScaling);
int Y = CalculateBackgroundPosY(drawFrame, mapShiftY, centerY, renderHeight, RenderObjectScaling);
int _cx = cx == 0 ? drawFrame.Width : cx;
int _cy = cy == 0 ? drawFrame.Height : cy;

switch (type)
{
default:
break;
case BackgroundType.Regular:
Draw2D(sprite, skeletonMeshRenderer, gameTime, X, Y, frame);
Draw2D(sprite, skeletonMeshRenderer, gameTime, X, Y, drawFrame);
break;
case BackgroundType.HorizontalTiling:
DrawHorizontalCopies(sprite, skeletonMeshRenderer, gameTime, renderWidth, X, Y, _cx, frame);
DrawHorizontalCopies(sprite, skeletonMeshRenderer, gameTime, renderWidth, X, Y, _cx, drawFrame);
break;
case BackgroundType.VerticalTiling:
DrawVerticalCopies(sprite, skeletonMeshRenderer, gameTime, renderHeight, X, Y, _cy, frame);
DrawVerticalCopies(sprite, skeletonMeshRenderer, gameTime, renderHeight, X, Y, _cy, drawFrame);
break;
case BackgroundType.HVTiling:
DrawHVCopies(sprite, skeletonMeshRenderer, gameTime, renderWidth, renderHeight, X, Y, _cx, _cy, frame);
DrawHVCopies(sprite, skeletonMeshRenderer, gameTime, renderWidth, renderHeight, X, Y, _cx, _cy, drawFrame);
break;
case BackgroundType.HorizontalMoving:
DrawHorizontalCopies(sprite, skeletonMeshRenderer, gameTime, renderWidth, X + (int)bgMoveShiftX, Y, _cx, frame);
DrawHorizontalCopies(sprite, skeletonMeshRenderer, gameTime, renderWidth, X + (int)bgMoveShiftX, Y, _cx, drawFrame);
IncreaseShiftX(_cx, TickCount);
break;
case BackgroundType.VerticalMoving:
DrawVerticalCopies(sprite, skeletonMeshRenderer, gameTime, renderHeight, X, Y + (int)bgMoveShiftY, _cy, frame);
DrawVerticalCopies(sprite, skeletonMeshRenderer, gameTime, renderHeight, X, Y + (int)bgMoveShiftY, _cy, drawFrame);
IncreaseShiftY(_cy, TickCount);
break;
case BackgroundType.HorizontalMovingHVTiling:
DrawHVCopies(sprite, skeletonMeshRenderer, gameTime, renderWidth, renderHeight, X + (int)bgMoveShiftX, Y, _cx, _cy, frame);
DrawHVCopies(sprite, skeletonMeshRenderer, gameTime, renderWidth, renderHeight, X + (int)bgMoveShiftX, Y, _cx, _cy, drawFrame);
IncreaseShiftX(_cx, TickCount);
break;
case BackgroundType.VerticalMovingHVTiling:
DrawHVCopies(sprite, skeletonMeshRenderer, gameTime, renderWidth, renderHeight, X, Y + (int)bgMoveShiftY, _cx, _cy, frame);
DrawHVCopies(sprite, skeletonMeshRenderer, gameTime, renderWidth, renderHeight, X, Y + (int)bgMoveShiftY, _cx, _cy, drawFrame);
IncreaseShiftX(_cy, TickCount);
break;
default:
break;
}
}

Expand Down
6 changes: 3 additions & 3 deletions HaSharedLibrary/Render/DX/DXSpineObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ public void DrawBackground(SpriteBatch sprite, SkeletonMeshRenderer skeletonMesh
spineObject.state.Update(gameTime.ElapsedGameTime.Milliseconds / 1000f);
spineObject.state.Apply(spineObject.skeleton);

if (spineObject.skeleton.FlipX != flip || spineObject.skeleton.X != x || spineObject.skeleton.Y != y) // reduce the number of updates
{
//if (spineObject.skeleton.FlipX != flip || spineObject.skeleton.X != x || spineObject.skeleton.Y != y) // reduce the number of updates [removed, recent spine object includes the ones that does not move]
//{
spineObject.skeleton.FlipX = flip;
spineObject.skeleton.X = x; //x + (Width);
spineObject.skeleton.Y = y;//y + (Height / 2);
spineObject.skeleton.UpdateWorldTransform();
}
//}

skeletonMeshRenderer.PremultipliedAlpha = spineObject.spineAnimationItem.PremultipliedAlpha;

Expand Down
60 changes: 9 additions & 51 deletions MapleLib/WzLib/Spine/WzSpineTextureLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,60 +76,18 @@ public void Load(AtlasPage page, string path)
canvasProperty = property;
}

if (canvasProperty != null)
if (canvasProperty != null && graphicsDevice != null)
{
WzCanvasProperty linkImgProperty = (WzCanvasProperty) canvasProperty.GetLinkedWzImageProperty();

WzCanvasProperty linkImgProperty = (WzCanvasProperty)canvasProperty.GetLinkedWzImageProperty();
WzPngProperty pngProperty = linkImgProperty.PngProperty;
SurfaceFormat surfaceFormat = linkImgProperty.PngProperty.GetXNASurfaceFormat();

if (graphicsDevice != null)
{
Texture2D tex;
tex = new Texture2D(graphicsDevice,
pngProperty.Width, pngProperty.Height,
false, surfaceFormat);
/*switch (surfaceFormat)
{
case SurfaceFormat.Bgra4444:
tex = new Texture2D(graphicsDevice,
pngProperty.Width * 2, pngProperty.Height * 2,
false, surfaceFormat);
break;
case SurfaceFormat.Bgra32:
tex = new Texture2D(graphicsDevice,
pngProperty.Width * 4, pngProperty.Height * 4,
false, surfaceFormat);
break;
case SurfaceFormat.Bgr565:
tex = new Texture2D(graphicsDevice,
pngProperty.Width * 2, pngProperty.Height * 2,
false, surfaceFormat);
break;
case SurfaceFormat.Dxt3:
tex = new Texture2D(graphicsDevice,
pngProperty.Width * 4, pngProperty.Height * 4,
false, surfaceFormat);
break;
case SurfaceFormat.Dxt5:
tex = new Texture2D(graphicsDevice,
pngProperty.Width * 4, pngProperty.Height * 4,
false, surfaceFormat);
break;
default:
tex = new Texture2D(graphicsDevice,
pngProperty.Width, pngProperty.Height,
false, surfaceFormat);
break;
}
*/
pngProperty.ParsePng(true, tex);


page.rendererObject = tex;
page.width = pngProperty.Width;
page.height = pngProperty.Height;
}
Texture2D tex = new Texture2D(graphicsDevice, pngProperty.Width, pngProperty.Height, false, linkImgProperty.PngProperty.GetXNASurfaceFormat());

pngProperty.ParsePng(true, tex);

page.rendererObject = tex;
page.width = pngProperty.Width;
page.height = pngProperty.Height;
}
}

Expand Down

0 comments on commit 0914d51

Please sign in to comment.