Main Page   Class Hierarchy   Compound List   File List   Compound Members  

KrImage Class Reference

The parent class for any Node that actually draws to the screen. More...

#include <image.h>

Inheritance diagram for KrImage::

KrImNode KrBox KrCanvas KrSprite KrTile List of all members.

Public Methods

virtual void QueryBoundingBox (KrRect *boundingBox, int window)=0
 Get the bounding box of the image, in its current state. More...

bool CheckCollision (KrImage *other, int window=0)
 Check to see if this object collides with another object. More...

virtual KrImage * ToImage ()
 Return a pointer if this is an image.


Detailed Description

The parent class for any Node that actually draws to the screen.

See also:
KrImNode


Member Function Documentation

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:

  • Setting any X, Y, or Scale property
  • Adding anything to the Tree. (Deleting from the tree is safe, however.)
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:

  • Move sprites, canvases, etc. Game & logic actions.
  • Call Walk
  • Check collisions. Call deletes as you go, queue up additional move and scaling actions.
  • Apply queued move / scaling actions.
  • Draw()
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 KrRect   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.

Reimplemented in KrBox, KrCanvas, KrSprite, and KrTile.


The documentation for this class was generated from the following file:
Generated on Mon Sep 15 12:01:11 2003 for Kyra by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001