0

I'm currently porting a Flash game to OUYA (an Android powered device) via Adobe Air.

Most of the work has been done already; it's packaged up and runs on Android devices.

However! It's stuck in a tiny corner on the screen, as seen in this picture

What I want is for the game to scale to the full size of the screen, while keeping the aspect ratio. I've seen other Flash to Air to Android games do this, so I know it's possible, I just don't know how.

Anyone have any tips? Thanks!

Bob
  • 55
  • 1
  • 9

2 Answers2

1

Read up on stage.scaleMode:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Stage.html#scaleMode

That should be exactly what you need.

Another option to preserve aspect ratio is if you have a parent container that holds everything is scale it to fit yourself:

var widthRatio:Number = stage.stageWidth / BASE_WIDTH;
var heightRatio:Number = stage.stageHeight / BASE_HEIGHT;

if (widthRatio < heightRatio)
{
    container.scaleX = container.scaleY = widthRatio;
}
else
{
    container.scaleX = container.scaleY = heightRatio;
}

At that point you could either center the container to the stage:

container.x = (stage.stageWidth - container.width) /2;
container.y = (stage.stageHeight - container.height) / 2;

Or do something else with it.

Nabren
  • 582
  • 1
  • 7
  • 17
  • Does `scaleMode` have any effect on mobile apps? I don't think it does, though I could be wrong on that (and I won't be able to test until morning). Regardless, I think you are near to the correct idea here. The original game may have been built with scaling in mind and mobile apps may not scale. The game may need to be remade so it scales itself (which is how it should have been done in the first place if it wasn't, honestly) – Josh Oct 10 '13 at 05:29
  • This gives a bit more information: http://www.adobe.com/devnet/air/articles/multiple-screen-sizes.html. That article states you have to use NO_SCALE to get a resize event if you want to resize yourself so that seems to suggest it would work in a mobile setting. Beyond that, the article also talks about some other methods as well. – Nabren Oct 10 '13 at 14:10
  • In the event you don't use scaleMode, see the second solution I provided in the original answer. That solution will allow it to be a different size while filling the screen as much as possible while preserving aspect ratio. If you want it to remain the same relative size regardless of screen, scale based on dpi instead. The above article explains that case. – Nabren Oct 10 '13 at 14:37
  • Turns out all I needed to make it work were these two lines of code: 'code' stage.scaleMode = StageScaleMode.SHOW_ALL; stage.align = ""; – Bob Oct 15 '13 at 13:14
0

Turns out all I needed to make it work were these two lines of code:

stage.scaleMode = StageScaleMode.SHOW_ALL;
stage.align = "";
Bob
  • 55
  • 1
  • 9