Tag Info

Hot answers tagged

9

No, multiple inheritance does not solve all the same problems that entity systems do: entity systems and multiple inheritance are two very different things. You can build an entity system with or without multiple inheritance and similarly you can utilize multiple inheritance without building an entity system. Traditionally, component-focused entity systems ...


8

Refer to the popular software engineering principle, "Prefer composition over inheritance". Class proliferation concerns are the central reason behind the Component-Based Entity Systems (CBEs) so often mentioned on this site, which is a gamedev-specific embodiment of the aforementioned principle. The essence of the matter is that inheritance hierarchies are ...


7

Your class tree in general confuses me, namely the fact that you have multiple "Application" derived classes that presumably get implemented all in the same application. It further seems to be a grab bag of all sorts of unrelated functionality... simulation state management, layout, rendering, input... which seems to be why you have so much forwarding: ...


6

Several suggestions come to mind. I feel you may have gone a little inheritance happy. While inheritance is a great tool, sometimes all you need is a little more customization of a single object. First, a component system seems to jump out as a good candidate. Then you'd just have a Spell class (or perhaps something even more broad, but that's not ...


6

To check whether an object is an instance of a class in C#, use the is keyword: var item = inventory.getItem( ... ); if ( item is SpecialItem ) { var specialItem = (SpecialItem) item; // do something special... } or just cast it with as and see if it succeeds: var specialItem = item as SpecialItem; if ( specialItem != null ) { // do ...


3

Regarding question two: http://www.oodesign.com/ Look for: Singleton Visitor Observer Command Proxy


3

Why are you worrying about 3 virtual function calls per key-press? Modern computers can execute roughly 100,000,000,000 instructions per second and you're worried about a handful of function calls for events that happen once or twice per second? Your structure is fine. Factor out the Application interface to one called EventHandler or similar, have the ...


2

Multiple inheritance In C++, you want to be careful with multiple inheritance. It can really add complexity to your code. Especially when you include two objects that have the same base class. This is known as the diamond problem. There are, however, cases were multiple inheritance has it's uses, as seen below. How to properly use multiple inheritance In ...


2

This is one of the best examples why use composition over inheritance. When you learned coding OOP, you were very often advised to derive... and derive, and derive. This is usually not (that) bad for applications but you will run into serious problems in games very soon. Exactly whose what you posted. Entity component system design is frequently advised ...


2

Your idea of using a static method is probably the way to go. Give Enemy a constructor with all the values as parameters, then use static methods to make it easy to call it. Generally, you extend a class so you can override its methods. Suppose Enemy has a goToPoint method that moves the object in a straight line at a constant speed. You want a Ninja to ...


1

@wondra's comment that anything that does damage is a Weapon is spot-on. Don't get confused by having the class name be restrictive when it's not the right word. Perhaps in this case you want the class to be DamageDealer instead of Weapon. Another, and better, option is to use interfaces for the object types. This way you get a broad hierarchy instead of a ...


1

Your IDE of choice should have a way for you to navigate to the source for a specified class. For IntelliJ IDEA try moving your cursor to the Game class name that MyGdxGame extends and pressing CTRL + B. That should take you to the source for Game. Take a look at the override for render() that Game implements. @Override public void render () { if ...


1

You might also wan't to consider a component based approach for your game. I can point you to these two articles on the subject: 1 - 2 If you search for "component based game architecture" or "entity component system" you should be able to find a lot more on the subject.


1

In my humble opinion you should use neither. I would go with the Entity Component System and use composition instead of inheritance in this case. If you do choose to use one of the two, I reccommend using an Interface. You should avoid inheritance and use interfaces when there is no substantial inherit connection between the various classes that share the ...


1

Working from the framework you have now, can GamePlayState simply expose a public getPlayerCharacter() method? Then you can cast your IGameObject to a GamePlayState and call it. Something a bit like... GamePlayState currentState = stateSystem.getGameObject("Gameplay") as GamePlayState; if(currentState != null) PlayerCharacter playerCharacter = ...


1

This old Enchant.js blog entry talks about class inheritance and offers the following example enchant();。 A = Class.create({ initialize:function(){ this.x=1; }, method:function(){ document.write(this.x); } }); B = Class.create(A,{ //Inherits A initialize:function(){ A.call(this); // Calls up A constructor ...


1

Josh's answer is awesome, but I'd like to add: One of the coolest features of Entity/Component is the data-driven way in which every "thing" in your game is created and managed. From what I've seen, once you have a nice library of component types and systems created, you can build just about anything with minimal code modifications. (Note: minimal != 0) By ...



Only top voted, non community-wiki answers of a minimum length are eligible