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 - lorence30

Pages: [1] 2 3 ... 9
1
General / menu design
« on: July 06, 2016, 01:45:37 pm »
hi guys, i wonder what would be the best design for menu.
my menu will have
-START
-DIFFICULTY
-EXIT

take a look at my class: http://pastebin.com/WwhUCFn0
i dont know if this will be a good class design  for my menu

I EDITED THE LINK PLEASE LOOK AGAIN.

2
General / best practice
« on: June 20, 2016, 08:52:56 pm »
hello, is it only alright to update an object outside the event loop?
since it doesnt have to do anything with events.
 
while(window.isOpen())
    {
        sf::Event e;
        while(window.pollEvent(e))
        {
            if ( sf::Event::Closed == e.type)
                window.close();
        }

        w.update(timer.getElapsedTime().asSeconds());
        timer.restart();

        window.clear();
        w.draw(window);
        window.display();
    }

3
Window / Re: sf::Event::Keypress problem
« on: April 30, 2016, 01:59:52 pm »
okay thanks for reply.

fixed , i just changed if ( isPlayer1 ) to if ( !isPlayer1 )

4
Window / Re: sf::Event::Keypress problem
« on: April 27, 2016, 11:47:27 pm »
EDITED

5
Window / sf::Event::Keypress problem
« on: April 27, 2016, 11:42:47 pm »
hello,
so i have this code
Paddle::Paddle()
{
        dir = sf::Keyboard::Unknown; // dir is of type sf::Keyboard::Key
}
void Paddle::update(bool isPlayer1,float delta)
{
    if ( isPlayer1 )
    {
        if ( dir == sf::Keyboard::Up  )
        {
            pad.move(0,(-speed)*delta);
        }
        if ( dir == sf::Keyboard::Down  )
        {
            pad.move(0,speed*delta);
        }
    }
    else
    {
        std::cout << dir << std::endl;
        if ( dir == sf::Keyboard::W  )
        {
            pad.move(0,(-speed)*delta);
        }
        if ( dir == sf::Keyboard::S  )
        {
            pad.move(0,speed*delta);
        }
    }
}

void Paddle::setDir(sf::Keyboard::Key key)
{
    dir = key;
}

 


on the Game class i have this

void Game::start()
{
while(window->isOpen())
{
  event();
  update();
  render();
}
}
void Game::event()
{
    sf::Event e;
    while(window->pollEvent(e))
    {
        if ( e.type == sf::Event::KeyPressed )
        {
            if ( e.key.code == sf::Keyboard::Up || e.key.code == sf::Keyboard::Down )
                player2.setDir(e.key.code); // player2 is a Paddle type
            else if ( e.key.code == sf::Keyboard::W || e.key.code == sf::Keyboard::S )
                player1.setDir(e.key.code); // player1 is a Paddle type
        }
        else if ( e.type == sf::Event::KeyReleased )
        {
            if ( e.key.code == sf::Keyboard::Up || e.key.code == sf::Keyboard::Down )
                player2.setDir(sf::Keyboard::Unknown);  // player2 is a Paddle type
            else if ( e.key.code == sf::Keyboard::W || e.key.code == sf::Keyboard::S )
                player1.setDir(sf::Keyboard::Unknown); // player1 is a Paddle type
        }
    }
}

void Game::update()
{
     player1.update(true,somedelta);
     player2.update(false,somedelta);
}
 

when ever i hold S key nothign happens.
the line
 std::cout << dir << std::endl;  
always output -1 which is its default value sf::Keyboard::Unknown it should output 18 which is sf::Keyboard::S

6
Graphics / Re: sf::Texture getSize() crashes the program
« on: April 13, 2016, 10:36:13 pm »
i thought it already has a texture and its size is 50x50
thanks :)

7
Graphics / sf::Texture getSize() crashes the program
« on: April 12, 2016, 08:57:38 pm »
Hello, i have a problem
my problem gets crashed whenever i get the size of square, even in circle and other shapes

int main()
{
     sf::RectangleShape square(sf::Vector2f(50,50));
     std::cout << square.getTexture()->getSize().x;
}

