1
Graphics / sf::Text problem (bug?)
« on: January 28, 2012, 10:55:53 pm »
Thanks for confirming it is not just me, all I know is sf::Font has reference counting.
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.
sprite.SetPosition(mouse.GetPosition(Window).x, mouse.GetPosition(Window).y);
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
sf::Font font;
if (!font.LoadFromFile("res\\font\\white_rabbit.ttf"))
return EXIT_FAILURE;
sf::Text text;
text.SetString("test");
text.SetFont(font);
text.SetCharacterSize(50);
//sf::Text text("Hello SFML", font, 50);
while (window.IsOpen())
{
sf::Event event;
while (window.PollEvent(event))
{
if (event.Type == sf::Event::Closed)
window.Close();
}
window.Clear(sf::Color(0, 0, 0));
window.Draw(text);
window.Display();
}
return EXIT_SUCCESS;
}
sf::Text text("Hello SFML", font, 50);
instead. My application runs fine and doesn't crash upon closing the rendering window.Good job!
at least it looks good (no time to test for now). but did you read the "pacman unveiled" in the pacaman thread ?
Basically, does the ghost have different IA ? or they are all "kill pac man" ?
Yes.
Now, if you want to improve your code, you can have a look at the following things:
- initializer list (to use in the copy constructor)
- copy & swap implementation of the assignment operator
It looks good, but :
1 - why are you using a pointer to a sprite??? this is definitely not necessary, it adds complexity and potential problems for no gain
2 - your assignment operator should be implemented using copy & swap
3 - your assignment operator leaks (you never delete the old m_sprite), but using either 1- or 2- will solve this problem
4 - setting pointers to NULL in a destructor is useless, the object is destroyed and won't be used again
#include "Pill.h"
sf::Texture Pill::texture;
Pill::Pill()
{
}
Pill::~Pill()
{
}
Pill::Pill(const Pill& other)
{
sprite = other.sprite;
sprite.SetTexture(texture);
}
Pill& Pill::operator=(const Pill& rhs)
{
if (this != &rhs)
{
sprite = rhs.sprite;
sprite.SetTexture(texture);
Entity::operator=(rhs);
}
return *this;
}
#ifndef PACCAT_PILL
#define PACCAT_PILL
#include "Entity.h"
#include <SFML/Graphics.hpp>
#include "Load.h"
class Pill : public Entity {
public:
static bool InitializeTexture(sf::RenderWindow& renderWindow)
{
return Load::LoadTextureFromFile(renderWindow, texture, "resources\\image\\pill.png");
}
Pill();
~Pill();
Pill(const Pill& other);
Pill& operator=(const Pill& rhs);
private:
static sf::Texture texture;
sf::Sprite* sprite;
};
#endif
#include "Pill.h"
sf::Texture Pill::texture;
Pill::Pill()
{
sprite = new sf::Sprite(texture);
}
Pill::~Pill()
{
delete sprite;
sprite = NULL;
}
Pill::Pill(const Pill& other)
{
sprite = new sf::Sprite(*other.sprite);
sprite->SetTexture(texture);
}
Pill& Pill::operator=(const Pill& rhs)
{
if (this != &rhs)
{
sprite = new sf::Sprite(*rhs.sprite);
sprite->SetTexture(texture);
Entity::operator=(rhs);
}
return *this;
}
Quote from: "replicant"Did you make that background effect just using SFML graphic commands? or did you use opengl directly?
Very cool.
I used SFML commands, they're not suing very much memory even if they are 1 pixels white sprites xD
Thanks!
There are several solutions to this problem:
- use Thor clocks, they can be paused
- never reset the position of the stars, apply a modulo only when you display them to make them fit in the window
- ignore huge frame times (> 1 sec)
Nice intro screen, by the way
Do you have to scale them or can you use SetCharacterSize instead?