Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Best way to scale for mobile when blitting with copyPixels?

New Here ,
May 21, 2014 May 21, 2014

A game that I'm working on is set at 640x360. For the desktop version, I allow the user to double or triple the size of the window. This can be done easily by using Stage.nativeWindow.width and Stage.nativeWindow.height. I don't have to worry about scaling since everything scales up to fill the entire window when the resizing occurs.

I'm having difficulty figuring out how to scale this 640x360 game to fill the entire screen of a mobile device. There is no option in copyPixels that allows me to scale before blitting, so if I wanted to resize my game to fill the screen on a phone, I believe that my best bet would be to manually scale everything to fill the screen while keeping the aspect ratio intact.

640x360 is a 16:9 aspect ratio. My Nexus 4 lies somewhere between 15:9 and 16:9. So, if I scale my game to fill the Nexus' screen, it would end up being a little wide. To center it, everything would have to be moved a bit to the left (the sides would be cut off, which is fine).

Is there a way to manually control the built-in scaling system (the one used to automatically resize everything in the desktop version) to resize everything according to a scale that I calculate and then center everything on the screen?

Is what I am trying to do even possible, or should I be taking a different approach?

TOPICS
ActionScript
499
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
May 22, 2014 May 22, 2014

Years ago I found that the native stage scale in Flash is not very reliable and discovered that using fullScreenSourceRect as a kind of mediator gave me better results.

can´t be sure though that it works in AIR on mobile. Maybe its worth a shot?

function goScaledFullScreen() {

    var screenRectangle:Rectangle=new Rectangle(0,0,stage.stageWidth,stage.stageHeight);

    stage.fullScreenSourceRect=screenRectangle;

    stage.displayState=StageDisplayState.FULL_SCREEN;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 23, 2014 May 23, 2014

This is pretty much what I was looking for. Unfortunately, it only works on the desktop, not on mobile (or at least, not on Android). I did find something that worked - ScaleMode.NO_BORDER. It scaled everything up, centered things, and cut off whatever was to the right and left in order to keep the original aspect ration intact.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 22, 2014 May 22, 2014

draw() or drawWithQuality() allow you to use a transformation matrix. Because they're slower than copyPixels(), you may want to consider creating an initial resource using one of the draw methods and thereafter using copyPixels().

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 23, 2014 May 23, 2014
LATEST

Thanks for the suggestions. I will try using draw(). If there is a noticeable performance hit, I will try creating a new BitmapData and drawing a resized version of the entire spritesheet onto it so that I can continue using copyPixels().

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines