简体   繁体   English

如何根据手机屏幕尺寸改变敌人的尺寸,速度等?

[英]How to change enemy size, speed, etc depending on mobile screen size?

I have a game where enemies are spawned from a library at random. 我有一个游戏,从图书馆随机产生敌人。 Their size and speed are set to work on specific dimensions. 它们的大小和速度设置为可在特定尺寸上使用。 However, these specific standards won't work well on phones with small screens. 但是,这些特定的标准不适用于小屏幕手机。 Is there a way to change speed, size depending on a phone's dimensions? 有没有一种方法可以根据手机的尺寸更改速度和尺寸?

you can get Screen size with following code: 您可以使用以下代码获取屏幕尺寸:

  if (android.os.Build.VERSION.SDK_INT >= 13)
  {
    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    int height = size.y;
   }
   else
   {
     Display display = getWindowManager().getDefaultDisplay(); 
     int width = display.getWidth();  // deprecated
     int height = display.getHeight();  // deprecated
   }

more info , and change any thing with this information 更多信息 ,并使用此信息更改任何内容

For detecting the environment, check out the System Capabilities class (screenResolution, etc) http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/Capabilities.html 要检测环境,请检出“系统功能”类(screenResolution等) http://help.adobe.com/zh_CN/FlashPlatform/reference/actionscript/3/flash/system/Capabilities.html

and for Flash settings, stageWidth and stageHeight may help: ( http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Stage.html ). 对于Flash设置,stageWidth和stageHeight可能会有所帮助:( http://help.adobe.com/zh_CN/FlashPlatform/reference/actionscript/3/flash/display/Stage.html )。

However, if you're targeting both small and large screens, you may want to think about two (or more) sets of FLA files, since you can't set stage size on-the-fly, and otherwise you'd be scaling graphics, bitmaps, etc. to fit on either. 但是,如果您要同时针对大屏幕和大屏幕,则可能要考虑两套(或更多套)FLA文件,因为您无法即时设置舞台大小,否则会进行缩放图形,位图等都适合。

You can use Config Constants (ActionScript settings) to signal to the code which environment you're compiling. 您可以使用Config常量(ActionScript设置)向代码发出信号,告知您正在编译的环境。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM