Stage scaling - sprite disappears

Hi!

I’m having a bit of a problem…
In my main Game class i have the following code for scaling the game depending on fullscreen or not
(Resize event)

scaleX = Lib.current.stage.stageWidth / _stageBaseWidth // 800;
scaleY = Lib.current.stage.stageHeight / _stageBaseHeight //480;

Each time a level is completed i run the following function:

private function initNewStage(): Void {
        _stage = null;
        removeChild(_stage);
        _level += 1;
        _stage = new Stage(_line, _background, this);
        addChild(_stage);
}

Now, if i start the game in window mode it’s fine. But when i switch to fullscreen and a new level is initialized, the sprites inside the stage class disappears - yet their x/y positions remain the same. Shouldn’t the scaling keep them in the same position?

The stage class populates a list of class Dot

class Dot extends Sprite
{
    private var distanceFromCenter:Float;
    private var angle:Float;
    private var angleIncrement:Float;
    public function new(_line: Line) 
    {
        super();
        var svg = new SVG (Assets.getText ("img/Dot.svg"));
        svg.render (graphics);    
        this.x = _line.x + Math.floor(Math.random() * _line.width);
        this.y = Lib.current.stage.stageHeight / 2 - (this.height / 2 - 2);
    }   
}

It is this Dot class that disappears when i switch between fullscreen & window-mode.
It’s still on the screen but it’s being drawn outside the viewport.

Sorry for the wall of text. I hope it makes sense :stuck_out_tongue:

Bumping this one - Still havn’t figured it out. Are there a better approach for scaling the scene?

Let’s say your fullscreen height is 1250 pixels. Your Dots will position themselves at 1250 / 2 - (this.height / 2 - 2), which is a bit less than 625.

Meanwhile, your scaling code multiplies all y values by about 2.6. So 625 becomes 1628, which is well below the bottom of your 1250-pixel screen.

Why don’t you change the Dot code to this?

this.y = Game._stageBaseWidth - (this.height / 2 - 2);