Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

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.

Topics - aquaglow

Pages: [1]
SFML website / Missing step in SFML and Xcode tutorial (2.1)
« on: August 01, 2013, 08:54:19 am »
I just setup XCode and SFML 2.1 (clang version) on my Mac (10.8.4) for the first time, and I think the tutorial misses a step.

If you simply choose the SFML template and then immediately run, you get a compilation error:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/iosfwd:90:10: 'wchar.h' file not found

To fix it I installed the Command Line Tools package from the Downloads pane in the Xcode preferences (which installs the system headers). I think this issue with separate installation of headers might only exist in recent versions of XCode.

General / Segmentation fault trying to return sf::String from class
« on: July 08, 2011, 09:15:52 pm »
I've been trying to find a solution for a couple of hours, but having no luck :?

After advice earlier, I rewrote one of my simple struct's as a proper class, but now get a segmentation fault when trying to return a sf::String it stores.

My class:

Code: [Select]
namespace sw {

    class Hitpoints {
        sf::String string;
        int framesLeft;
        int fadeRate;
        float shrinkRate;
        bool isExpired;
        Hitpoints(sf::Unicode::Text, sf::Font, int, sf::Color, int, int, int, int, float);
        void update();
        sf::String getString();
        bool hasExpired();

    Hitpoints::Hitpoints(sf::Unicode::Text text, sf::Font font, int fontSize, sf::Color color, int centreX, int centreY, int framesL, int fadeR, float shrinkR) {
        this->string = sf::String(text, font, fontSize);
        sf::FloatRect rect(this->string.GetRect());
        this->string.SetPosition(centreX - (rect.GetWidth() / 2), centreY - (rect.GetHeight() / 2));
        this->framesLeft = framesL;
        this->fadeRate = fadeR;
        this->shrinkRate = shrinkR;
        isExpired = false;

    void Hitpoints::update() {
        sf::Color color = this->string.GetColor();
        this->string.SetColor(sf::Color(color.r, color.g, color.b, color.a - this->fadeRate));

        this->string.SetSize(this->string.GetSize() - shrinkRate);

        this->framesLeft = this->framesLeft - 1;
        if (this->framesLeft == 0) {
            this->isExpired = true;

    sf::String Hitpoints::getString() {
        return this->string;

    bool Hitpoints::hasExpired() {
        return this->isExpired;

In my main function I first add to the list:

Code: [Select]
sw::Hitpoints hitpoint("+10", scoreFont, 18, sf::Color(255, 234, 0), bulletVec2.x, bulletVec2.y, 60, 4, 0.2);

And then later I try to display it:

Code: [Select]
std::list<sw::Hitpoints>::iterator hps = hitpoints.begin();
while (hps != hitpoints.end()) {

I've run a backtrace in gdb, and get the segmentation fault on the line App.Draw(hps->getString());

Code: [Select]
(gdb) bt
#0  0x0013a377 in sf::Font::GetCharacterSize() const ()
   from /usr/lib/libsfml-graphics.so.1.6
#1  0x00139edb in sf::Drawable::Draw(sf::RenderTarget&) const ()
   from /usr/lib/libsfml-graphics.so.1.6
#2  0x00146730 in sf::RenderTarget::Draw(sf::Drawable const&) ()
   from /usr/lib/libsfml-graphics.so.1.6
#3  0x0804e2b3 in main () at spacewar.cpp:466

I've tried returning a reference to the sf::String object (perhaps wrongly) instead, but the same thing happens.

General / Best practice for object oriented game design?
« on: July 08, 2011, 07:33:44 am »
I'm not having any problems getting my game working with SFML, but currently all my code is just in the main() function. I'm new to C++, and was wondering what's considered the best strategy for splitting up ones code into different classes?

There are certain game objects which different classes will all need access to, is it a better approach to define static class variables or to pass references around?

In this section:

g++ -o ... -lsfml-graphics -lsfml-window -lsfml-system
Basically, every SFML library depends on sfml-system, and sfml-graphics also depends on sfml-window. That's it for dependencies.

Shouldn't you mention -lsfml-audio also?

Graphics / Slow framerate when moving lots of sf::Shape about
« on: July 02, 2011, 09:02:26 pm »
Code: [Select]
           // Are we firing the gun?
            if (fireGun){
            int targetX = Input.GetMouseX();
            int targetY = Input.GetMouseY();
            float angleShip = atan2(targetX - sVec.x, targetY - sVec.y);
            // Initially set to 0,0 and then move, to avoid the nuisance of local/global positioning later
            // http://www.sfml-dev.org/forum/viewtopic.php?t=4954
            float x = 0;
            float y = 0;            
            float x2 = sin(angleShip) * 12;
            float y2 = cos(angleShip) * 12;
            sf::Shape fire = sf::Shape::Line(x, y, x2, y2, 2, sf::Color(255, 255, 255), 0, sf::Color(0, 0, 0));
            fire.SetPosition(sVec.x, sVec.y);
            // Move the position of existing gunfire along so it travels
  std::list<sf::Shape>::iterator b = bullets.begin();
  std::list<float>::iterator gf = gunfireAngles.begin();
  while (b != bullets.end()) {
            float movingX = sin(*gf) * 0.5;
            float movingY = cos(*gf) * 0.5;
            b->Move(movingX, movingY);      

  // check if a bullet is still shown inside the window. If not, erase it
  sf::Vector2f bulletVec = b->GetPosition();
            if (bulletVec.x < -10 || bulletVec.x > 810 || bulletVec.y < -10 || bulletVec.y > 610){
            b = bullets.erase(b);
            gf = gunfireAngles.erase(gf);


I'm currently using a list of sf::Shape::Line as bullets in my game. When a few 100 are displayed on the screen, the movement noticeably slows down (I haven't put any sort of frame limiting on yet). Is this to be expected?

Each loop I move every bullet slightly further along its trajectory, and remove any which are outside the screen bounds.

Could it be my repeated calls to sin() and cos() making it slow? From reading the advice seems to be that with modern processors pre-calculated lookup tables shouldn't be needed.

I don't have any easy way to do profiling at the moment (having trouble compiling with the profiling option), but will persevere.

Pages: [1]