Questions tagged [polymorphism]
The polymorphism tag has no summary.
26 questions
0
votes
1
answer
120
views
Newtonsoft.Json JsonConvert.DeserializeObject (Polymorphism)
I'm using JsonConvert.DeserializeObject to deserialize animals from the Animal list, but unfortunately they get deserialized as Animals instead of their derived classes (Cat and Dog). As you can see, ...
2
votes
1
answer
455
views
What design pattern should I use for adding functionality
I am making a tile based roguelike game with different objects in the world, like Doors, Security Cameras, Storage Shelves.
With that, there are objects that have an inventory, can detect the player, ...
0
votes
0
answers
92
views
How to handle collision detection with different 2D shapes while maintaining performance? Is polymorphism appropriate?
If I'm making a small library for handling 2D shapes, should polymorphism generally be avoided? I know that it can worsen performance but it's not like polymorphism is never used in game development ...
0
votes
2
answers
289
views
How to replace if/else/switch with polymorphisim
For a long time Robert Martin has been advising against if/else/switch branching logic and instead rely on the polymorphic behavior of different types. ...
0
votes
1
answer
87
views
Problem with Parameters for polymorphism class
This is going to be a bit tricky but it is really bothering me so I hope you will have the patience to follow along :)
Here is my very basic architecture:
So in the framework, I am creating I have <...
0
votes
0
answers
92
views
is there any different solution for different buildings different behaviours
I'm trying to make different behaviours for workers of different buildings, let's say an agricultural worker would need to sow wheat seed and collect the wheat grain when it's grown. let's call that <...
0
votes
0
answers
180
views
Remove nested if statements
I have been learning a new method of programming. I have been programming many years and am recently finding out there is a better method in general via abstract classes.
My question is how to ...
0
votes
1
answer
156
views
Interact with inheriting class methods from "casted" base class (collisions, etc)
I want to implement a damage system that works across both living items (Entity) and environment items (Environment). The key ...
1
vote
1
answer
1k
views
RPG Item Design [duplicate]
I'm currently fiddling around with some RPG mechanics and I'm trying to implement a solid way to handle items that have different on use effects.
Currently, I have a base class called "Item" that ...
3
votes
2
answers
1k
views
Using polymorphism in an Entity-Component System without sacrificing data-oriented design
I've been planning out an Entity-Component System in C++. My idea of it is most in line with the one described on this page of the entity systems wiki. To summarize, components are just structs of ...
0
votes
2
answers
277
views
How to: Duplicating and updating component data in systems
I am new to game development. Coming across the ECS (entity-component system) pattern I generally quite liked the idea. I have implemented the current version of my engine using the OOP style approach....
0
votes
1
answer
1k
views
Make the components of an ECS polymorphic
I have implemented an entity component sytsem (ECS) in my game engine (SFML and C++ 17). An entity has an array of components. You can get a components by its type e.g.: ...
1
vote
1
answer
478
views
Component based Entity System using polymorphism: OpenGL does not render
I want to be able to create Entities from different Component sets. I want to call Entity entity(new StaticObject(modelpath, position));
I have an EntityTypes ...
2
votes
2
answers
273
views
Cost of Using Virtual Methods to Query Properties?
Let's say you're making a tile-based roll-playing game, and you're obsessed with OOP.
You have an abstract base class Tile which will be inherited from by many ...
1
vote
1
answer
481
views
Inherited property in derived class reference only base class
[Context] I am developing a game in Unity, and wanted to make a Game Manager. Like many examples out there, it uses a Singletron design pattern. But i have several other Managers, all using Singletron ...
3
votes
1
answer
1k
views
'Ball.rigidbody' hides inherited member 'Component.Rigidbody'
I have some understanding of c# and I am new to unity. I am currently making a 3D project which use the Rigidbody component on the ball object.
When I use following code:
...
2
votes
1
answer
3k
views
Unity polymorphism in editor through a list
So I have an ItemDatabase class which basically only has a list of Item
...
6
votes
1
answer
6k
views
Unity3D [C#]: How do I use a custom inspector to expose an array of polymorphic objects to edit?
[EDIT: based on some feedback, I pruned the example down to the base functionality of the bug we are trying to solve. The description below remains accurate, but the repro has been shortened to:
Add ...
3
votes
1
answer
1k
views
Collision Shapes Abstraction Design
Straight to the facts.
I have a base CEntity class for different entities in my game:
Static entities ( those do not move, simply props and items )
Dynamic entities ( these move, jump )
Each of these ...
0
votes
1
answer
144
views
Interface or Class Inheritance [closed]
I am making an inventory system. Different inventory item will have different uses so i am thinking about making a base class called InventoryItem and derive Wood, Gold, Weapons and so on. This way ...
9
votes
3
answers
1k
views
Flexible alternatives to many many small polymorphic classes (for use as properties or messages or events) C++
There are two classes in my game that are really useful, but slowly becoming a pain. Message and Property (property is essentially a component).
They both derive from a base class and contain a ...
5
votes
4
answers
3k
views
Inheritance Hierarchy and Design -- avoiding multiple inheritance
I am working on a 3D game, and need some advice about how to best design and structure my code so that I achieve what I'm going for without using bad practices like multiple inheritance.
Basically ...
1
vote
1
answer
2k
views
Creating an abstract Animation class
I'm creating a simple 2d game with c++ and SFML, and I've got a simple framework going for animating a sprite using a "SpriteSheet" image (an big image containing all the "frames" of an animation)
I'...
0
votes
1
answer
654
views
Problem creating levels using inherited classes/polymorphism
I'm trying to write my level classes by having a base class that each level class inherits from...The base class uses pure virtual functions.
My base class is only going to be used as a vector that'...
2
votes
2
answers
204
views
How to handle similar actions in derived actors (inheritance)
I have a base class called Attacker that has a update method. The update method moves ...
-7
votes
2
answers
826
views
Component-based entities without IDs?
I'd like to know if someone has found a way to build a component-based entity system in their game(s) without using IDs. I find that IDs tend to do away with one of the major (possible) advantages of ...