#include <iostream>
#include <SFML/Graphics.hpp>
#include <Box2D/Box2D.h>
#include "Player.h"
using namespace std;
int main()
{
sf::RenderWindow *window = new sf::RenderWindow(sf::VideoMode(800, 600, 32), "Quanta");
sf::FloatRect viewRect(0, 0, 800/50, 600/50);
sf::View gameView(viewRect);
b2Vec2 gravity(0.0f, -10.0f);
b2World *world = new b2World(gravity);
Player mainPlayer(*window, *world);
sf::RectangleShape testShape;
testShape.setFillColor(sf::Color(0, 0, 0));
testShape.setSize(sf::Vector2f(1.28, 1.28));
while(window->isOpen())
{
sf::Event ev;
while(window->pollEvent(ev))
{
if(ev.type == sf::Event::Closed || sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
window->close();
}
window->clear(sf::Color(100, 175, 255));
world->Step(1.0f/60.0f, 6, 2);
window->setView(gameView);
mainPlayer.UpdatePlayer(*window);
//window->draw(testShape); //This is required, you'll see why later on.
window->display();
}
delete window;
delete world;
return 0;
}
void Player::UpdatePlayer(sf::RenderWindow& window)
{
b2Vec2 bodyPosition = _playerBody.body->GetPosition();
sf::Vector2f spritePosition(bodyPosition.x, bodyPosition.y);
sf::Vector2u spriteSize(1.28f, 1.28f);
_renderPlayer.UpdateSprite(window, playerSprite, spritePosition, spriteSize); //Graphics component will update the sprite
}
void GraphicsComponent::UpdateSprite(sf::RenderWindow& window, sf::Sprite &objectSprite, sf::Vector2f positions,
sf::Vector2u objectSize)
{
objectSprite.setPosition(positions.x - (objectSize.x / 2), -(positions.y + (objectSize.y /2)));
window.draw(objectSprite);
}
The sprite transformations are not applied until you draw the sprite. This is the normal behaviour in SFML 2.0No, they are applied immediately. Internally I use lazy assignments, but it should not make any difference for the end user.
QuoteThe sprite transformations are not applied until you draw the sprite. This is the normal behaviour in SFML 2.0No, they are applied immediately. Internally I use lazy assignments, but it should not make any difference for the end user.
I must read documentation againYou may have misunderstood the specific point of the documentation which states that transformations are not accumulated nor applied in the order of call, but rather applied once and in a predefined order (i.e. you cannot move(p)/rotate/move(-p) to rotate around a custom center).
A variable time step produces variable results, which makes itAre you absolutely sure that GraphicsComponent::UpdateSprite gets given good positions?
difficult to debug. So don't tie the time step to your frame rate (unless you really, really have to).