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

Pages: 1 [2] 3
16
General discussions / Re: SFML 2.0 Tutorials?
« on: February 27, 2013, 09:19:51 am »
Sorry for reviving an old topic but if anybody is in need of some sfml 2.0 tutorials then you can always check here. I have started a new sfml 2.0 tutorial series.



Currently there's 16 tutorials but there's lot more to come.

17
Graphics / Re: Problem with Window.EnableKeyRepeat and arrow keys
« on: September 25, 2012, 07:20:23 pm »
Yea i understand that but why does it work for all keys except for the arrow keys when I use it outside the event loop?

18
Graphics / Re: Problem with Window.EnableKeyRepeat and arrow keys
« on: September 25, 2012, 06:58:44 pm »
Sorry for the late reply but I have the code at home. But the inputmanager is essentially used like this

(dummycode.h)

#include "InputManager.h"

class Dummy
{
    public:
        void LoadContent();
        void UnloadContent();
        void Update(sf::RenderWindow &Window, sf::Event event);
        void Draw(sf::RenderWindow);
    private:
        InputManager input;
};
 

(dummycode.cpp)

#include "dummycode.h"

void DummyCode::LoadContent()
{
}

void DummyCode::UnloadContent()
{
}

void DummyCode::Update(sf::RenderWindow &Window,  sf::Event event)
{
    input.Update(event);
    if(input.KeyPressed(sf::Key::Up))
       // do something
}

void DummyCode::Draw(sf::RenderWindow &Window)
{
}
 


(main.cpp)

#include "dummycode.h"

int main()
{
    // all the initialize stuff

    DummyCode dummyCode;
   
    dummyCode.LoadContent();
   
    while(Window.IsOpened())
    {
        sf::Event event;
       while(Window.GetEvent(event))
       {
            // do the event loop actions
       }

        dummyCode.Update(Window, event);
        dummyCode.Draw(Window);

        Window.Display();
    }
}
 

19
Graphics / Re: Problem with Window.EnableKeyRepeat and arrow keys
« on: September 22, 2012, 08:18:10 pm »
Ok I figured out the problem but I don't know how to fix it. Ok well my input manager is not running in the event loop. When I run this code in the event loop it runs fine

if(event.Type == sf::Event::KeyPressed && event.Key.Code == sf::Key::Up)
    std::cout << "UP" << std::endl;
 

When I run it outside of the event loop that's when things go wrong but the weird thing is that if you change sf::Key::Up to sf::Key::W then it works fine even if it's outside the event loop : /

20
Graphics / Re: Problem with Window.EnableKeyRepeat and arrow keys
« on: September 22, 2012, 08:10:48 pm »
I will try that right now and I'm using Windows 7. Also if you must know. I'm using sfml 1.6

21
Graphics / Problem with Window.EnableKeyRepeat and arrow keys
« on: September 22, 2012, 07:18:41 pm »
I have created an inputmanager class which handles all the input in my game. What I have done is set EnableKeyRepeat to false so that it helps for single key presses. Anyways it works fine until you try to check for input using the arrow keys.

Whenever I do input using the arrow keys it treats it as continuous input but when I use other key codes it treats it as a single key press :/. Here's my inputmanager code

InputManager.h

#ifndef INPUTMANAGER_H
#define INPUTMANAGER_H

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

class InputManager
{
    public:
        InputManager();
        ~InputManager();

        void Update(sf::Event event);

        bool KeyPressed(int key);
        bool KeyPressed(std::vector<int> keys);

        bool KeyReleased(int key);
        bool KeyReleased(std::vector<int> keys);

        bool KeyDown(sf::RenderWindow &Window, sf::Key::Code key);
        bool KeyDown(sf::RenderWindow &Window, std::vector<sf::Key::Code> keys);
    protected:
    private:
        sf::Event event;
};

#endif // INPUTMANAGER_H

 

InputManager.cpp

#include "InputManager.h"

InputManager::InputManager()
{
    //ctor
}

InputManager::~InputManager()
{
    //dtor
}

void InputManager::Update(sf::Event event)
{
    this->event = event;
}

bool InputManager::KeyPressed(int key)
{
    if(event.Key.Code == key && event.Type == sf::Event::KeyPressed)
        return true;
    return false;
}

bool InputManager::KeyPressed(std::vector<int> keys)
{
    for(int i = 0; i < keys.size(); i++)
    {
        if(KeyPressed(keys[i]))
            return true;
    }
    return false;
}

