diff --git a/v3/src/gameobjects/image/Image.js b/v3/src/gameobjects/image/Image.js index 3945cd821..89cb5b620 100644 --- a/v3/src/gameobjects/image/Image.js +++ b/v3/src/gameobjects/image/Image.js @@ -10,6 +10,7 @@ var Image = new Class({ Components.Alpha, Components.BlendMode, Components.GetBounds, + Components.Origin, Components.ScaleMode, Components.Size, Components.Texture, @@ -26,6 +27,7 @@ var Image = new Class({ this.setTexture(texture, frame); this.setPosition(x, y); + this.setOriginToCenter(); } }); diff --git a/v3/src/gameobjects/image/ImageWebGLRenderer.js b/v3/src/gameobjects/image/ImageWebGLRenderer.js index 93f9a822b..dadd79868 100644 --- a/v3/src/gameobjects/image/ImageWebGLRenderer.js +++ b/v3/src/gameobjects/image/ImageWebGLRenderer.js @@ -13,8 +13,8 @@ var ImageWebGLRenderer = function (renderer, src, interpolationPercentage, camer var frame = src.frame; var alpha = 16777216; var spriteBatch = renderer.spriteBatch; - var anchorX = src.anchorX; - var anchorY = src.anchorY; + // var anchorX = src.anchorX; + // var anchorY = src.anchorY; //var vertexColor = src.color._glTint; var vertexDataBuffer = spriteBatch.vertexDataBuffer; var vertexBufferF32 = vertexDataBuffer.floatView; @@ -35,8 +35,8 @@ var ImageWebGLRenderer = function (renderer, src, interpolationPercentage, camer var d = cameraMatrix[3]; var e = cameraMatrix[4]; var f = cameraMatrix[5]; - var x = width * -anchorX + frame.x; - var y = height * -anchorY + frame.y; + var x = -src.originX + frame.x; + var y = -src.originY + frame.y; var xw = x + width; var yh = y + height; var tx = x * a + y * c + e; diff --git a/v3/src/gameobjects/sprite/Sprite.js b/v3/src/gameobjects/sprite/Sprite.js index 033f139cb..3766f2d7f 100644 --- a/v3/src/gameobjects/sprite/Sprite.js +++ b/v3/src/gameobjects/sprite/Sprite.js @@ -7,12 +7,14 @@ var SpriteRender = require('./SpriteRender'); var Sprite = new Class({ Mixins: [ - Components.Transform, - Components.Texture, - Components.Size, Components.Alpha, Components.BlendMode, + Components.GetBounds, + Components.Origin, Components.ScaleMode, + Components.Size, + Components.Texture, + Components.Transform, Components.Visible, SpriteRender ], @@ -23,8 +25,9 @@ var Sprite = new Class({ { GameObject.call(this, state); - this.setPosition(x, y); this.setTexture(texture, frame); + this.setPosition(x, y); + this.setOriginToCenter(); } }); diff --git a/v3/src/gameobjects/sprite/SpriteWebGLRenderer.js b/v3/src/gameobjects/sprite/SpriteWebGLRenderer.js index 1eb71e427..5810ee8ec 100644 --- a/v3/src/gameobjects/sprite/SpriteWebGLRenderer.js +++ b/v3/src/gameobjects/sprite/SpriteWebGLRenderer.js @@ -13,8 +13,8 @@ var SpriteWebGLRenderer = function (renderer, src, interpolationPercentage, came var frame = src.frame; var alpha = 16777216; var spriteBatch = renderer.spriteBatch; - var anchorX = src.anchorX; - var anchorY = src.anchorY; + // var anchorX = src.anchorX; + // var anchorY = src.anchorY; //var vertexColor = src.color._glTint; var vertexDataBuffer = spriteBatch.vertexDataBuffer; var vertexBufferF32 = vertexDataBuffer.floatView; @@ -35,8 +35,8 @@ var SpriteWebGLRenderer = function (renderer, src, interpolationPercentage, came var d = cameraMatrix[3]; var e = cameraMatrix[4]; var f = cameraMatrix[5]; - var x = width * -anchorX + frame.x; - var y = height * -anchorY + frame.y; + var x = -src.originX + frame.x; + var y = -src.originY + frame.y; var xw = x + width; var yh = y + height; var tx = x * a + y * c + e; diff --git a/v3/src/renderer/canvas/utils/DrawImage.js b/v3/src/renderer/canvas/utils/DrawImage.js index 97c927b1a..11ca6cc26 100644 --- a/v3/src/renderer/canvas/utils/DrawImage.js +++ b/v3/src/renderer/canvas/utils/DrawImage.js @@ -29,8 +29,8 @@ var DrawImage = function (src, camera) // ctx[this.smoothProperty] = (source.scaleMode === ScaleModes.LINEAR); } - var dx = frame.x - (src.anchorX * frame.width) - camera.scrollX; - var dy = frame.y - (src.anchorY * frame.height) - camera.scrollY; + var dx = frame.x - src.originX - camera.scrollX; + var dy = frame.y - src.originY - camera.scrollY; ctx.save(); ctx.translate(src.x, src.y);