iPhone的不同屏幕尺寸在闪光? (获得黑酒吧) [英] iPhone different screen sizes in flash? (Getting Black Bars)

查看:149
本文介绍了iPhone的不同屏幕尺寸在闪光? (获得黑酒吧)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的编程世界,而actionscript 3是我第一个真正的经验,所以对不起,如果我不明白你的答案马上。

我已经在AIR for iOS中使用Adobe Flash CC构建了一个iPhone应用程序。所有的代码是在时间轴上或单独的.as文件(所以不使用文档类)。游戏的核心概念是随机生成的物体从屏幕的顶部落下,用户必须点击它们以使它们在触摸底部之前消失。 / p>

我的问题是我的文档大小是 640 x 960 。我认为这适合iPhone 4(还没有测试过),但是当我在我的iPhone 5s上测试时,我会在顶部和底部找回条形码。显然他们有不同的屏幕尺寸,但我希望应用程序能够运行在许多不同大小的iPhone上。

我已经花了数小时搜索这个,但仍然不明白我的意思。我试着玩了 stage.scaleMode 设置,但没有任何变化。我还添加了一个名为 default-568h@2x.png 的文件(只是一个尺寸为 640 x 1136 )在包含的文件,但这并不显示。

所以基本上我想知道如何更改我的应用程序和AS3代码,以允许我的应用程序适合所有不同尺寸的iPhone?



任何帮助将非常感激。 ,在其他任何事情之前,您需要确保您的项目中包含正确的启动图像。



以下是





缩放内容




  • 选项1,填充和裁剪 >

    如果您不介意修剪您的内容,您可以在应用程序启动时执行此操作:

     在Stage.scaleMode = StageScaleMode.NO_BORDER 

    这样可以缩放你的swf,这样可以在保持宽高比的情况下填充整个屏幕。这是很容易找出多少填充你需要使这种方法适用于各种iPhone的纵横比的小变化。



    然而,如果你想选项2 - 响应式设计 >




尽管适应不同屏幕分辨率和宽高比的最佳方式是让应用程序响应。这涉及到您的应用程序开始时的以下代码:

  stage.scaleMode = StageScaleMode.NO_SCALE; 
stage.align = StageAlign.TOP_LEFT;

现在您的阶段界限( stage.stageWidth & stage.stageHeight )将是设备的全宽和高度*。 (有些设备的底部或顶部带有一个软件工具栏)

然后你可以通过代码来定位。
$ b $如果你想要一个简单的方法来转换你所拥有的东西(你不想使用代码来调整大小和绝对对齐所有的东西),只需把所有的内容放在一个容器MovieClip中,其实例名称为 container ,然后你可以像这样调整大小和位置:

  //将容器尽可能大,而仍然完全适合在屏幕上:

//找出哪个尺寸应与舞台匹配(widht或height)
if(container.width - stage.stageWidth> = container.height - stage.stageHeight){
container.width = stage.stageWidth;
container.scaleY = container.scaleX;
} else {
container.height = stage.stageHeight
container.scaleX = container.scaleY;
}

//将其居中在屏幕上:
container.x =(stage.stageWidth - container.width)* 0.5;
container.y =(stage.stageHeight - container.height)* 0.5;

在屏幕大小发生变化的情况下,侦听大小调整事件也是一个好主意(例如, /在桌面上恢复,或从手机上的肖像到风景)。

您可以通过在舞台上监听resize事件来实现这一点:

  stage.addEventListener(Event.RESIZE,redrawScreen); 

函数redrawScreen(e:Event):void {
//当窗口大小发生变化时,调整所有的大小。
}


I'm new to the whole world of coding, and actionscript 3 is my first real experience, so sorry if I don't understand your answer straight away.

I've built an iPhone app using Adobe Flash CC in AIR for iOS. All the code is either in the timeline or separate .as files (so not using documents classes).

The core concept of the game is randomly generated objects fall from the top of the screen and the user has to tap them to make them disappear before they touch the bottom.

My problem is my document size is 640 x 960. I think this fits the iPhone 4 (haven't tested that) but when I test it on my iPhone 5s I get back bars at the top and bottom. Obviously they have different screen sizes but I want the app to be able to run on many all the different size iPhones.

I have spent hours googling this and still don't understand what I'm meant to do. I've tried playing around with the stage.scaleMode settings but nothing changes. I have also added a file called default-568h@2x.png (just a green rectangle with the dimensions 640 x 1136) in the included files but this doesn't show either.

So essentially I want to know how to change my app and AS3 code to allow my app to fit all the different size iPhones?

Any help would be very much appreciated.

解决方案

LAUNCH IMAGES

First, before anything else, you need to make sure you have the correct launch images included in your project.

Here is a table from Adobe's website:

  • Default~iphone.png | iPhone 4 (non-retina) 640 x 960 Potrait
  • Default@2x~iphone.png | iPhone 4, 4s 640 x 960 Potrait
  • Default-568h@2x~iphone.png | iPhone 5, 5c, 5s 640 x 1136 Potrait
  • Default-375w-667h@2x~iphone.png | iPhone 6 750 x 1334 Potrait
  • Default-414w-736h@3x~iphone.png | iPhone 6+ 1242 x 2208 Potrait
  • Default-Landscape-414w-736h@3x~iphone.png | iPhone 6+ 2208 x 1242 Landscape

Once you have those images made (and named exactly as shown), include them in your project (They have to be in the root of your application) by doing the following:

In FlashPro

  • go to your publish settings
  • go to the AIR for iOS Settings.
  • Go to the "General" tab
  • add all those images to the "included files" list (the root)

SCALING YOUR CONTENT

  • OPTION 1, FILL AND CROP

If you don't mind cropping your content a little bit, you can just do this when your app starts:

stage.scaleMode = StageScaleMode.NO_BORDER

This will scale your swf so it fills the whole screen while keeping aspect ratio. It's pretty easy to figure out how much padding you need to make this method work well for the small variations in aspect ratios for the various iPhones.

However, if you want to allow orientation changes (portrait to landscape), the cropping will likely be too severe.

  • OPTION 2 - RESPONSIVE DESIGN

The best way to accommodate varying screen resolutions and aspect ratios though, is to make your application responsive. This involves the following code at the start of your application:

stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align     = StageAlign.TOP_LEFT;

Now your stage bounds (stage.stageWidth & stage.stageHeight) will be the full width and height of the device*. (some devices still have a software toolbar at the bottom or the top band)

You can then position things through code.

If you want an easy way convert what you have (you don't want to use code to resize and align absolutely everything), just put all your content in a container MovieClip with an instance name of container, you could then size and position it like this:

//scale the container as big as possible while still fitting entirely in the screen:

//figure out which dimension should match the stage (widht or height)
if(container.width - stage.stageWidth >= container.height - stage.stageHeight){
    container.width = stage.stageWidth;
    container.scaleY = container.scaleX;
}else {
    container.height = stage.stageHeight
    container.scaleX = container.scaleY;
}

//center it on the screen:
container.x = (stage.stageWidth - container.width) * 0.5;
container.y = (stage.stageHeight - container.height) * 0.5;

It's also a good idea to listen for resize events, in case the screen size changes (eg you maximize/restore on desktop, or go from portrait to landscape on mobile).

You do that by listening for the resize event on the stage:

stage.addEventListener(Event.RESIZE, redrawScreen);

function redrawScreen(e:Event):void {
    //resize everything as the window size has changed.
}

这篇关于iPhone的不同屏幕尺寸在闪光? (获得黑酒吧)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