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

Author Topic: Problem with background texture  (Read 969 times)

0 Members and 1 Guest are viewing this topic.

ayang

  • Newbie
  • *
  • Posts: 1
    • View Profile
Problem with background texture
« on: March 19, 2020, 04:03:15 am »
Hello I am working on a Lynda learning tutorial and I am not sure why my background texture is not showing up. I am not getting any errors either. As for my project settings I added the path directory of SFML to the c++ and linker settings just like the tutorial said to do. It doesn't give me a file loading error either (I purposely changed it previously to get the loading error so I know it is finding the correct picture). I know there are some spots of comments that I haven't gotten to code in yet but the background image should be showing up at least already.





here is my code:




#include "pch.h"
#include <iostream>
#include <SFML\Graphics.hpp>


using namespace sf;




int main()
{
        //This creates an object  called vm from the class VideoMode


        VideoMode vm(1280,720);


        //This creates an object called window from the class RenderWindow


        RenderWindow window(vm, "Timber!!!", Style::Fullscreen);


       
       
        Texture textureBackground;






        // This creates the texture background


        textureBackground.loadFromFile("graphics/background-1280-720.png");








        Sprite spriteBackground;


        spriteBackground.setTexture(textureBackground);


        spriteBackground.setPosition(0, 0);






        while (window.isOpen())
        {
                /*
                This will handle the player's input
                */



                if (Keyboard::isKeyPressed(Keyboard::Escape))
                {
                        window.close();
                }




                /*
                Update scene coming soon
                */





                /*
                Draw the scene coming soon
                */





                /*
                This clears everything from the last frame
                */



                window.clear();




                //Draw game here coming soon




                //shows everything we just drew
                window.display();


                }


        return 0;
}

 
« Last Edit: March 19, 2020, 04:06:47 am by ayang »

G.

  • Hero Member
  • *****
  • Posts: 1592
    • View Profile
Re: Problem with background texture
« Reply #1 on: March 19, 2020, 04:18:33 am »
You have to draw your sprite if you want it to be drawn.
window.draw(spriteBackground);
somewhere between your clear and your display.

 

anything