-
I'm using sfml 2.0-rc, Windows 7, and Visual studio 2010.
Here is my snippet of code:
for(int nrow = 0; nrow < 24; nrow++)
{
for (int ncol = 0; ncol < 33; ncol++)
{
sprite2.setPosition(ncol * 32, nrow * 32);
sprite1.setPosition(ncol * 32, nrow * 32);
if (dDungeon[nrow][ncol] == '#')
{
CollisionRectangles[nrow][ncol] = sf::FloatRect (ncol*32, nrow*32,32,32);
window.draw(sprite1);
}
if (dDungeon[nrow][ncol] == ' ')
{
window.draw(sprite2);
}
}
}
I'm getting some kind of error when I hover over the sf::FloatRect, which reads:
"Error: No suitable Conversion function from "sf::FloatRect" to "float" exists.
I don't really understand this at all, can anyone help?
With this code, I'm creating a tilemap from sprites, and putting one collision rectangle over every single sprite so that I can define collision detection later with a moving character sprite.
So how do I load 792 different (24*33) collision rectangles into an array made to store them?
-
Please provide more information: the line of the error, the type of the variables involved, etc.
My guess is that CollisionRectangles is an array of floats instead of FloatRects. That's the only line that can trigger this error in the code that you show.
-
One important part of the code is missing, where the CollisionRectangles gets declared, because now we can only guess what it's type is.
If I'm right the array is declared as float instead of sf::FloatRect, because that's what the error says. It's trying to convert sf::FloatRect to a float, which obviously fails. ;)
Additionally, since you're defining a sf::FloatRect you should also use floats in its constructor, e.g.
sf::FloatRect (ncol*32.f, nrow*32.f, 32.f, 32.f)
-
I see what you guys are saying, but I just can't get it to work -_-
This is one part of what you asked for:
float CollisionRectangles[24][33];
and this line was giving me that error:
CollisionRectangles[nrow][ncol] = sf::FloatRect (ncol*32.f, nrow*32.f, 32.f, 32.f);
I'll try to explain again,
Basically I'm trying to put a rectangle the same size and position over every tile on the tile map, which lets me use the check intersect function with the player sprite's rectangle to establish collision detection.
I don't know how to put a different rectangle onto every tile of the tilemap. (I am going to use a for loop to cycle through them later and check each tile for collision).
-
I see what you guys are saying, but I just can't get it to work -_-
This is one part of what you asked for:
float CollisionRectangles[24][33];
and this line was giving me that error:
CollisionRectangles[nrow][ncol] = sf::FloatRect (ncol*32.f, nrow*32.f, 32.f, 32.f);
The just do this change to your code:
sf::FloatRect CollisionRectangles[24][33];
:)
-
Worked, Thanks!