I created object. But drawn with distortion. What's wrong?
int main()
{
sf::View view;
view.reset(sf::FloatRect(0.0f, 0.0f, 1280u, 640u));
view.setViewport(sf::FloatRect(0.0f, 0.0f, 2.0f, 2.0f));
renderWindow.setView(view);
tmx::MapLoader ml("maps/");
ml.Load("platformer.tmx");
//create a box2D world
b2World world(tmx::SfToBoxVec(sf::Vector2f(0.f, 200.f)));
sf::Sprite dynamicCube;
sf::Texture tileSet;
tileSet.loadFromFile("maps/box.png");
dynamicCube.setTexture(tileSet);
sf::FloatRect rect1;
rect1 = sf::FloatRect(0,0,32,32);
dynamicCube.setTextureRect(sf::IntRect(rect1.left, rect1.top,rect1.height,rect1.width));
dynamicCube.setOrigin(rect1.height/2,rect1.width/2);
b2Body* b;
const std::vector<tmx::MapLayer>& layers = ml.GetLayers();
for (const auto& l : layers)
{
if (l.name == "Stat")
{
for (const auto& o : l.objects)
{
b2Body* b1 = tmx::BodyCreator::Add(o, world);
}
}
else if (l.name == "Din")
{
for (const auto& o : l.objects)
{
b = tmx::BodyCreator::Add(o, world, b2BodyType::b2_dynamicBody);
}
}
}
//-----------------------------------//
while(renderWindow.isOpen())
{
//poll input
sf::Event event;
while(renderWindow.pollEvent(event))
{
if (event.type == sf::Event::Closed)
renderWindow.close();
}
//update
world.Step(1.0f / 60.0f, 6, 3);
sf::Vector2f pos = tmx::BoxToSfVec(b->GetPosition());
dynamicCube.setPosition(pos.x,pos.y);
dynamicCube.setRotation(tmx::BoxToSfAngle(b->GetAngle()));
renderWindow.clear();
renderWindow.draw(ml);
renderWindow.draw(dynamicCube);
renderWindow.display();
}
return 0;
}