16
General / Help me optimize my game
« on: March 27, 2011, 10:57:28 am »
Start with compiling it in Release-mode instead of Debug - and you'll see rather nice space savings.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
. Anyway, #ifndef is easier then bothering with defined.
if !defined(_DEBUG) && !defined(_BETA)
const sf::Input & myInput = Target.GetInput();
if(myInput.IsKeyDown(sf::Key::Down))
m_movespeed.y += 5.f;
if(myInput.IsKeyDown(sf::Key::Up))
m_movespeed.y -= 5.f;
if(myInput.IsKeyDown(sf::Key::Left))
m_movespeed.x -= 5.f;
if(myInput.IsKeyDown(sf::Key::Right))
m_movespeed.x += 5.f;
sf::Vector2f newPos(splayer.GetPosition().x + m_movespeed.x, splayer.GetPosition().y + m_movespeed.y);
newPos.x = min(newPos.x, 780); // or replace with a proper clamp function
newPos.x = max(newPos.x, 240); //
newPos.y = min(newPos.y, 730); //
newPos.y = max(newPos.y, 40); //
splayer.SetPosition(newPos);
class Ball
{
/* removed for easier reading */
private:
sf::Image iBall;
};
Ball::Ball(float xP, float yP)
{
if(! iBall.LoadFromFile("pilka.bmp") )
{
/* removed for easier reading */
It is important to note that the sf::Sprite instance doesn't copy the image that it uses, it only keeps a reference to it. Thus, a sf::Image must not be destructed while it is used by a sf::Sprite (i.e. never write a function that uses a local sf::Image instance for creating a sprite).