本部分将演示移动平台开发者编写代码和构建游戏结构以便快速运行的方法。这里的核心思想是游戏设计和优化并不是真正独立的过程;在设计游戏时做出的决定可以使游戏既好玩又快速。
您可能还记得一些老游戏:玩家一次只能在屏幕上玩一回,而再装弹速度由子弹是否击中而由非计时器进行控制。这种技术称为对象池,它能简化内存管理,使程序运行更流畅。
太空入侵者游戏的创作者只能使用少量的 RAM,且必须确保程序需要分配的量不得超过可用量。如果他们让玩家每秒射击一次,并提供一个能量块使再装弹时间减少到半秒,那么他们必须确保有足够的内存空间来分配大量飞弹,以防玩家以尽可能快的速度射击并需要让所有射击效果保留尽可能长的时间。这种情况可能会给他们带来问题,所以取而代之的做法是仅分配一个飞弹并就此作罢。一旦飞弹销毁,便简单地将其停用,然后再次射击时对其重新定位并激活。但是,此飞弹始终存在于内存中的相同空间内,也不必移动或不断删除和重建飞弹。
这样的游戏不太真实,但却很有趣。当外星入侵者接近地面时,紧张感在一个高潮时刻释放,类似于电影或文学中的高潮。入侵者的接近距离为熟练的玩家提供了近乎瞬时的再装弹时间,让他们在完美的时间内按压射击按键,奇迹般地保卫地球。出色的游戏设计介于交互式叙事与背景驱动技术之间的一个奇异空间中。很难规划出这样优秀、有趣、高效的游戏,因为代码逻辑和用户交互是截然不同而又非常挑剔的两个方面,将它们结合起来合成新鲜有趣的成果需要大量的思考和实验。
可能无法在交互方面和同时使用移动端硬件方面进行游戏的全方位规划。让两者和谐碰撞的“瑰宝”更有可能在您进行实验时突然闪现。但是,充分了解代码在计划部署的硬件上的运行情况将有所帮助。如果要查看为何对象池更好的详细技术说明,并了解内存分配,请参阅我们的脚本优化页面。
假设您要开始进行游戏开发,希望同时通过大量操作和华丽的外观给玩家留下深刻印象。如何规划这些东西?如何知道限制在哪里?比如在游戏方面有多少金币?多少僵尸?多少对手车辆?这一切都取决于如何对游戏进行编码。
通常情况下,如果以简单方式编写游戏代码,或者使用最常规和最通用的方式,那么很快就会遇到性能问题。越依赖特定结构和技巧来运行游戏,视野就会越开阔,您就可以在屏幕上塞入更多的东西。
请参阅优化脚本页面。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.