Flixel Forums

development => help => Topic started by: Yuuji on Mon, Nov 2, 2015

Title: Down scaling image
Post by: Yuuji on Mon, Nov 2, 2015
I recently started working on my flixel project again and need help scaling down my background image. I essentially plan on scaling the image down to the same size as games width/height but for now when I try scaling it down by 0.5 it doesnt draw the background (the background is black) but when I do 0.6 its fine.

Code: [Select]
        backgroundSprite = new FlxSprite(0, 0, backgroundPath);

        backgroundSprite.scale.x = 0.5f;
        backgroundSprite.scale.y = 0.5f;


Edit: Just noticed when BOTH scale.x and scale.y are equal to or less than 0.5 it turns black but if i do

Code: [Select]
        backgroundSprite.scale.x = 0.6f;
        backgroundSprite.scale.y = 0.4f;

then its not black but unfortunately this doesnt help my case

I found the cause but not sure how to fix it

in FlxSprite.draw()

Code: [Select]

I assume I need to update offsets but not sure what to update to :/
Title: Re: Down scaling image
Post by: Yuuji on Tue, Nov 3, 2015
After looking at this https://github.com/HaxeFlixel/flixel/commit/20622a5d677a386d14efd52502876d5a1a54f994

Code: [Select]
* Helper function to set the graphic's dimenions by using scale, allowing you to keep the current aspect ratio
* should one of the Integers be <= 0. Also updates the sprite's hitbox, offset and origin for you by default!
* @param width How wide the graphic should be. If <= 0, and a Height is set, the aspect ratio will be kept.
* @param height How high the graphic should be. If <= 0, and a Width is set, the aspect ratio will be kept.
public void setGraphicDimensions(float width, float height, boolean updateHitBox)
if (width <= 0 && height <= 0) {

float newScaleX = width / (float) frameWidth;
float newScaleY = height / (float) frameHeight;

scale.make(newScaleX, newScaleY);

if (width <= 0) {
scale.x = newScaleY;
else if (height <= 0) {
scale.y = newScaleX;

if (updateHitBox)
float newWidth = scale.x * (float) frameWidth;
float newHeight = scale.y * (float) frameHeight;

this.width = newWidth;
this.height = newHeight;

offset.make(-((newWidth - (float) frameWidth) * 0.5f), -((newHeight - (float) frameHeight) * 0.5f));

and called it with the dimensions I wanted and it works fine (for now :p). I think I didnt mess up anywhere
Title: Down scaling image
Post by: nesterdron on Wed, Apr 5, 2017
Its blocked because image shack doesnt support niho :3