Tag Info

New answers tagged

1

Wouldn't it be simpler(and smarter) to just have arrays of the base class, then stick in the needed subclass at some index? This doesn't work. Child classes are likely to be a larger size than the base class, since child classes usually add some new data members. If you have an array of a base class (which is, say 32 bytes in size) you can't fit a ...


1

The way I see it is, don't stick the hooks in for something that will give you no benefit. Write your code in the simplest possible manner first, which almost always means "hard-coding" some things like the sprite group snippet you mentioned. If you come across some new change or requirement that would benefit from the factory, then by all means, write it, ...


2

ngoaho91 is basically hinting in the right direction but is not spelling it out explicitly, so I will try to make it more explicit. So you took the framework and started implementing the logic within the separate framework classes. The problem why you can't simply test the game logic in isolation, is because it is not isolated. You write that you ...


2

Implement your own Point class. That's good design if UI Point is seperate from logic Point. //Point.h class Point { public: int x,y; }; Point different to cocos2d::Point. In Projectile class, you include and use it. //Projectile.h #include "Point.h" class Projectile { public: char* image; Point* position; }; Then render class, include the ...


0

You don't necessarily have to throw away inheritance to ensure data locality. One very common approach used by level based games is to allocate a large chunk of memory at level start and construct all game objects in this chunk. It doesn't matter that game objects will have different sizes in this case, they are still laid out sequentially in the memory. ...


0

Straight from The Gang of Four's Book: Observer pattern - Applicability: When an abstraction has two aspects, one dependent on the other. Encapsulating these aspects in separate objects lets you vary and reuse them independently. When a change to one object requires changing others, and you don't know how many objects need to be ...



Top 50 recent answers are included