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

Author Topic: SubRect dont work  (Read 1948 times)

0 Members and 1 Guest are viewing this topic.

Rexona for men

  • Newbie
  • *
  • Posts: 24
    • View Profile
SubRect dont work
« on: August 28, 2011, 01:18:40 am »
Im really confused what is wrong in my code :shock:
All is fine but the sprite is full displayed and not only it's subrect.

Code: [Select]
#include "Racetrack.hpp"



int main()
{
    // Create the main rendering window
    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");

Racetrack::Init ("data/Track2.png");

Racetrack track1;
track1.GetSprite ().SetSubRect (sf::IntRect (100, 100, 200, 200) );
   
    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }
       
        // Clear the screen (fill it with black color)
App.Clear(sf::Color (sf::Uint8 (40), sf::Uint8 (200), sf::Uint8 (30) ) );

App.Draw (track1.GetSprite () );

        // Display window contents on screen
        App.Display();
    }

    return EXIT_SUCCESS;
}

Haikarainen

  • Guest
SubRect dont work
« Reply #1 on: August 28, 2011, 01:33:30 am »
Umm, we couldnt tell since you dont post the full code. (racetrack.hpp and cpp)

Rexona for men

  • Newbie
  • *
  • Posts: 24
    • View Profile
SubRect dont work
« Reply #2 on: August 28, 2011, 01:45:10 am »
Huh, dont think you need the code, im very sorry.

Code: [Select]
#include <SFML/Graphics.hpp>
#include <string>


class Racetrack
{
public:
Racetrack ();
sf::Sprite GetSprite ();
static void Init (const std::string& filename);

private:
sf::Sprite Tracksprite;
static sf::Image TrackImage;
};




Code: [Select]
#include "Racetrack.hpp"

Racetrack::Racetrack ()
{
Tracksprite.SetImage (TrackImage);
Tracksprite.SetPosition (100.0f, 100.0f);

}


sf::Sprite Racetrack::GetSprite ()
{
return Tracksprite;
}

sf::Image Racetrack::TrackImage;

void Racetrack::Init (const std::string& filename)
{
TrackImage.LoadFromFile (filename);
}

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
SubRect dont work
« Reply #3 on: August 28, 2011, 02:49:46 am »
It's simple really, GetSprite returns a copy of the sprite and not the actual sprite. So the changes you made was actually on a copy.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Rexona for men

  • Newbie
  • *
  • Posts: 24
    • View Profile
SubRect dont work
« Reply #4 on: August 28, 2011, 03:31:31 am »
Thanks for help, I defined a new memberfunction for setting the subrect :D