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

Pages: 1 ... 8 9 [10]
136
Graphics / SFML 2 Water Shader Problem
« on: August 21, 2011, 12:52:19 pm »
Hey lolz123!

I don't know the answer, but I wanted to add that this sreenshot looks awsome! Would you give me some info on your project? Also, are you using some skeletal animation system there? Anyway, it looks fantastic!

Cheers,
easy

137
General / [SOLVED] SFML 2 Window resize & view resize
« on: August 20, 2011, 04:25:29 pm »
Answering my own question for that anybody can find this solution:

Code: [Select]
`FPSText.SetPosition(window.ConvertCoords(20, 20, defaultCamera));`

And the reason behind it is:
Code: [Select]
`    ////////////////////////////////////////////////////////////    /// \brief Convert a point from target coordinates to view coordinates    ///    /// Initially, a unit of the 2D world matches a pixel of the    /// render target. But if you define a custom view, this    /// assertion is not true anymore, ie. a point located at    /// (10, 50) in your render target (for example a window) may    /// map to the point (150, 75) in your 2D world -- for example    /// if the view is translated by (140, 25).    ///    /// For render windows, this function is typically used to find    /// which point (or object) is located below the mouse cursor.    ///    /// This version uses a custom view for calculations, see the other    /// overload of the function to use the current view of the render    /// target.    ///    /// \param x    X coordinate of the point to convert, relative to the render target    /// \param y    Y coordinate of the point to convert, relative to the render target    /// \param view The view to use for converting the point    ///    /// \return The converted point, in "world" units    ///    ////////////////////////////////////////////////////////////    Vector2f ConvertCoords(unsigned int x, unsigned int y, const View& view) const;`

138
General / [SOLVED] SFML 2 Window resize & view resize
« on: August 20, 2011, 01:06:05 pm »
Hi!

I've got an issue. When I resize the game window, and all the views including the default view, the text I draw on the default view changes it's position, no matter if I reposition it with "SetPosition(20.f, 20.f);", or not.

The truncated code is:

Code: [Select]
`        // Process events        sf::Event Event;        while (window.PollEvent(Event))        {            if (Event.Type == sf::Event::Resized)            {                defaultCamera.SetSize(Event.Size.Width, Event.Size.Height);                window.SetView(defaultCamera); // ... Just trying to make it work                FPSText.SetPosition(20.f, 20.f); // ... Here too            }        }`

See two screenshots of the resize:

Am I missing something?

easy

139
Graphics / Graphical glicth: horizontal lines in SFML2
« on: August 19, 2011, 01:38:43 pm »
Hello!

The level is made of 32x32 sprites, and they all share a texture (a tileset). I use no smoothing on the texture, but a camera (a view) to adjust where to render the tilemap.

Sometimes it renders with a horizontal lines under the tiles (see the screenshot), and this glitch remains while moving the camera horizontally.

I guess it's related to the floating-point rendering, how can I avoid it?

easy

P.S. My operating system is Linux Mint Debian.

140
Feature requests / SFML 2 Pong game update proposal
« on: August 16, 2011, 10:02:51 am »
By the way, I've found an ideal sound for the whistle idea: http://www.freesound.org/samplesViewSingle.php?id=90743

It's under Creative Commons Sampling Plus 1.0 license:

141
Feature requests / SFML 2 Pong game update proposal
« on: August 16, 2011, 09:43:57 am »
You're welcome!

142
Feature requests / SFML 2 Pong game update proposal
« on: August 16, 2011, 09:12:07 am »
Hello!

This might not be the ideal forum section so please move my topic if it's misplaced here. Also I don't know if you're open to such modifications or not.

I've modified a little bit the SFML 2 Pong example to slightly enhance the gameplay, that is:
- there is a 1 second delay before a round starts (shows how to use an sf::Clock),
- the game restarts when a player scores a point (encourages to play),
- the scores are printed on the screen instead of the end text (show how to print variables with sf::Text),
- fixes AITime to sf::Uint32,

Just an idea: a new sound (a whistle) could be played on every new round.

I think along with these enhancement the example is still encouraging the new users to modify it but also to play with it.
What do you think?

The code:

