游戏开发中的多态性? [英] Polymorphism in Game Development?

查看:90
本文介绍了游戏开发中的多态性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您使用c#或类似方法创建游戏时,使用与类相关的多态性是一种标准吗?



此消息中上传了一个多态的示例。



谢谢!

When you create a game in c# or similiar, is it a standard to use polymorphism in relation to classes?

A example of polymorphism is uploaded in this message.

Thanks!

推荐答案

我实际上看不到任何附加此消息。



无论如何,是的,使用多态性是很常见的。大多数游戏对象都会参与更新/绘制逻辑,因此他们可能会实现虚拟更新和绘制方法,不同类别(如敌人,玩家角色等)恰好有所不同。



当然,真正的细节会因用于编写游戏的框架而发生很大变化。例如,当我在WPF中创建游戏时,渲染大部分时间是使用WPF数据模板完成的,因此我不需要在类的任何虚拟方法上进行绘制。我还能够将动画与对象本身分开,因此敌人对象不需要动画的虚拟方法。然而,动画本身是多态的。



请参阅这些文章以获得一个想法:

Shoot'em Up .NET [ ^ ]

编写多人游戏(在WPF中) [ ^ ]



我在这篇文章中甚至用游戏来解释OOP:

面向对象编程简介(OOP) [ ^ ]

它实际上显示了w使用多态(虚拟方法)使游戏有效是一个好主意。
I actually don't see anything "attached" to this message.

In any case, yes, it is very common to use Polymorphism. Most game objects will participate in the Update/Draw logic, so they will probably have a virtual Update and Draw method implemented, which happens to be different by different classes (like enemies, the player character etc).

Of course the real details change a lot by the framework used to write the game. When I create games in WPF, for example, the rendering is most of the time done using WPF data-templates, so I don't need any virtual method on the class for the drawing. I am also able to separate animations from the objects themselves, so the Enemy objects don't need a virtual method for the animation. Yet, the animations themselves are polymorphic.

See these articles to have an idea:
Shoot'em Up .NET[^]
Writing a Multiplayer Game (in WPF)[^]

And I even used games to explain OOP in this article:
Introduction to Object Oriented Programming (OOP)[^]
It actually shows why it is a good idea to use Polymorphism (virtual methods) to make the game work.


这篇关于游戏开发中的多态性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