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

Pages: [1]
1
Graphics / Making sprite go in circles
« on: October 04, 2011, 02:55:41 pm »
:lol: I used old revision with new docs. Back to cmake and compiling. Sry for wasting your time :lol:

2
Graphics / Making sprite go in circles
« on: October 04, 2011, 02:38:23 pm »
Found the problem. It isn't graphic package. Window.GetFrameTime() returns 1 or 0. Tried with Clock class, but still the same problem. Anyone know a fix for it?

3
Graphics / Making sprite go in circles
« on: October 03, 2011, 11:14:14 pm »
I used trigonometric cicrcle to make ball sprite move on a circular path. It does, only thing is that the path is always moving and changing radius. Don't know if it is a float rounding error or my computer going mad, or probably a semantic error. I'd be grateful if someone took a look at code and helped my find the error.
Sry if code isn't readable. I commented only logic parts.

Code: [Select]


#include <SFML\Graphics.hpp>
#include <cmath>

int main()
{
    sf::VideoMode VMode(800, 600, 32);
    sf::RenderWindow Window(VMode, "Test");

    sf::Texture Ball;
    if (!Ball.LoadFromFile("ball.png"))
        return 1;

    double speed = 1;//constants and start values
    long double angle = 90;
    const double rad = 57.2957795;
    double ang = 0;

    sf::Sprite ball(Ball);
    ball.SetPosition(400,300);
    ball.SetScale(0.1,0.1);




    sf::Event Event;
    while (Window.IsOpened())
    {


        while (Window.PollEvent(Event))
        {
            if (Event.Type == sf::Event::Closed)
            {
                Window.Close();
                break;
            }

        }
        if (angle > 360)//if angle exceeds 360
                angle -= 360;//reset it
            angle += speed * Window.GetFrameTime();//angle in degrees
            ang = angle/rad;//angle in radians

        ball.Move(std::sin(ang),std::cos(ang));//move on a circular path
        Window.Clear(sf::Color(255,0,0));
        Window.Draw(ball);
        Window.Display();
    }

    return 0;
}

4
Graphics / Screenshot
« on: September 23, 2011, 12:45:16 pm »
Thx for a fast reply. Just moved Window.Capture() a bit above and it worked. Thx for help.

5
Graphics / Screenshot
« on: September 23, 2011, 12:32:11 pm »
I started learning SFML from SFMLCoder, and noticed that SFML interface changed, so I switched Image with Texture. This is lesson 2, so I didn't get very far :). The program worked, but I couldn't get a screenshot, so I googled, and found out, that I need an sf::Image and Window.Capture(). The program compiles, and runs, but it says that screenshot failed to save. My guess is that screenshot image is empty, but I am really new to SFML and I finished chapter 13 in Prata's book, so I am new to C++, too. I'd appreciate if someone took a look at the code and told me what to change and why. Sry if this has been asked 1000 times already.


Code: [Select]

#include <SFML/Graphics.hpp>

int main()
{

    sf::VideoMode VMode(800, 600, 32);//Create Window
    sf::RenderWindow Window(VMode, "Empty Window");

    sf::Texture Image;//Create image
    if (!Image.LoadFromFile("cake.png"))//Add a meme
        return 1;


    sf::Sprite Sprite2;//Make a sprite
    Sprite2.SetTexture(Image);//Adjust it as I want
    Sprite2.SetPosition(0.0f, 0.0f);
    Sprite2.SetScale(0.0f, 0.0f);
    Sprite2.Resize((float)VMode.Width, (float)VMode.Height);
    Sprite2.SetColor(sf::Color::Red);//Paint it with blood!!!!

    sf::Image Screenshot;//Image to store the screenshot

    while (Window.IsOpened())//If it is open
    {
        sf::Event Event;
        while (Window.PollEvent(Event))
        {
            switch (Event.Type)
            {
            case sf::Event::Closed://Check if it has been closed
                Window.Close();
                break;
            default:
                break;
            }
        }

        Window.Clear(sf::Color(0,255,127));//Color it

        Window.Draw(Sprite2);//Draw the sprite
        Window.Display();//Display the window
        Screenshot = Window.Capture();//Store screen in image

    }

    Screenshot.SaveToFile("sc.png");//Save screenshot
    return 0;
}

Pages: [1]
anything