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.

Messages - 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, 04:03:28 pm »
Thanks for all the help, I'll try splitting up my code as per your instructions.

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?

Graphics / Game Freezing
« on: July 07, 2011, 10:56:35 pm »
The simplest thing is setting some breakpoints and stepping through your code with a debugger (gdb if you're using g++, visual studio/xcode have a debugger integrated in the IDE). If you're not familiar with using a debugger it's worth investing the time to learn.

SFML projects / CosmoScroll - space shooter game
« on: July 06, 2011, 07:57:59 pm »
Excellent game :D

Thanks for the posting the source code, interesting to see how you've split up the logic.

I thought it should mention that if you're using the audio package you need to link the audio library with -lsfml-audio.

Unless it's too obvious to mention  :D

Audio / Flac error forgotten.
« on: July 06, 2011, 12:20:51 pm »
I believe this answers your question: http://www.sfml-dev.org/forum/viewtopic.php?p=31131

Graphics / Curving a sprite/shape
« on: July 05, 2011, 12:34:00 pm »
I believe this is on the "To Do" list for v2:

Someone describes a method of masking here by overriding draw and using the OpenGL API Directly, might be helpful: http://www.sfml-dev.org/wiki/en/sources/masking_using_alpha_and_blending

Graphics / animation
« on: July 04, 2011, 01:57:33 pm »
I don't see how your question relates to SFML graphics...

The most famous stop animation company at the moment is probably Aardman Animations, makers of Wallace and Grommit, Chicken Run etc.

Stop animation isn't used that much anymore because of the time and effort it takes, computer animation is much quicker.

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 / Programs used to make 2d Game images? Using gimp...
« on: July 02, 2011, 10:32:48 pm »
I'd personally suggest using Inkscape to make svg files, and then exporting to a .png file. Inkscape is much more suited to drawing and editing sprites in my opinion.

Graphics / Slow framerate when moving lots of sf::Shape about
« on: July 02, 2011, 10:09:44 pm »
Please ignore my post, I worked out what was wrong. I got the gprof profiler working, and because I wasn't limiting the framerate it was calling the bullet loop thousands of times a second.

I've now applied App.SetFramerateLimit(60) and made the speed/rotation of everything relative to App.GetFrameTime() and it's fine. It stays a constant 59 fps even with 1000 bullets  :shock:

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.

Graphics / sf::string draws in bad quality
« on: July 02, 2011, 06:00:45 am »
Do you have a screenshot and the example code you're using?

For me anyway, the font sizes I specify in SFML don't seem equivalent to those in GUI programs, i.e. a font size 8 in SFML appears much smaller than it would in a GUI.

I presume you're following the tutorial advice of loading the font at a larger size than you display it?

Code: [Select]
// Load at size 30
sf::Font scoreFont;
if (!scoreFont.LoadFromFile("Fonts/Courier_New.ttf", 30)) {
    return EXIT_FAILURE;

// Display at size 20
sf::String scoreLabel("Score", scoreFont, 20);

Pages: [1]