游戏邦在:
杂志专栏:
gamerboom.com订阅到鲜果订阅到抓虾google reader订阅到有道订阅到QQ邮箱订阅到帮看

Android游戏可能遇到的3个问题及解决方案

发布时间:2012-02-10 11:20:25 Tags:,,,

作者:Tim Bray

在Android上制作出一款游戏很容易,但在诸如Android这样移动、多任务、多核和多目标的系统上制作出一款优秀作品着实有些棘手。即便是最优秀的开发者,也会在他们与Android系统和其他应用互动时频繁犯错。这些错误不会影响到游戏可玩性的质量,但会在某种程度上影响用户体验的质量。

android games from zoomzum.com

android games from zoomzum.com

真正优秀的Android游戏知道如何产生良好的用户体验,也就是如何无缝地与Android设备上运行的应用系统、服务和UI特征相配合。在这个包含多个部分的系列博文里,专攻游戏Android Developer Relations的工程师将解析如何让你的游戏更加出众。

导航和生命周期

Android用户习惯于使用后退键。我们期望音量选项能够设计得更直观。我们期望主界面键的作用能够同Android导航范例相一致。有时,我们甚至期望菜单键能够发挥一定的作用。

1、问题:意外按到主界面

我正在玩XXX游戏,意外碰到了主界面键或后退键。当我用触摸屏幕的方式来玩游戏时,这种情况是很有可能出现的。无论我是在割绳子、控制飞机、切水果或抛小鸟,如果我因为上述情况失去了所有之前的游戏进程,我会感到相当愤怒。

问题出在哪里呢?

许多开发者设想,用户按主界面键都是为了离开游戏。可能在有些移动设备上,主界面键是个很难按动的实体按键。但是,就目前发布的Android设备而言,主界面键包括实体、电容和软按键。这意味着在某些设备上,主界面键被意外按到的可能性相对较高。因为这种情况导致玩家游戏进程的丢失,这是很糟糕的现象。

解决方案

(1)尽你所能将游戏状况保存到onSaveInstanceState()的Bundle中。无论你的应用何时接收到onPause()回叫信号,这个辅助功能都会被调用。注意,你可以将字节数组保存到Bundle中,所以可以方便地用来存储原始数据。

(2)如果你的游戏占用大量的本地系统资源,可以考虑在onPause()或onStop()期间停止运行庞大纹理(游戏邦注:或者所有纹理和游戏几何)。这可以帮助游戏继续留在内存中,加快切换回游戏任务的速度,否则那些占用内存较大的游戏会被清除出内存。但是,这样做可能会让较小游戏的重新加载速度变慢。

(3)当你的游戏重新开始时,可以从onRestoreInstanceState()的Bundle中重返状态数据。如果这个过程需要耗费一定时间,确保告知用户正在进行的事情,提供尽可能好的用户体验。

(4)对功能设置进行测试!

2、问题:后退键

我正在玩游戏,意外按到后退键。这可能出现以下糟糕的情况:

(1)游戏直接退出,玩家失去了当前游戏状态,导致其异常愤怒(游戏邦注:解决方案见问题1)。

(2)游戏毫无反应。

问题出在哪里呢?

我们已经知道了第1种情况的问题所在。从本质上来说,这是种数据遗失现象。那么,第2种情况的问题出在何处呢?

后退键是Android导航范例的必要组成部分。如果后退键无法让游戏回到活动阶层(游戏邦注:或游戏阶层)的上个屏幕,那么肯定存在一定的原因,比如活动文件没有存储草图的能力。

解决方案

如果用户处在游戏过程中,呈现对话框确认用户行为是很自然的做法,比如“你确定要马上退出吗?那个小怪物看起来很饿。”

在动作游戏中,你或许也可以采取类似《Replica Island》(游戏邦注:下文简称“RI”)的措施。RI忽略了所有其他触碰事件发生后200毫秒内的后退键指令,确保用户意外按到按键不会对游戏产生影响。

在游戏的主菜单上,你可以决定是否要给予用户提示。如果你的游戏加载时间很长,你或许需要提示用户。

3、问题:音量问题

最糟糕的情况是,在公共场合下无法马上关闭或降低游戏音量。一时间,所有人都知道你偏爱在游戏中做出暴力行为,这可能对你的职业有一定影响。

问题出在哪里呢?

默认情况下,多数Android设备的音量按键都能够控制振铃音量。你的应用必须将音量按键设置为超类状态,这样才能在游戏运行时保持其有效性。

解决方案

