• Create Account

### #ActualCryusaki

Posted 15 August 2013 - 10:42 PM

So I created a basic pong game in SFML using a single main.cpp file. Now I want to better organize the game so I created a seperate class to handle loading in the sprites, displaying them and then destroying them. I wanted to keep everything simple so I made sure the loading in file was under Public:

This is a line of code I use to load in a sprite

    sf::Texture paddle;
sPaddle.setTexture(paddle); 

So in the main program I make a call to that function however when I debug and run the program it says that sPaddle was not declared in this scope. The function was called directly after declaring my variables and initializing the screen. Also the function is in the public section of the class. The line of code that is trying to call sPaddle specifically

sPaddle.setPosition(0, SCREENHEIGHT/2 - (PADDLEHEIGHT/2));


comes directly after. What is wrong?

I never uploaded code before so if you need to look at it just let me know, Thanks

### #3Cryusaki

Posted 15 August 2013 - 10:42 PM

So I created a basic pong game in SFML using a single main.cpp file. Now I want to better organize the game so I created a seperate class to handle loading in the sprites, displaying them and then destroying them. I wanted to keep everything simple so I made sure the loading in file was under Public:

This is a line of code I use to load in a sprite

So in the main program I make a call to that function however when I debug and run the program it says that sPaddle was not declared in this scope. The function was called directly after declaring my variables and initializing the screen. Also the function is in the public section of the class. The line of code that is trying to call sPaddle specifically

sPaddle.setPosition(0, SCREENHEIGHT/2 - (PADDLEHEIGHT/2));


comes directly after. What is wrong?

I never uploaded code before so if you need to look at it just let me know, Thanks

### #2Cryusaki

Posted 15 August 2013 - 10:41 PM

So I created a basic pong game in SFML using a single main.cpp file. Now I want to better organize the game so I created a seperate class to handle loading in the sprites, displaying them and then destroying them. I wanted to keep everything simple so I made sure the loading in file was under Public:

This is a line of code I use to load in a sprite

So in the main program I make a call to that function however when I debug and run the program it says that sPaddle was not declared in this scope. The function was called directly after declaring my variables and initializing the screen. Also the function is in the public section of the class. The line of code that is trying to call sPaddle specifically

sPaddle.setPosition(0, SCREENHEIGHT/2 - (PADDLEHEIGHT/2));


comes directly after. What is wrong?

I never uploaded code before so if you need to look at it just let me know, Thanks

### #1Cryusaki

Posted 15 August 2013 - 09:56 PM

So I created a basic pong game in SFML using a single main.cpp file. Now I want to better organize the game so I created a seperate class to handle loading in the sprites, displaying them and then destroying them. I wanted to keep everything simple so I made sure the loading in file was under Public:

This is a line of code I use to load in a sprite

    if(!paddle.loadFromFile("Paddle.png"))

sPaddle.setPosition(0, SCREENHEIGHT/2 - (PADDLEHEIGHT/2));