So...i am making a game for my girlfriend (Pipeline) in this games i use tilesets to show the map on screen, in the spritesheet for each type of pipe there's a sprite for it, but i didn't do a seperate sprite for the pipes that are rotated, in theses cases i would rotate them on my code, and that's what i (almost) did, the thing is that my sprite is rotating but getting out of the grid in wich it should be drawn
Here's the code for the constructor of the pipe
Pipe::Pipe(const int tipoCano, const unsigned dir, const sf::Vector2f pos, const float scale) {
std::size_t cont = 0;
ladosPipe = std::bitset<4>(tipoCano);
switch (ladosPipe.to_ullong()) {
case 0b1100:
for(int i = dir; i>0; i--) {
cont++;
ladosPipe >> 1;
if (cont == 4) {
cont = 0;
ladosPipe = 0b1100;
}
}
spriteSheet = spriteManager("Images/tilesetCanos.png", 1, 4, 256, 256, 1);
break;
case 0b1010:
for (int i = dir; i>0; i--) {
cont++;
ladosPipe >> 1;
if (cont == 2) {
cont = 0;
ladosPipe = 0b1010;
}
}
spriteSheet = spriteManager("Images/tilesetCanos.png", 1, 4, 256, 256);
break;
case 0b1000:
for (int i = dir; i>0; i--) {
cont++;
ladosPipe >> 1;
if (cont == 4) {
cont = 0;
ladosPipe = 0b1000;
}
}
spriteSheet = spriteManager("Images/tilesetCanos.png", 1, 4, 256, 256, 3);
break;
}
spriteSheet.aplicarTexturaSprite(sprCano);
sprCano.setOrigin(128.f, 128.f);
sprCano.rotate(angle * dir);
sprCano.setOrigin(0.f, 0.f);
sprCano.scale(scale, scale);
sprCano.setPosition(pos);
}
And where i call the constructor
Mapa::Mapa(char tipo, const sf::Vector2f pos, float scale) : Cano (nullptr) {
if (tipo == '0') {
spriteSheet = spriteManager("Images/tilesetCampo.png", 2, 1, 256, 256, 1);
colocavel = true;
}
else if (tipo == '1') {
spriteSheet = spriteManager("Images/tilesetCampo.png", 2, 1, 256, 256);
colocavel = false;
}
else if(tipo >= '2' && tipo <= '5'){
Cano = std::make_unique<Pipe>(Pipe(0b1000, 2, pos, 0.3125f));
spriteSheet = spriteManager("Images/tilesetCampo.png", 2, 1, 256, 256, 1);
colocavel = false;
}
else {
Cano = std::make_unique<Pipe>(Pipe(0b1000, 0, pos, 0.3125f));
spriteSheet = spriteManager("Images/tilesetCampo.png", 2, 1, 256, 256, 1);
colocavel = false;
}
spriteSheet.aplicarTexturaSprite(tile);
tile.setPosition(pos);
tile.scale(scale, scale);
this->scale = scale;
}
and last but not least, how it's shown on the screen (the red square is where the pipe should be drawn)
https://goo.gl/photos/BNS69bitmaCmq4Tg8and the pipes' spritesheet
https://goo.gl/photos/KPiTqkJgSDTVX1H68can anyone help me find the error?
(sorry if i wrote something wrong, english isn't my native language)