Alsware
Alsware

Reputation: 36

HaxeFlixel Dynamic Positioning

To TLDR, I created a Border of seperate sprites that resize using basic drag logic. Within this border, I placed 'content', or various sprites/buttons to design an application like interface.

The issue I've encountered stems from the positioning and scaling. When scaling a sprite, it offsets the X or Y position. To negate this, I set the origin to the inverse of the updated X and Y position. This worked. However, now that I want to update the hitboxes of said sprites and buttons, I can't get it to work whatsoever without throwing off the positioning.

Here is the primary function.

public function updateContentDimensions():Void {
   if (contentGroup == null) return;

   var scaleX = width / contentGroup.width;
   var scaleY = height / contentGroup.height;

   contentGroup.scale.set(scaleX, scaleY);
   contentGroup.setPosition(x, y);
}

Then, when creating a sprite, I use origin.set(-X, -Y);

var colorButton = new FlxButton(colorButtonX, colorButtonY, "");
colorButton.loadGraphic(buttonSprite.pixels);
colorButton.origin.set(-colorButtonX, -colorButtonY);

To negate any offset that scaling creates. If I use updateHitbox() or even offset.set(), the positioning logic no longer works. Any idea on how to resolve this?

Upvotes: 0

Views: 14

Answers (0)

Related Questions