Code: [Select]
`////////////////////////////////////////////////////////////// Headers////////////////////////////////////////////////////////////#include <SFML/Graphics.hpp>#include <SFML/Audio.hpp>//#include <cmath>//#include <ctime>//#include <cstdlib>#include <sstream>/////////////////////////////////////////////////////////////// Entry point of application////// \return Application exit code///////////////////////////////////////////////////////////////int main(){    std::srand(static_cast<unsigned int>(std::time(NULL)));    // Defines PI    const float PI = 3.14159f;    // Create the window of the application    sf::RenderWindow window(sf::VideoMode(800, 600, 32), "SFML Pong");    // Load the sounds used in the game    sf::SoundBuffer ballSoundBuffer;    if (!ballSoundBuffer.LoadFromFile("resources/ball.wav"))    {        return EXIT_FAILURE;    }    sf::Sound ballSound(ballSoundBuffer);    // Load the textures used in the game    sf::Texture backgroundTexture, leftPaddleTexture, rightPaddleTexture, ballTexture;    if (!backgroundTexture.LoadFromFile("resources/background.jpg")    ||        !leftPaddleTexture.LoadFromFile("resources/paddle_left.png")   ||        !rightPaddleTexture.LoadFromFile("resources/paddle_right.png") ||        !ballTexture.LoadFromFile("resources/ball.png"))    {        return EXIT_FAILURE;    }    // Load the text font    sf::Font font;    if (!font.LoadFromFile("resources/sansation.ttf"))        return EXIT_FAILURE;    // Initialize the score text    sf::Text scoreText;    scoreText.SetFont(font);    scoreText.SetCharacterSize(60);    scoreText.SetColor(sf::Color(50, 50, 250));    // Create the sprites of the background, the paddles and the ball    sf::Sprite background(backgroundTexture);    sf::Sprite leftPaddle(leftPaddleTexture);    sf::Sprite rightPaddle(rightPaddleTexture);    sf::Sprite ball(ballTexture);    leftPaddle.Move(10, (window.GetView().GetSize().y - leftPaddle.GetSize().y) / 2);    rightPaddle.Move(window.GetView().GetSize().x - rightPaddle.GetSize().x - 10, (window.GetView().GetSize().y - rightPaddle.GetSize().y) / 2);    // Define the paddles properties    sf::Clock AITimer;    sf::Uint32 AITime      = 200;    float leftPaddleSpeed  = 400.f;    float rightPaddleSpeed = 400.f;    // Define the ball properties    float ballSpeed = 400.f;    float ballAngle;    // Main loop    int leftScore = 0, rightScore = 0;    sf::Clock start;    bool restart = true;    while (window.IsOpened())    {        // Handle events        sf::Event event;        while (window.PollEvent(event))        {            // Window closed or escape key pressed : exit            if ((event.Type == sf::Event::Closed) ||               ((event.Type == sf::Event::KeyPressed) && (event.Key.Code == sf::Keyboard::Escape)))            {                window.Close();                break;            }        }        // Restart the game        if (restart)        {            // Make sure the ball initial angle is not too much vertical            do            {                ballAngle = std::rand() * 2 * PI / RAND_MAX;            }            while (std::abs(std::cos(ballAngle)) < 0.7f);            ball.SetPosition((window.GetView().GetSize().x - ball.GetSize().x) / 2, (window.GetView().GetSize().y - ball.GetSize().y) / 2);            // Update score            std::ostringstream oss;            oss << leftScore << " : " << rightScore;            scoreText.SetString(oss.str());            scoreText.SetPosition((window.GetView().GetSize().x / 2) - (scoreText.GetRect().Width / 2), 20.f);            // Reset            start.Reset();            restart = false;        }        if (!restart)        {            // Move the player's paddle            if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Up) && (leftPaddle.GetPosition().y > 5.f))                leftPaddle.Move(0.f, -leftPaddleSpeed * window.GetFrameTime() / 1000.f);            if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Down) && (leftPaddle.GetPosition().y < window.GetView().GetSize().y - leftPaddle.GetSize().y - 5.f))                leftPaddle.Move(0.f, leftPaddleSpeed * window.GetFrameTime() / 1000.f);            // Move the computer's paddle            if (((rightPaddleSpeed < 0.f) && (rightPaddle.GetPosition().y > 5.f)) ||                ((rightPaddleSpeed > 0.f) && (rightPaddle.GetPosition().y < window.GetView().GetSize().y - rightPaddle.GetSize().y - 5.f)))            {                rightPaddle.Move(0.f, rightPaddleSpeed * window.GetFrameTime() / 1000.f);            }            // Update the computer's paddle direction according to the ball position            if (AITimer.GetElapsedTime() > AITime)            {                AITimer.Reset();                if ((rightPaddleSpeed < 0) && (ball.GetPosition().y + ball.GetSize().y > rightPaddle.GetPosition().y + rightPaddle.GetSize().y))                    rightPaddleSpeed = -rightPaddleSpeed;                if ((rightPaddleSpeed > 0) && (ball.GetPosition().y < rightPaddle.GetPosition().y))                    rightPaddleSpeed = -rightPaddleSpeed;            }            // Wait a second before the ball starts moving            if (start.GetElapsedTime() > 1000)            {                // Move the ball                float factor = ballSpeed * window.GetFrameTime() / 1000.f;                ball.Move(std::cos(ballAngle) * factor, std::sin(ballAngle) * factor);            }            // Check collisions between the ball and the screen            if (ball.GetPosition().x < 0.f)            {                restart = true;                ++rightScore;            }            if (ball.GetPosition().x + ball.GetSize().x > window.GetView().GetSize().x)            {                restart = true;                ++leftScore;            }            if (ball.GetPosition().y < 0.f)            {                ballSound.Play();                ballAngle = -ballAngle;                ball.SetY(0.1f);            }            if (ball.GetPosition().y + ball.GetSize().y > window.GetView().GetSize().y)            {                ballSound.Play();                ballAngle = -ballAngle;                ball.SetY(window.GetView().GetSize().y - ball.GetSize().y - 0.1f);            }            // Check the collisions between the ball and the paddles            // Left Paddle            if (ball.GetPosition().x < leftPaddle.GetPosition().x + leftPaddle.GetSize().x &&                ball.GetPosition().x > leftPaddle.GetPosition().x + (leftPaddle.GetSize().x / 2.0f) &&                ball.GetPosition().y + ball.GetSize().y >= leftPaddle.GetPosition().y &&                ball.GetPosition().y <= leftPaddle.GetPosition().y + leftPaddle.GetSize().y)            {                ballSound.Play();                ballAngle = PI - ballAngle;                ball.SetX(leftPaddle.GetPosition().x + leftPaddle.GetSize().x + 0.1f);            }            // Right Paddle            if (ball.GetPosition().x + ball.GetSize().x > rightPaddle.GetPosition().x &&                ball.GetPosition().x + ball.GetSize().x < rightPaddle.GetPosition().x + (rightPaddle.GetSize().x / 2.0f) &&                ball.GetPosition().y + ball.GetSize().y >= rightPaddle.GetPosition().y &&                ball.GetPosition().y <= rightPaddle.GetPosition().y + rightPaddle.GetSize().y)            {                ballSound.Play();                ballAngle = PI - ballAngle;                ball.SetX(rightPaddle.GetPosition().x - ball.GetSize().x - 0.1f);            }        }        // Clear the window        window.Clear();        // Draw the background, paddles and ball sprites        window.Draw(background);        window.Draw(leftPaddle);        window.Draw(rightPaddle);        window.Draw(ball);        window.Draw(scoreText);        // Display things on screen        window.Display();    }    return EXIT_SUCCESS;}`

Cheers,
easy

143
General / Creating CMake files of SFML 2 on Linux Mint Debian
« on: August 15, 2011, 09:28:54 pm »

Thanks Laurent! Now it compiled all right.

144
General / Creating CMake files of SFML 2 on Linux Mint Debian
« on: August 15, 2011, 07:37:34 pm »
Bonjour!

This is my first post here.

I've installed SFML 1.6 without problems on my system but I'd like try out the upcoming version 2. So I've followed the instructions and this is how far I've made it:

And the directory where SMFL 2 is:

The complete error message from CMake is:
Code: [Select]
`Could NOT find SNDFILE (missing:  SNDFILE_LIBRARY SNDFILE_INCLUDE_DIR) CMake Error: The following variables are used in this project, but they are set to NOTFOUND.Please set them or make sure they are set and tested correctly in the CMake files:SNDFILE_INCLUDE_DIR (ADVANCED)   used as include directory in directory /home/easy/Dokumentumok/Programozas/SFML-2/src/SFML/AudioConfiguring incomplete, errors occurred!`