I am using Box2D and SFML to make a game.
Everything works great and perfectly except for this.
The problem is that when an object is spinning quickly in Box2D, the sprites start to not render in the correct rotation/position.
I know the problem is probably with Box2D, but I posted there (http://www.box2d.org/forum/viewtopic.php?f=3&t=9614) and I haven't gotten any replies, so I figured I would post here, and hopefully get some input on what I could try and do to fix it, if there is anything I can do.
Spinning slowly, 5 rpm maybe:
(http://oi42.tinypic.com/2jg9ydc.jpg)
Spinning at about 40 rpm:
(http://oi39.tinypic.com/2lxjhwz.jpg)
Here is the code that draws the sprite. Drawing happens after the Box2D timeStep().
Each Fixture of the Body has its own sprite, called m_sprite.
m_sprite.setPosition(scale*(m_pFixture->GetAABB(0).GetCenter().x), scale*(m_pFixture->GetAABB(0).GetCenter().y));//scale is 64
m_sprite.setRotation(180.0*m_pBody->GetAngle()/PI);//PI is defined as 3.1415926
m_rWindow.draw(m_sprite);
Using a the TileMap class actually solves the original problem of this post, as well as being faster, so I will definitely use them if possible
And when I said Quad pointer, I meant 4 vertex pointers (for each vertex of a quad), so the object can change the textureCoordinates to change what is being displayed (animation).
This is what I have as an example to loop over pieces of an animation, all part of a .png (4 states):
if (sf::Keyboard::isKeyPressed(sf::Keyboard::X))
{
textureTileX++;
if(textureTileX == 4)
textureTileX = 0;
quad[0].texCoords = sf::Vector2f(textureTileX * tileSize.x, textureTileY * tileSize.y);
quad[1].texCoords = sf::Vector2f((textureTileX + 1) * tileSize.x, textureTileY * tileSize.y);
quad[2].texCoords = sf::Vector2f((textureTileX + 1) * tileSize.x, (textureTileY + 1) * tileSize.y);
quad[3].texCoords = sf::Vector2f(textureTileX * tileSize.x, (textureTileY + 1) * tileSize.y);
}
Sorry if I didn't understand, but how do I get data from multiple files, for example:
The file "Gun_Type1.png" would ideally only hold the sprite sheet for that specific entity, while "Armor_Type2.png" would hold its own sprite sheet for a different entity. TileMap only lets me load one texture. How do I get around this?
Would I need multiple sf::VertexArrays and a corresponding sf::Textures in the TileMap, so that each call to states.texture = loop over textures;
target.draw(loop over vertices, states);
would result in the correct texture being used, for the correct vertices? That doesn't seem like a good solution but it's the only one I have come up with.