#include <image.h>
Inheritance diagram for KrImage:
Public Member Functions | |
virtual void | QueryBoundingBox (grinliz::Rectangle2I *boundingBox, int window)=0 |
Get the bounding box of the image, in its current state. | |
bool | CheckCollision (KrImage *other, int window=0) |
Check to see if this object collides with another object. | |
virtual KrImage * | ToImage () |
Return a pointer if this is an image. |
bool KrImage::CheckCollision | ( | KrImage * | other, | |
int | window = 0 | |||
) |
Check to see if this object collides with another object.
Only Sprites and Canvases can collide. (Boxes, Tiles, etc. are ignored.)
Composite Objects -- TextBox and Widgets -- are built on Sprites. Their components *will* collide. Something to be aware of.
This is a pixel perfect (or near perfect, if scaled) 2D collision detection. 2D collision detection is a necessary -- but not sufficient -- collision criteria for 3D collision, if you are using an isometric view. For top down or side views, this is a complete detection scheme.
See KrImageTree::CheckChildCollision and KrImageTree::CheckAllCollision for possibily more useful Tree variants of this call.
The ImageTree must be in an consistent state in order to for collision checking to work. The function Engine()->Tree()->Walk() will bring the tree into a consistent state. The following operations will invalidate the state of the Tree, causing collision checking to fail:
Walk can be a somewhat expensive call. And you should avoid calling it more than once per frame. A normal sequence of events would be something like:
Note that if you aren't using collision detection, you should never need to call Walk() directly. Also, if you check collisions *after* Draw(), but before any x/y/scale transformations, you don't need to call Walk().
Returns true if the objects collide.
A window can be specified. Depending on the transformations appiled, collisions can be different per window.
Collisions with scaled sprites and canvases is supported with one caveat: un-cached sprites can not be collision detected. For a full discussion of scaling, see the HTML docs. In brief, a scaled image can be cached (pre-calculated at a give x and y scale) or real time scaled. Real time scaled sprites can not be used in a collision test.
virtual void KrImage::QueryBoundingBox | ( | grinliz::Rectangle2I * | boundingBox, | |
int | window | |||
) | [pure virtual] |
Get the bounding box of the image, in its current state.
If this is a sprite, it will be the bounding box of the current frame and action. The bounds are relative to the hotspot, so xmin and ymin will often be not zero.
The current transformation matrix will be applied, so the result may be transformed bounds.