Getting window dimensions(not stage ones)[SOLVED]


(billy2000) #1

When i am playing a .swf i can modify window dimensions. I want to align the stage so it will always be on center whatever window dimensions would be . But i don’t know how to access those dimension to do so. Any ideas? Thx.


(Bora Kasap) #2

so you don’t wanna let people scale your game like fullscreen or widescreen etc…? then one more question, really you need to do that for window dimensions or page dimensions? because at the end of this you’re gonna publish it on pages, not on window? unless you let be downloadable?


(billy2000) #3

Dude please simply tell me how can i get this value in AS3.Because Some people are smart and will download the game and + i learn more about tricks in AS3 ,and that’s what i want .


(Abel Toy) #4

You can’t move the stage or get the window’s dimensions.

You could use the stage.align property, but it doesn’t allow a full center.

What you can do is listen to the resize event in your Engine class, and place it accordingly. Something like this:

This goes to your main class, the one that extends Engine.

override public function init():void
{
    stage.addEventListener(Event.RESIZE, onStageResize);
}

protected function onStageResize():void
{
    x = (stage.stageWidth - FP.width) * 0.5;
    y = (stage.stageHeight - FP.height) * 0.5;
}

I haven’t tested this code, but it should work.

Good luck! Tell me if it worked for you.


(billy2000) #5

I tried stage.align and you are right. I also tried your code and sadly it the same as a TOP_LEFT align. All i find that seems to work abit is this

stage.align="";

But if the stage is bigger than the window dimensions it will not center so well. Any other solutions? Thx.


(billy2000) #6

I managed to fully center it by calculateing the difference between stage’s width and project’s width and found 135 pixels. and all i did is this in the main’s init:

FP.screen.x-=135;
stage.align = "";