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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Cayle

Pages: [1]
1
General / Game Program (Pong Movement Stutter)
« on: December 06, 2013, 03:06:06 pm »
Hi, I am makeing a pong game, and for my movement, the paddle stutters when it moves, like when you hold down a letter on the keyboard. Taking that in mind I compensated for it in my code. The same strategy worked in another program but not in this one.

main(pong)
pong.cpp:
Code: [Select]
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include "paddle.hpp"

/* Program Flow
init -> mainMenu -> game -> exit / main
*/

int main(){
paddle cayle;
sf::RenderWindow window(sf::VideoMode(800,600), "Pong -By Cayle");
cayle.createSprite();
window.setVerticalSyncEnabled(true);
while(window.isOpen()){
sf::Event event;

while(window.pollEvent(event)){

if(event.type == sf::Event::Closed){window.close();}
cayle.processEvent(event);
}

window.clear(sf::Color::Black);
window.draw(cayle.sprite);
window.display();
}
return 0;
}

paddle class:

Code: [Select]

#include <string>
#include <SFML/Graphics.hpp>
#include "paddle.hpp"

int paddle::getInt(std::string var){
int data;

if(var == "xPos"){
data = this -> xPos;
}else if(var == "yPos"){
data = this -> yPos;
}else if(var == "length"){
data = this -> length;
}
return data;
}

int paddle::move(int distance){
this -> yPos += distance;
return this -> yPos;
}

void paddle::createSprite(){
this -> texture.loadFromFile("../resources/paddleTexture.png");
this -> sprite.setTexture(texture);
}
void paddle::processEvent(sf::Event event){


bool upPress, downPress, leftPress, rightPress;

if(event.type == sf::Event::KeyPressed){

if(event.key.code == sf::Keyboard::Left){
leftPress = true;
}
if(event.key.code == sf::Keyboard::Right){
rightPress = true;
}
if(event.key.code == sf::Keyboard::Up){
upPress = true;
}
if(event.key.code == sf::Keyboard::Down){
downPress = true;
}
}

if(event.type == sf::Event::KeyReleased){

if(event.key.code == sf::Keyboard::Left){
leftPress = false;
}
if(event.key.code == sf::Keyboard::Right){
rightPress = false;
}
if(event.key.code == sf::Keyboard::Up){
upPress = false;
}
if(event.key.code == sf::Keyboard::Down){
downPress = false;
}
}

if(upPress){this -> yPos -= this -> speed;}
if(downPress){this -> yPos += this -> speed;}
sprite.setPosition(this -> xPos, this -> yPos);

}

paddle class header:

Code: [Select]
#ifndef PADDLE_HPP
#define PADDLE_HPP
#include <string>
#include <SFML/Graphics.hpp>
class paddle{
private:


int speed;
int length;


public:
int xPos;
int yPos;
paddle(){
xPos = 60;
yPos = 300;
speed = 7;
length = 80;
}
sf::Texture texture;
sf::Sprite sprite;
void createSprite();
void processEvent(sf::Event);
int move(int distance);
int getInt(std::string var);
};

#endif

2
Graphics / Screenshot whenever I create a window.
« on: December 01, 2013, 12:43:45 am »
Hey guys, I have my code below. The problem is that when I create the window it just takes a screen shot of whatever is behind it, I tried using the clear command but it doesn't work.


#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>


using namespace std;

int main(){
sf::RenderWindow splashScreen(sf::VideoMode(180, 160), "Naval Command!");


       
while(splashScreen.isOpen()){
        splashScreen.clear();
                sf::Event event;

                while(splashScreen.pollEvent(event)){

                        if(event.type == sf::Event::Closed){
                                splashScreen.close();
                        }
                       
                }
}
return 0;
}
 

3
General / Re: Using SFML in Sublime Text 3
« on: November 17, 2013, 11:45:58 pm »
I know this is dumb, but could you give an example?

4
General / Using SFML in Sublime Text 3
« on: November 17, 2013, 06:42:02 pm »
Hey guys, I am an relatively advanced beginner in c++, and I feel I am ready to start working with graphics. I use sublime text 3 as my editor of choice, and would like to know how to use SFML through it. If someone could give a detailed description on that I would be super happy, thanks.

Pages: [1]