Example #1
0
bool QTEMonster::hittestPoint(Vec2 p)
{
    AppDelegate *app = (AppDelegate*)Application::getInstance();
    float scaleFactory = app->scaleFactory;
    
    Vec2 pos = this->convertToNodeSpace(p);
    
    spBone *bodybone = skeletonNode->findBone("body");
    spAttachment *ata = skeletonNode->getAttachment("hitBox", "hitBox");
    spBoundingBoxAttachment *boundingAttachment = (spBoundingBoxAttachment*)ata;
    
    spPolygon *boundingPolygon = spPolygon_create(boundingAttachment->verticesCount);
    for (int i = 0; i<boundingAttachment->verticesCount; i++) {
        boundingPolygon->vertices[i]=boundingAttachment->vertices[i];
        boundingPolygon->count+=1;
    }
    spBoundingBoxAttachment_computeWorldVertices(boundingAttachment, bodybone, boundingPolygon->vertices);
    
    for (int i = 0; i<boundingPolygon->count; i++) {
        boundingPolygon->vertices[i]=boundingPolygon->vertices[i]*scaleFactory*characterScaleFactor;
    }
    
    bool clicked = spPolygon_containsPoint(boundingPolygon, pos.x, pos.y);
    spPolygon_dispose(boundingPolygon);
    return clicked;
}
void spSkeletonBounds_dispose (spSkeletonBounds* self) {
	int i;
	for (i = 0; i < SUB_CAST(_spSkeletonBounds, self)->capacity; ++i)
		if (self->polygons[i]) spPolygon_dispose(self->polygons[i]);
	FREE(self->polygons);
	FREE(self->boundingBoxes);
	FREE(self);
}