bool InputManager::KeyReleased(int key)
{
    if(event.Key.Code == key && event.Type == sf::Event::KeyReleased)
        return true;
    return false;
}

bool InputManager::KeyReleased(std::vector<int> keys)
{
    for(int i = 0; i < keys.size(); i++)
    {
        if(KeyReleased(keys[i]))
            return true;
    }
    return false;
}

bool InputManager::KeyDown(sf::RenderWindow &Window, sf::Key::Code key)
{
    if(Window.GetInput().IsKeyDown(key))
        return true;
    return false;
}

bool InputManager::KeyDown(sf::RenderWindow &Window, std::vector<sf::Key::Code> keys)
{
    for(int i = 0; i < keys.size(); i++)
    {
        if(Window.GetInput().IsKeyDown(keys[i]))
            return true;
    }
    return false;
}

 

Thanks in advance :)

22
Audio / Window Crashes when loading sound and music
« on: February 03, 2011, 02:30:27 am »
Nothing. And that's the weird thing. I just can't figure out the problem

23
Audio / Window Crashes when loading sound and music
« on: February 02, 2011, 11:22:02 pm »
Hi Everybody. For some reason I can't load sounds or music in sfml anymore. I got it to work and I used music in a lot of my other programs but not suddenly it won't work! It won't even display an error message , the window just crashes when it tries to load the file , which generally shouldn't happen

Here's my code

Code: [Select]


void Sound::LoadSound (const char* filename, int linenum) {
  string test;
  ifstream openfile (filename);

    cout << "opened " << filename << endl;
    for (int i = 0; i <= linenum; i ++) {
      if (openfile.is_open())
        openfile >> test;
    }
    //name = "Sound/audio.wav";
    cout << "Done" << endl;
    cout << test << endl;
    if (SoundBuf.LoadFromFile(test)) {
      cout << "Loaded " << test << " successfully" << endl;
      SoundInst.SetBuffer (SoundBuf);
    }
    else
      cout << "Failed" << endl;

} // End of LoadSound ( , )

void Sound::LoadMusic (const char* filename, int linenum) {
  ifstream openfile;
  string testing;
  openfile.open(filename, ifstream::in);
  for (int i = 0; i <= linenum; i ++)
    openfile >> testing;

    cout << testing << endl;

  if (MusicInst.OpenFromFile (testing))
    cout << "Loaded " << testing << " successfully" << endl;
} // End of LoadMusic ( , )



I used cout to see it if got the directory right and it works I just don't know why the sound and music won't load and why it crashes the window.

I'm using sfml 1.6 on windows vista and I'm using code::blocks

Help would be greatly appreciated :D[/code]

24
Audio / Crashing after "Failed to open the audio device".
« on: February 02, 2011, 10:48:40 pm »
I know this post is over a year old but just so people in the future can see how to solve this problem I'll post it here. What you have to do is copy all those .dll files to your debug folder.  I had the same problem and I just did that and it works now. It sometimes says failed to load audio device but when I run it immediately after it runs fine with the sound and everything! :D

So I hope that this helps anybody who happens to see this in the future

25
Audio / Failed to open the audio device
« on: January 11, 2011, 10:29:31 pm »
When I put all the audio (.dll) files in the debug folder it works.... but why doesn't this happen with graphics?

26
Audio / Failed to open the audio device
« on: January 11, 2011, 05:55:10 pm »
I'm using Code::Blocks and I have the music files in my project folder. I put the graphics in the same place and the graphics work fine .... maybe I should put the .dll files in the same folder as the .exe file.. maybe it will work then ... when I reach home I'll test it out and tell you the results

but how would you set the working directory in code::blocks?

27
Audio / Failed to open the audio device
« on: January 10, 2011, 11:37:42 pm »
Ok this is weird.... Now I've made my file into an executable file and when I run the executable (.exe) file the sound works fine. But when I run it in the compiler it doesn't play :/

28
Audio / Failed to open the audio device
« on: January 10, 2011, 10:54:07 pm »
I remember it saying earlier that I needed to use the initialize function .... but I didn't because I saw examples where you didn't need it .... and then after a while it said that it failed to open the audio device...

does that have anything to do with it?

29
Graphics / Comments on first game.
« on: January 10, 2011, 10:42:55 pm »
np just trying to help :D .. Hope I didn't sound toooo negative

30
Audio / Failed to open the audio device
« on: January 10, 2011, 10:41:35 pm »
So loading the sound is the problem?

Pages: 1 [2] 3