8
Audio / audio error
« on: December 06, 2015, 08:37:57 am »
Failed to play audio stream: sound parameters have not been initialized (call initialize() first)
can someone tell me the cause of that error?

9
Graphics / resource manager
« on: December 05, 2015, 03:15:04 pm »
std::map doesnt store the pair if the key  has conflict
ie:
std::map<std::string,int> test;
test["One"] = 1;
test["One"] = 2;
std::cout << test.size(); // outputs 1

so in the resource manager of sfml essentials book
why it still need to check if the requested resource to load is already loaded before loading?

10
Audio / Re: stack allocated sf::Music
« on: November 30, 2015, 09:25:38 am »
thanks guys


im using QT and SFML audio , i was trying to inherit sf::Music to my Track class and just add a feature for std::string name so i can keep track of the name of the song, so if the user double clicks the song i will just find the name matches with the name being clicked then play the Track::audio

11
Audio / stack allocated sf::Music
« on: November 29, 2015, 03:42:50 pm »
why cant I allocated sf::Music on stack

heres my code:
class Track
{
   public:
       Track(const std::string&);
       const std::string& getName() const;
       const sf::Music& getAudio() const;
   private:
       std::string name;
       sf::Music audio;
};
this spits out:
error: use of deleted function 'sf::Music::Music(const sf::Music&)'
error: use of deleted function 'sf::SoundStream::SoundStream(const sf::SoundStream&)'
error: use of deleted function 'sf::Mutex::Mutex(const sf::Mutex&)'
error: 'sf::NonCopyable::NonCopyable(const sf::NonCopyable&)' is private NonCopyable(const NonCopyable&);
error: use of deleted function 'sf::InputSoundFile::InputSoundFile(const sf::InputSoundFile&)'
 error: use of deleted function 'sf::Mutex::Mutex(const sf::Mutex&)'
 class SFML_AUDIO_API Music : public SoundStream
 error: use of deleted function 'Track::Track(Track&&)'

but when i allocate it on heap like this:

class Track
{
   public:
       Track(const std::string&);
       const std::string& getName() const;
       const sf::Music& getAudio() const;
   private:
       std::string name;
       sf::Music* audio;
};
it works fine

TIA.

12
Network / conflicting use of packet
« on: November 18, 2015, 07:11:43 pm »
should i have more than one packet in a class?
for example in chat app.

theres a:
- list of people in the chat room
     - people who joins the room
     - people who leaves the room
- messaging system


so i only have one sf::Packet in my class
class ClientManager
{
    public:
         void sendPacket();
         void receivePacket()
         {
                socket.receive(packet);
         }
         sf::Packet packet;
}


class MainWindow
{
     public:
 
          void leavesTheChatRoom()
          {
                 client.packet << "my name"; // send it, so everybody knows who leaves the room
                 client.sendPacket();
          }
          void sendMessage()
          {
                 client.packet << "my message"; // send the message to everybody
                 client.sendPacket();
          }
          void receiveMessage()
          {
                client.receivePacket();
          }
    private:
          ClientManager client;

}

as you can see in the code, 3 functions can use the packet at the same time
- you send a message at the same time someone leaves the room
- you receive a message at the same time you send a message
- etc.

so if thats happens, the packet will have your message and the message of other client and the name in it

13
Network / Re: packet sending through tcpsocket corrupted
« on: November 17, 2015, 11:33:44 am »
Shouldn't you extract the name first, and then the integer?
wtf that fixes it, lmfao. i thought i can extract it in not in order.


And all these "== 0" are really ugly, use sf::Socket::Done to improve the readability of your code.
yea thanks i was just lazy typing sf::Socket::Done XD

This is explained in the tutorial
ive read about it, im just using int because its short and planning to replace with fixed size when the program is done.

thanks guys, i was so stupid

14
Network / Re: packet sending through tcpsocket corrupted
« on: November 17, 2015, 10:58:43 am »
sfml is enough to make  a chat program, i already use sfml before, all my crappy games are written in sfml.
i want my lui chat program to have a gui in it

15
Network / Re: packet sending through tcpsocket corrupted
« on: November 16, 2015, 07:02:38 pm »
i cant send compilable sample, because im working with qt and sfml, and the classes are so big now. i cant cut it


Pages: [1] 2 3 ... 9