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 - Krssst

Pages: [1]
1
Graphics / Different behavior of sf::Text with SFML 2.0 and SFML 2.1
« on: August 17, 2013, 04:36:37 pm »
Hello,

When compiling a game I wrote with SFML 2.1 instead of SFML 2.0, I noticed that text alignment was messed up. I then ran an experiment with a simple program :
#include <stdio.h>
#include "SFML/Window.hpp"
#include "SFML/Graphics.hpp"

int main(int argc, char *argv[])
{
        sf::RenderWindow window;
        window.create(sf::VideoMode(640, 480), "Manger");
        sf::Font font;
        font.loadFromFile("font.ttf");
        sf::Text text("Manger", font);
        text.setColor(sf::Color(255, 255, 255));
        text.setCharacterSize(60);
        sf::FloatRect bounds = text.getLocalBounds();
        sf::RectangleShape rectangle(sf::Vector2f(bounds.width, bounds.height));
        rectangle.setOrigin((int)(bounds.width/2), (int)(bounds.height/2));
        rectangle.setFillColor(sf::Color(0, 0, 0, 0));
        rectangle.setOutlineColor(sf::Color(255, 0, 0));
        rectangle.setOutlineThickness(1.0f);
        text.setOrigin((int)(bounds.left+bounds.width/2), (int)(bounds.top+bounds.height/2));
        text.setPosition(320, 240);
        rectangle.setPosition(320, 240);

        while(true)
        {
                window.clear();
                window.draw(rectangle);
                window.draw(text);
                window.display();
                sf::sleep(sf::milliseconds(100));
        }
        return 0;
}
 

Here is what I have with SFML 2.0:


And with SFML 2.1:


Am I missing something?
I never really understood bounding boxes with text, so I may be doing something wrong...
The rectangle is supposed to represent the bounding box of the text (and, hopefully, is precisely at the center of the window). With SFML 2.1, the bottom of the 'g' is cropped, and there is a small whitespace on the left of the 'M'.

I am using the SFML 2.1 precompiled binaries for Visual C++ 11 (32 bits)

EDIT: tested on Linux with git version versus 2.0 ; same problem.

2
SFML projects / Nekoculus: a cat, a bullet and movement prediction
« on: August 15, 2013, 12:48:08 pm »
Hello,

A little while ago, I made a small game in C++ using SFML: Nekoculus. The goal is simple: you are a cat trying to escape a bullet and you must survive 67 seconds. You can move with the arrow keys. The bullet is slightly slower than you, but will remember every movement you make in order to predict what your next moves will be. To avoid collision, you will have to continually imagine new paths to confuse the AI.







Windows version is available here : https://www.dropbox.com/s/kmo1uz2co3u27xw/Nekoculus_R4.zip (4.5Mb). The game is using SFML 2.0, as text positioning seems to mess up when I use SFML 2.1.

Only problem is that I never managed to finish it (reached a 3500 score out of 4096), but this kind of game is more about always trying to improve the score than finishing it. But I believe it is theoretically possible to finish it :-)

This game is written in C++ and uses SFML for basically everything. The windows version is statically linked.

As it is quite simple, I now believe it would probably have been better to use something much higher-level, as 90% of the time I spent working on this game has just been for finishing touches (buttons (I had to write my own class for a rectangle with rounded corners), win/lose screen (especially the lose screen, if you reach 1024 score :-)), and making it run on Windows (I did it back when SFML 2 was in beta ; had to recompile SFML for windows under linux as I did not manage to do it in Windows...)). However, as the prediction algorithm is really computation-expensive, maybe it wouldn't have worked well.

Pages: [1]
anything