Fix positioning of flipped Sprite object with platformer or set X position action

Fix #1194
This commit is contained in:
Florian Rival
2019-08-16 09:28:20 -07:00
parent 9d06da36ed
commit 7d7bde12d0
2 changed files with 16 additions and 4 deletions

View File

@@ -1,6 +1,13 @@
/**
* The renderer for a gdjs.SpriteRuntimeObject using Pixi.js.
* @class SpriteRuntimeObjectPixiRenderer
* @memberof gdjs
* @param {gdjs.SpriteRuntimeObject} runtimeObject The object
* @param {gdjs.RuntimeScene} runtimeScene The scene
*/
gdjs.SpriteRuntimeObjectPixiRenderer = function(runtimeObject, runtimeScene)
{
/** @type gdjs.SpriteRuntimeObject */
this._object = runtimeObject;
this._spriteDirty = true;
this._textureDirty = true;
@@ -67,13 +74,13 @@ gdjs.SpriteRuntimeObjectPixiRenderer.prototype.update = function() {
gdjs.SpriteRuntimeObjectPixiRenderer.prototype.updateX = function() {
this._sprite.position.x = this._object.x + (this._object._animationFrame.center.x - this._object._animationFrame.origin.x)*Math.abs(this._object._scaleX);
if ( this._flippedX )
if ( this._object._flippedX )
this._sprite.position.x += (this._sprite.texture.frame.width/2-this._object._animationFrame.center.x)*Math.abs(this._object._scaleX)*2;
}
gdjs.SpriteRuntimeObjectPixiRenderer.prototype.updateY = function() {
this._sprite.position.y = this._object.y + (this._object._animationFrame.center.y - this._object._animationFrame.origin.y)*Math.abs(this._object._scaleY);
if ( this._flippedY )
if ( this._object._flippedY )
this._sprite.position.y += (this._sprite.texture.frame.height/2-this._object._animationFrame.center.y)*Math.abs(this._object._scaleY)*2;
}

View File

@@ -629,7 +629,8 @@ gdjs.RuntimeScene.prototype.getInitialSharedDataForBehavior = function(name) {
/**
* Get the layer with the given name
* @param {gdjs.Layer} name The name of the layer
* @param {string} name The name of the layer
* @returns {gdjs.Layer} The layer, or the base layer if not found
*/
gdjs.RuntimeScene.prototype.getLayer = function(name) {
if ( this._layers.containsKey(name) )
@@ -638,6 +639,10 @@ gdjs.RuntimeScene.prototype.getLayer = function(name) {
return this._layers.get("");
};
/**
* Check if a layer exists
* @param {string} name The name of the layer
*/
gdjs.RuntimeScene.prototype.hasLayer = function(name) {
return this._layers.containsKey(name);
};