121
Graphics / Scrolling Text..
« on: March 16, 2010, 09:15:58 pm »
I'm not sure of what you mean by "scrolling text", is that just moving the text in a vertical way?
This can be simply done by adding 3 lines of code:
This can be simply done by adding 3 lines of code:
Code: [Select]
#include <SFML/Graphics.hpp>
#include<iostream>
int main()
{
// Create the main window
sf::RenderWindow App(sf::VideoMode(703, 493), "Rahul.Reincarnated ");
// Load a sprite to display
sf::Image Image;
if (!Image.LoadFromFile("image1.jpg"))
return EXIT_FAILURE;
sf::Sprite Sprite(Image);
// Create a graphical string to display
sf::Font Arial;
if (!Arial.LoadFromFile("arial.ttf"))
return EXIT_FAILURE;
sf::String Text("\t \t Welcome to OpenGL Project \n \t \t \t \t \t \t \t \t \t \t \t By Rahul ", Arial, 50);
const int SCROLL_SPEED = 20; // 20 pixels per second
Text.SetY(-Text.GetRect().GetHeight()); // text position is just above the screen
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App.Close();
}
// increase Y axis, move down
Text.Move(0, App.GetFrameTime() * SCROLL_SPEED);
// Clear screen
App.Clear();
// Draw the sprite
App.Draw(Sprite);
// Draw the string
App.Draw(Text);
// Update the window
App.Display();
}
std::cout<<" thank you for using the program ";
getchar();
return EXIT_SUCCESS;
}