Hi i’m new in programming stuff, i i’m struggling to check collision with an Spriter Animated Sprite and a tile. I tried messing with the bounding box from the AnimatedSprite2D and creating a custom from an tile node, but i don’t seen to understand it well, it don’t intersect. Do anyone
i’m following this article: http://www.wildbunny.co.uk/blog/2011/12/14/how-to-make-a-2d-platform-game-part-2-collision-detection/
void ResolveCollision(Node* tile) {
BoundingBox actorBBox = animSprite->GetBoundingBox();
actorBBox.Transform(node_->GetTransform());
std::cout << "tile " << tile->GetPosition().ToString().CString() << "\n;";
std::cout << node_->GetPosition().ToString().CString() << "\n;";
if (actorBBox.IsInside(tile->GetPosition()) != OUTSIDE)
std::cout << "NOT FIRING" << "\n";
}
void PosCollisions(float timeStep) {
Vector2 position = node_->GetPosition2D() + Vector2(0, 0.5f);
Vector2 predictedPos = position + (Vector2(velocity.x_, velocity.y_) * timeStep);
Vector2 min = Vector2(Min(position.x_, predictedPos.x_), Min(position.y_, predictedPos.y_));
Vector2 max = Vector2(Max(position.x_, predictedPos.x_), Max(position.y_, predictedPos.y_));
int mapMinX = -1;
int mapMinY = -1;
map_->PositionToTileIndex(mapMinX, mapMinY, min);
int mapMaxX = -1;
int mapMaxY = -1;
map_->PositionToTileIndex(mapMaxX, mapMaxY, max);
for (int x = mapMinX; x <= mapMaxX; x++) {
for (int y = mapMinY; y <= mapMaxY; y++) {
Node* tile = map_->GetLayer(0)->GetTileNode(x, y);
if (tile) {
ResolveCollision(tile);
}
}
}
}
Edit: Updated Code