diff --git a/game/addons/tools/Code/Assets/PreviewSprite.cs b/game/addons/tools/Code/Assets/PreviewSprite.cs index d094d2ae..d9b0ce9d 100644 --- a/game/addons/tools/Code/Assets/PreviewSprite.cs +++ b/game/addons/tools/Code/Assets/PreviewSprite.cs @@ -45,8 +45,19 @@ class PreviewSprite : AssetPreview public override void UpdateScene( float cycle, float timeStep ) { + var texture = spriteRenderer.Texture; + if ( texture.Width == 0 || texture.Height == 0 ) + return; + var ratio = (float)texture.Width / texture.Height; var pivotOffset = new Vector2( 0.5f, 0.5f ) - (CurrentAnimation?.Origin ?? new Vector2( 0.5f, 0.5f )); - PrimaryObject.WorldPosition = new Vector3( 0, pivotOffset.x, pivotOffset.y ) * 16; + if ( ratio > 1 ) + { + PrimaryObject.WorldPosition = new Vector3( 0, pivotOffset.x, pivotOffset.y / ratio ) * 16; + } + else + { + PrimaryObject.WorldPosition = new Vector3( 0, pivotOffset.x * ratio, pivotOffset.y ) * 16; + } spriteRenderer.TextureFilter = FilterMode; diff --git a/game/addons/tools/Code/Editor/SpriteEditor/Preview.cs b/game/addons/tools/Code/Editor/SpriteEditor/Preview.cs index 5fc4c2c5..2bf8f0f3 100644 --- a/game/addons/tools/Code/Editor/SpriteEditor/Preview.cs +++ b/game/addons/tools/Code/Editor/SpriteEditor/Preview.cs @@ -94,10 +94,23 @@ public class Preview : Widget private void ScenePreFrame() { - var originOffset = new Vector2( 0.5f, 0.5f ) - (SpriteEditor?.SelectedAnimation?.Origin ?? new Vector2( 0.5f, 0.5f )); - Renderer.WorldPosition = Renderer.WorldPosition - .WithY( originOffset.x * 100 ) - .WithZ( originOffset.y * 100 ); + var texture = Renderer.Texture; + if ( texture.Width == 0 || texture.Height == 0 ) + return; + var ratio = (float)texture.Width / texture.Height; + var pivotOffset = new Vector2( 0.5f, 0.5f ) - (SpriteEditor?.SelectedAnimation?.Origin ?? new Vector2( 0.5f, 0.5f )); + if ( ratio > 1 ) + { + Renderer.WorldPosition = Renderer.WorldPosition + .WithY( pivotOffset.x * 100 ) + .WithZ( pivotOffset.y * 100 / ratio ); + } + else + { + Renderer.WorldPosition = Renderer.WorldPosition + .WithY( pivotOffset.x * 100 * ratio ) + .WithZ( pivotOffset.y * 100 ); + } switch ( SpriteEditor?.Antialiasing ) {