Skip to content

Commit

Permalink
clamp cels that are larger than the sprite
Browse files Browse the repository at this point in the history
  • Loading branch information
martinhodler committed Jan 20, 2020
1 parent 97c59bb commit 37a057d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions Editor/Aseprite/AseFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,20 @@ public Texture2D GetTextureFromCel(CelChunk cel)
int renderRectHeight = Math.Min(canvasHeight, cel.Height);
Color[] colors = new Color[renderRectWidth * renderRectHeight];

// Sometimes cell width/height can be larger than image (pixels stored off-screen), adjust our rect to fit canvas viewport

// If cel offset is positive, displace the same amount on our texture
int destX = Mathf.Max(0, cel.X);
int destY = Mathf.Max(0, canvasHeight - cel.Height - cel.Y); // Aseprite is upper left origin, Unity textures are lower left, so perform flip


// Sometimes cell width/height can be larger than image (pixels stored off-screen), adjust our rect to fit canvas viewport
if (renderRectWidth + destX > canvasWidth)
{
renderRectWidth -= (renderRectWidth + destX) - canvasWidth;
}
if (renderRectHeight + destY > canvasHeight)
{
renderRectHeight -= (renderRectHeight + destY) - canvasHeight;
}

// If cell offset is negative, displace the same same amount on cel data
int celX = Mathf.Max(0, -cel.X);
int celY = Mathf.Max(0, -cel.Y);
Expand Down

0 comments on commit 37a057d

Please sign in to comment.