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:
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.
#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;
}
#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;
}