Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Text and sprite in the guise  (Read 1232 times)

0 Members and 1 Guest are viewing this topic.

Mina66

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
Text and sprite in the guise
« on: March 02, 2013, 03:00:41 am »
Hello!
Tell me how can I do?
To moving text or sprite was visible like a mask. For the red box could not see them.


The result should look like this:
http://minimultik.ru/animashka/1303012052529b259bbe28b1a2ad

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Text and sprite in the guise
« Reply #1 on: March 02, 2013, 03:03:35 am »
You could draw your text on a view with a custom viewport.

Mina66

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
Re: Text and sprite in the guise
« Reply #2 on: March 02, 2013, 03:14:48 am »
I tried and failed.
#include <iostream>
#include <SFML\Graphics.hpp>


int main()
{


    sf::VideoMode VMode(720, 576, 32);
    sf::RenderWindow Window(VMode, "sfml", sf::Style::Close);
    //Window.setFramerateLimit(60);
    Window.setVerticalSyncEnabled(true);

    sf::Texture texture;
    texture.loadFromFile("image.png");
    sf::Sprite sprite;
    sprite.setTexture(texture);
    sf::RenderTexture r_texture;
    r_texture.create(480, 48);
    r_texture.clear(sf::Color(100, 100, 100));
    sf::View view;
    view.reset(sf::FloatRect(0, 0, 480, 48));
    r_texture.setView(view);
    r_texture.draw(sprite);
    r_texture.display();

    sf::Sprite sprite_1;
    sprite_1.setTexture(r_texture.getTexture());

    while(Window.isOpen())
    {
        sf::Event Event;
        while(Window.pollEvent(Event))
        {
            switch(Event.type)
            {
                case sf::Event::Closed:
                    Window.close();
                    break;
                case sf::Event::KeyPressed:

                    if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
                        Window.close();

                    if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Left))
                        {
                            view.move(1, 0);
                        }

                    if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Right))
                        {
                            view.move(-1, 0);
                        }
                    break;

                default:
                    break;
            }
        }


        Window.clear(sf::Color(128, 128, 128));
        Window.draw(sprite_1);
        Window.display();
    }

    return 0;
}
 
« Last Edit: March 02, 2013, 03:42:12 am by Mina66 »

 

anything