Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualKhatharr

Posted 21 December 2012 - 02:55 PM

Some terminology may help. These terms are not universally agreed upon, but in general:
 
"entity" - an interactable object within the game 'world'
"sprite" - an instance of rendering information
"bitmap" - aka 'texture' - wrapped (or raw) image data to be used in rendering
"collider" - coordinates and dimensions for use in testing collision against other colliders
 
(The point I'm driving at here is that you should not be colliding sprites. Colliders collide and they belong to entities, not sprites. (Hopefully.))

The composite pattern would have an Entity class which contains a collider and a sprite. The sprite would contain either a reference to or else an exclusive instance of a bitmap.
 
The composite pattern is actually very straightforward:
 
class Thing {
  Part p;
  OtherPart q;
  YAP r;
};
'Thing' composes 'Part', 'OtherPart' and 'YAP' and possibly manages their interactions or relative activities:
 
class Entity {
public:
  void moveTo(int x, int y) {
    collider.x = x;
    collider.y = y;
    sprite.x = x;
    sprite.y = y;
  }
private:
  Collider collider;
  Sprite sprite;
};
Composition is simply gathering together a set of objects into a container that lets you work with them as a single object.
 
 A POD struct is probably the simplest example of composition.
 
Using the composite pattern helps keep code manageable because you can compose more and more complex types and still make use of them with ease - an entity being a great example since it will likely end up containing all manner of data through members with members with members, but you can still just:
 
Entity ent;

#2Khatharr

Posted 21 December 2012 - 02:53 PM

Some terminology may help. These terms are not universally agreed upon, but in general:
 
"entity" - an interactable object within the game 'world'
"sprite" - an instance of rendering information
"bitmap" - aka 'texture' - wrapped (or raw) image data to be used in rendering
"collider" - coordinates and dimensions for use in testing collision against other colliders
 
The composite pattern would have an Entity class which contains a collider and a sprite. The sprite would contain either a reference to or else an exclusive instance of a bitmap.
 
The composite pattern is actually very straightforward:
 
class Thing {
  Part p;
  OtherPart q;
  YAP r;
};
'Thing' composes 'Part', 'OtherPart' and 'YAP' and possibly manages their interactions or relative activities:
 
class Entity {
public:
  void moveTo(int x, int y) {
    collider.x = x;
    collider.y = y;
    sprite.x = x;
    sprite.y = y;
  }
private:
  Collider collider;
  Sprite sprite;
};
Composition is simply gathering together a set of objects into a container that lets you work with them as a single object.
 
 A POD struct is probably the simplest example of composition.
 
Using the composite pattern helps keep code manageable because you can compose more and more complex types and still make use of them with ease - an entity being a great example since it will likely end up containing all manner of data through members with members with members, but you can still just:
 
Entity ent;

#1Khatharr

Posted 21 December 2012 - 02:50 PM

Some terminology may help. These terms are not universally agreed upon, but in general:

 

"entity" - an interactable object within the game 'world'

"sprite" - an instance of rendering information

"bitmap" - aka 'texture' - wrapped (or raw) image data to be used in rendering

"collider" - coordinates and dimensions for use in testing collision against other colliders

 

The composite pattern would have an Entity class which contains a collider and a sprite. The sprite would contain either a reference to or else an exclusive instance of a bitmap.

 

The composite pattern is actually very straightforward:

 

class Thing {
  Part p;
  OtherPart q;
  YAP r;
};

'Thing' composes 'Part', 'OtherPart' and 'YAP' and possibly manages their interactions or relative activities:

 

class Entity {
public:
  void moveTo(int x, int y) {
    collider.x = x;
    collider.y = y;
    sprite.x = x;
    sprite.y = y;
  }
private:
  Collider collider;
  Sprite sprite;
};

Composition is simply gathering together a set of objects into a container that lets you work with them as a single object.

 

 A POD struct is probably the simplest example of composition.


PARTNERS