Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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!
Posted

1 solution

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.
 
Share this answer
 
v2
Comments
deelll 14-Feb-15 2:32am    
Thank your for your help!

I have some questions to you.

1.
Do you have any recommended website about game tutorial in C# and java?

2.
Do you know about any good community about game development in 2D?
Paulo Zemek 14-Feb-15 17:15pm    
Unfortunately, I don't know any site or community to recommend.
Sergey Alexandrovich Kryukov 30-Mar-15 21:05pm    
Paulo,

I would like to invite your to see my new 1 of April publication and have some fun:
Some Programming Approaches to "Neuro-Linguistic Programming".
Participation in this game in Comments and Discussions is especially encouraged.

Thank you.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900