使用2D Rect进行碰撞检测

时间:2015-01-24 18:21:03

标签: c++ sprite marmalade

我想为IW2D添加一个Rect,以便我可以在两个图像之间进行碰撞检测。 我创建了一个struct Rect(x,y,width,height)

我使用以下代码进行渲染:

Transform.SetRot(Angle);
    Transform.ScaleRot(Scale);
    Transform.SetTrans(Position);
    Iw2DSetTransformMatrix(Transform);
    Iw2DSetColour(Colour);
    // Render image
    if (ShipBullet != 0)
        Iw2DDrawImage(ShipBullet, CIwFVec2(Position.x, Position.y));

    boundingRect.srcX = Position.x;
    boundingRect.SrcY = Position.y;

    Iw2DSetColour(0xff0000ff); // Set red
    Iw2DDrawRect(CIwFVec2(boundingRect.srcX, boundingRect.SrcY),
        CIwFVec2(boundingRect.Width, boundingRect.Height));

但我仍然不知道如何更新精灵的boundingRect。我添加了一个调试代码IW2DDrawRect来绘制边界矩形,但是矩形没有绑定图像,它实际上是在其他地方绘制的。

0 个答案:

没有答案
相关问题