我的questioin是pretty的多的称号,为什么我总是看在ActionScript 3.0,它的对象写作code时,单独的头脑是个好主意?
My questioin is pretty much in the title, Why do I keep reading in actionscript 3.0 that its a good idea to seperate the 'mind' from the 'object' when writing code?
感谢您的帮助,这是混淆了我的地狱了。
Thanks for any help, this is confusing the hell out of me.
如果你问为什么图形是从定位,运动和物理分离;拿这棵树,我得出:
If you're asking why graphics are separated from the positioning, movement and physics; take this tree I've drawn:
在树中,您将看到实体
有两个属性:
In the tree you'll see that Entity
has two properties:
向下移动,你会看到,有几件事情,延长实体
- 最显着的是播放
和在敌人
类。
Moving down, you will see that there are several things that extend Entity
- most notable are the Player
and the Enemy
classes.
扩展我的实体
级以上,我可以很容易地改变什么应该被用作图形
和还略显提供不同的体
。例如,玩家和敌人都会有明显不同的外观,而树
类将不再需要使用车身
与速度一样,因为它没有移动值处理。
Extending my Entity
class above, I can easily change what should be used as the graphics
and also provide slightly different bodies
. For example, the player and enemies will have obviously different appearances, and the Tree
class won't need to use a Body
that deals with values like velocity because it doesn't move.
下面是上述的一些优点:
Here are some advantages of the above:
我们可以创建不具有图形的实体,保存性能和存储器。 我们可以使用不同类型的图形,而不是固守影片剪辑
如果您已经扩展影片剪辑
您实体
类。
我们可以添加额外的逻辑到图形
类,如能够很容易隐蔽一个Sprite或MovieClip成精灵表有更好的表现。
的图形会更容易地管理和更轻巧(相对于好像它是自动捆绑每个实体)。
物理学会更容易处理,而无需知道有关图片。
的车身
无需对图形即时影响进行更新。
您了解物理是完全无关的出现将改善显著。
We can create entities that don't have graphics, saving performance and memory.
We can use different types of graphics rather than having to stick to MovieClip
if you had extended MovieClip
with your Entity
class.
We can add additional logic into the Graphics
class such as being able to easily covert a Sprite or MovieClip into a sprite sheet for better performance.
The graphics will be easier to manage and more lightweight (as opposed to if it were auto-bundled with each entity).
Physics will be easier to deal with without needing to know about graphics.
The Body
can be updated without immediate effects on the graphics.
Your understanding of physics being completely unrelated to appearance will improve significantly.