开发者

Scalling FlashPunk game for fullscreen

开发者 https://www.devze.com 2023-03-04 04:07 出处:网络
I\'m making a Flash game with FlashPunk. When I press Ctrl+F Flash goes fullscreen but the game st开发者_开发百科ays at the original size, aligned to the top-left corner.

I'm making a Flash game with FlashPunk. When I press Ctrl+F Flash goes fullscreen but the game st开发者_开发百科ays at the original size, aligned to the top-left corner.

How can I specify to FlashPunk that I want the game scalled to the size of the screen? (keeping aspect ratio, off course)

Thanks


You can control scaling in OBJECT attributes when you embed the Flash into HTML. Use scale=default to scale maintain aspect ratio. When you run the Flash in player, use menu item View->Show All which functions same as scale=default in OBJECT in HTML.


Scaling your flash movie will decrease performance significantly. I urge you not to do this for any reason. I'm not sure what flash punk is, but try using this:

stage.scaleMode = StageScaleMode.SHOW_ALL;


You could hook into the resize event and scale it in code

//put this in your initialization method

stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.addEventListener(Event.RESIZE, onResize); 
stage.dispatchEvent(new Event(Event.RESIZE));


public function onResize(event:Event=null):void
{       

    width = stage.stageWidth;
    height = stage.stageHeight;

    if (scaleX < scaleY)
        scaleY = scaleX;
    else
        scaleX = scaleY;

}


The best way to do this, is to override the setStageProperties public function in your main class (in FlashPunk, your main class should be extending the Engine class)

override public function setStageProperties():void 
{
    super.setStageProperties();
    stage.scaleMode = StageScaleMode.SHOW_ALL;
}


Take a look at the FP class in flashpunk. Specifically FP.screen.scale which lets you resize your entire game by a specified factor. For example, the code below will double the size of your game screen:

FP.screen.scale = 2;

If you need to worry about the aspect ratio, you can do X and Y separately with:

FP.screen.scaleY = 2;
FP.screen.scaleX = 3;

After you go to fullscreen, you can use the code below to get the correct aspect ratio for enlarging your screen:

  var scaleFactorX = stage.stageWidth / FP.screen.width;
  var scaleFactorY = stage.stageHeight / FP.screen.height;
  FP.screen.scaleX = scaleFactorX;
  FP.screen.scaleY = scaleFactorY;
0

精彩评论

暂无评论...
验证码 换一张
取 消