- 浏览: 314911 次
- 性别:
- 来自: 益阳
文章分类
最新评论
-
duckbit:
楼主是否能把共享layout的例子发给我,有点没明白 谢谢额! ...
Android换肤apk -
天涯海角262253:
...
Androidpn里的Xmpp的理解 -
lbstudy:
Activity之间的切换动画 -
dumbnesslys:
楼主可不可以给个源码 ,就build.xml的 772774 ...
Ant自动打包 -
finaljava:
build.xml 这么复杂,看看这个吧http://angr ...
Ant自动打包
I used to make games like this:
class RenderableMovingCollidableGameObject extends RenderableMovingGameObject { public void update() { super.update(); // Parent classes implement rendering and movement. // implement collision detection here } } class PlayerObject extends RenderableMovingCollidableGameObject { public void update() { super.update(); // Run rendering, movement, and collision. // update the player } } ... // Main loop! while (true) { InputSystem.update(); // poll for input. for (gameObject : ListOGameObjects) { gameObject.update(); gameObject.draw(); } }
This isn't a bad way to start making games, but it doesn't scale. Making a good game requires flexibility and the ability to iterate quickly, and this approach starts to break down when the game becomes medium-sized. What if we have more than one game mode? What if the behavior of a specific game object needs to change for a short period of time? What if Level 27's version of the player needs to be subtly different than Level 26's?
In a nutshell, the problem with this approach is that the structure of the code producing a single frame of the game is hard-coded into the program. What I want is something that can change its structure between levels, or between game modes, or even on the fly. I need something more dynamic than a hard-coded for loop.
Another Approach
Let's look at game objects as an example. Game objects are entities in the game world like coins, enemies, moving platforms, and the player. They often have similar functionality, so one way to go about implementing a set of similar objects is to use an inheritance tree. We can create a base GameObject class, and from that derive RenderableGameObject, and from that derive RenderableMovingGameObject, and from that derive RenderableMovingCollidableGameObject, etc, etc, etc. Each level of derivation can add some common functionality until the leafs of this tree are specific entities, like the player.
The real problem with inheritance trees is that features that don't need to be inter-related become dependent on each other because of the way the code itself is written. Given the example class structure above, it's not possible to make a GameObject that can move but doesn't need to render (short of littering the code with flags--don't do that). Because of inheritance, a dependency between movement and rendering has been created where none actually needs to exist. What if we could mix and match features on a per-instance basis rather than tying them all together in a class hierarchy? This is where object composition comes in.
Object composition (or "object aggregation" depending on which design patterns book you read) is the idea that an object "has a" feature instead of "is a" feature. Rather than using inheritance or some other code-side method of collecting functionality together in a single object, we make the object manage a list of separate feature objects; the contents of that list can be different per instance.
So for Replica Island, I have a GameObject class that contains a list of GameComponents. A game object with an empty list does nothing; it can't be drawn, or make noise, or hit things, or do anything else to affect the game. GameComponents implement all of those features, and they must be inserted into the GameObject for it to actually be able to act. Here's some psudeo-code of how GameObject and GameComponents work:
class GameObject { private Array<GameComponent> mComponents; public void addComponent(GameComponent component) { mComponents.push(component); } public void update(float time) { for (component : mComponents) { component.update(time, this); } } }
class GameComponent { public void update(float time, GameObject parent) { // ... functionality goes here } }
A GameObject just runs all the GameComponents it contains to produce its output each frame. GameComponents in Replica Island implement things like movement, physics, collision detection, sprite animation, rendering, animation selection, AI, player control, etc. Once a generic GameComponent is written it can be inserted in any number of objects; if a specific object requires special functionality, a new GameComponent can be written just for that object without disturbing anything else in the system.
The beauty of this approach is that individual components can be compartmentalized features, and brand new objects in the game world can be created just by sticking different pieces of pre-existing code together in new ways. The result is also dynamic: unlike an inheritance-based object, Replica Island game objects can change their structure at runtime. For example, one of the Android robot's powers is to possess other robots. When an enemy robot is possessed, his AI component is removed and a new component that lets the player control him is inserted. All of a sudden the robot is being driven by the player; all the rest of his code for animation selection, physics, and collision detection, continues to work without realizing that anything has changed. When the player releases the robot, the original component structure can be restored (actually, in this case the robot blows up, taking out anything else near it, but you get the idea).
I've made a couple of games now using components and I'm very happy with the result. In Replica Island I took a couple of shortcuts for speed that damage the goal of completely independent components, but I think it was worth it; the sacrifices I've made for frame rate haven't actually proved detrimental to the flexibility or extensibility of the system.
发表评论
-
Want to Change the Game Industry? Support the Xperia PLAY.
2011-12-07 21:05 0The problems with the console g ... -
Replica Island Updated
2011-12-07 21:04 0Yesterday I uploaded the first ... -
Hot Failure
2011-12-07 21:04 0An article I originally wrote f ... -
Building a Reflective Object System in C++
2011-12-07 21:03 0Every game engine I've worked w ... -
Leveraging Java and C++ for Hybrid Games
2011-12-07 21:02 0I've been thinking a lot lately ... -
Game Object Construction Rabbit Hole
2011-12-07 21:01 0Today I want to write a little ... -
Long Time, No See
2011-12-07 21:00 0I haven't written anything here ... -
Replica Island Passes a Million Installs
2011-12-07 20:59 0Holy crap!Replica Island passed ... -
Control Configuration and Abstraction
2011-12-07 20:58 0The #1 thing that I've learn ... -
Design Post-Mortem: Three Mistakes
2011-12-07 20:58 0While I'm pretty happy with Rep ... -
Replica Island: One Month On
2011-12-07 20:57 0As of today, Replica Island ... -
My New Favorite User Feedback
2011-12-07 20:56 0You can't write this stuff ... -
Replica Island User Comments Are Hilarious
2011-12-07 20:55 0Update: Blogger apparently isn' ... -
Design Post-Mortem: The Possession Orb
2011-12-07 20:55 0Rather than write a big lo ... -
Replica Island Released!
2011-12-07 20:54 0I released Replica Island almos ... -
Fragmentation? More like Fragmentawesome.
2011-12-07 20:53 0I'm lucky enough to have occasi ... -
The Elusive Perfect Platformer Camera
2011-12-07 20:52 0I've come to believe that platf ... -
Game Play Video
2011-12-07 20:51 0Here's some footage of an early ... -
Tuning With Metrics Redux
2011-12-07 20:50 0A while back I posted about the ... -
Some Screenshots
2011-12-07 20:49 0I've posted some screenshots of ...
相关推荐
### MongoDB Group Aggregate 实战解析 #### 一、项目背景与目的 在数据分析领域,特别是针对时间序列数据的处理,MongoDB 提供了强大的查询和聚合功能。本实战笔记旨在通过一个具体的案例,来探讨如何利用 MongoDB...
在SAP BusinessObjects(简称BO)环境中,聚合感知函数是一种强大的工具,它可以帮助用户在报告设计过程中处理复杂的聚合逻辑。聚合感知函数的主要作用是确保计算结果能够根据不同的数据聚合级别正确地进行调整或...
在MATLAB中,“aggregate”通常指的是对数据进行聚合操作,这是一种数据分析的重要方法,它涉及到将数据根据特定的分组变量进行汇总,并对每个分组应用特定的统计函数。这个“matlab开发-aggregate”可能是一个...
"aggregate-v0.75.tgz" 是一个用于Cacti监控系统的插件包,它在IT领域中扮演着重要角色。Cacti是一款广泛使用的网络监控和图形化性能数据工具,尤其在服务器、网络设备和带宽利用率的监控方面表现出色。这个名为...
在本篇文章中,我们将深入探讨如何在Spring Boot应用中使用MongoDB的聚合框架(Aggregate)进行数据处理和分析。 首先,让我们理解MongoDB的聚合框架。在SQL世界中,我们有GROUP BY、JOIN等操作来对数据进行聚合和...
根据给定的信息,我们可以深入探讨聚合感知函数(@Aggregate_Aware)的概念及其在特定场景中的应用。该知识点主要围绕如何处理复杂的数据集以及如何优化查询性能展开。 ### 聚合感知函数@Aggregate_Aware #### ...
meteor-aggregate, 对 Meteor的适当的MongoDB聚合支持 meteorhacks:aggregate为 Meteor 添加适当聚合支持的简单软件包。 这个包在 Mongo.Collection 实例上公开了 .aggregate 方法。这只在服务器端工作,没有...
### Cacti Aggregate Sum 插件详解 #### 特性 Cacti Aggregate Sum插件是基于用户Linegod(J.P. Pasnak)的一个指南开发而成。它的主要目的是减少创建基于两个或更多已存在图形的新汇总图形所需的手动任务量。尽管...
MongoDB的`aggregate`函数是用于处理数据集合的高级工具,尤其在数据分析、报表生成以及数据清洗方面表现强大。在本场景中,我们将探讨如何利用`aggregate`来查询和处理重复数据记录。 首先,理解`aggregate`的基本...
a novel variant called aggregate channel features, make a full exploration of feature design, and discover a multi- scale version of features with better performance. To deal with poses of faces in ...
标题:“THE COMPUTATION OF AGGREGATE LOSS DISTRIBUTIONS”指的是总损失分布的计算。总损失分布是风险管理和保险精算中一个重要的概念,用于估计一定时期内所有索赔事件的损失总额的概率分布。在保险领域,了解...
maven-site-aggregate-plugin-2.7.0.jar
本实例主要探讨了两个核心主题:数据排序和使用Aggregate字段。以下是对这两个关键知识点的详细说明。 首先,我们来讨论数据排序。在Delphi中,当你从数据库获取数据时,可能需要对这些数据进行排序,以便于分析...
maven-site-aggregate-plugin-2.10.0.jar
我的博客:www.wangs0622.com, mongoDB-aggregate pipeline 使用的文档集合。
jar包,亲测可用
maven-site-aggregate-plugin-2.0.0.jar
mongo聚合函数(aggregate)java版, 类似mysql的group。 对应查询语句可查看 https://blog.csdn.net/xu180/article/details/89175663
根据给定的信息,本文将对“1聚合感知函数@Aggregate_Aware”进行详细的解析与介绍。此函数在数据库查询及数据分析领域具有重要意义。 ### 1. 聚合感知函数@Aggregate_Aware简介 #### 1.1 定义与用途 聚合感知函数...
DynSketch: a spatio-temporal aggregate index for moving objects in road networks