要设置这些按键能够控制游戏音量,你需要调用setVolumeControlStream。正如之前所说的那样,你需要做的是将这些按键添加到游戏架构中,这样用户便可以用标准和恰当的方法来控制音频。

游戏邦注:本文发稿于2011年12月14日,所涉时间、事件和数据均以此为准。(本文为游戏邦/gamerboom.com编译,拒绝任何不保留版权的转载,如需转载请联系:游戏邦

More Android Games that Play Nice

Tim Bray

Making a game on Android is easy. Making a great game for a mobile, multitasking, often multi-core, multi-purpose system like Android is trickier. Even the best developers frequently make mistakes in the way they interact with the Android system and with other applications — mistakes that don’t affect the quality of gameplay, but which affect the quality of the user’s experience in other ways.

A truly great Android game knows how to play nice: how to fit seamlessly into the system of apps, services, and UI features that run on Android devices. In this multi-part series of posts, Android Developer Relations engineers who specialize in games explain what it takes to make your game play nice.

II: Navigation and Lifecycle

Android users get used to using the back key. We expect the volume keys to work in some intuitive fashion. We expect that the home key behaves in a manner consistent with the Android navigation paradigm. Sometimes we even expect the menu key to do something.

1. Problem: There’s no place like [Home]

I’m playing [insert favorite game here] and I accidentally hit the [Home] key or the [Back] key. This is probably happening because I’m furiously using the touchscreen to actually play the game. Whether I’ve been cutting ropes, controlling aircraft, cleaving fruit, or flinging birds, I’m almost certainly angry if I’ve suddenly lost all of my game progress.

What went wrong?

Lots of developers assume that pressing the Home key exits a game. Perhaps this is because on some mobile devices the Home key is a somewhat-difficult-to-press physical button. Depending on the device and Android release, it might be a physical, capacitive, or soft button. This means that it is relatively easy to hit accidentally. Having progress lost by such an event as an incoming call is even worse.

How to avoid Angry Users

Save as much about the status of the game into the Bundle in onSaveInstanceState() as you can. This helper function will get called whenever your application receives an onPause() callback. Note that you can save byte arrays into that bundle, so it can easily be used for raw data.

If your game takes lots of native system resources, consider dumping large textures (or all textures and geometry) during onPause() or onStop(). (GLSurfaceView will do this automatically unless you tell it not to — at least you can tell it not to do so starting in API level 11). This will help your title continue to reside in memory, which will typically speed task-switching back to your game for very large titles that might otherwise be swapped out of memory, but may slow things down for smaller titles that can more efficiently multitask if they don’t bother to do this.

When your game resumes, restore the state from the bundle in onRestoreInstanceState(). If there is any sort of time-consuming loading that has to be done, make sure that you notify the user of what is happening to give them the best possible experience.

Test thoroughly!

2. Problem: [Back] I say!

I’m in the middle of playing a game and I hit the back key. One of several bad things can happen here:

The game exits immediately, losing all state and leading to Angry User Syndrome. (see Problem 1).

The game does nothing.

What went wrong?

We already know what is wrong with scenario 1. It’s essentially a data loss scenario, and it’s worse than pigs stealing your eggs. What is wrong with scenario 2?

The [Back] key is an essential part of the Android navigation paradigm. If the back key doesn’t return to the previous screen in the activity stack (or in the game hierarchy) there better be a very good reason, such as an active document with no capability to save a draft.

What to do about it

If the user is in the middle of gameplay, it is customary to display some sort of dialog asking the user if they intended the action: “Are you sure you wish to exit now? That monster looks hungry.”

In an extreme action game, you might also wish to do something similar to what Replica Island (RI) did. RI assumed that any [Back] keypress that happened within 200ms of another touch event was invalid in order to make it a bit more challenging to accidentally press the key.

At the Main Menu of the game, you can decide whether it makes sense to prompt the user or not. If your game has very long load times, you might want to prompt the user.

3. Problem: Quiet [Down]!

There’s nothing worse than wanting to settle down for a good session of [insert favorite game here] in some sort of public place with your volume turned up. Suddenly everyone has learned that you prefer pummelling produce to predicting present progressions and that’s practically profane in your profession.

What went wrong?

By default, volume keys in most Android devices will control the ringer volume, and your application must pass the volume keys through to the super class so this continues to work.

What to do about it

In order to make these keys control the music volume (which is the channel that your game will be using), you need to call setVolumeControlStream(AudioManager.STREAM_MUSIC). As stated previously, all you need to do is pass these keys through to the framework and you’ll get control of the audio in the standard and proper way. Do it as early as possible so a user can start changing the volume far before you begin playing anything. (Source: Android Develop)


上一篇:

下一篇: