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.


Topics - CodingMadeEasy

Pages: [1]
1
General discussions / What is wrong with my tutorials?
« on: July 10, 2014, 12:47:45 am »
I did a search of my youtube channel name "CodingMadeEasy" and a couple of people have been saying not to follow my tutorials. They say I have no knowledge of C++ or Sfml and that people should avoid my tutorials at all cost.

My tutorials aren't designed to be the most optimized and use the newest code style that comes with c++ 11 and c++ 14 as well as using advanced algorithms to make things happen. They're there to show the basic code to get something on the screen, and enough knowledge to create a simple game. In no instance did I mention that my tutorials were to be watched over the docs. I even praise the docs in my tutorials and advise my subscribers to check it out for more in-depth knowledge of SFML.

Anyways what I want to know is what am I doing that is so crippling to the programming community. All I've seen people say is "Don't watch his tutorials" but no one explains why. I'm not looking for bashing or arguments just constructive criticism that's all.

Thanks for your time.

2
General / sf::View / sf::Shape Glitch
« on: February 27, 2013, 09:34:15 am »
When the view's center is set to the players position each frame, the player movement is fine but when the view is not centered to the players position, the rectangle jitters back and forth when receiving input commands.

Here's my code

#include<SFML/Graphics.hpp>
#include<string>
#include<iostream>

int main()
{
        sf::Vector2i screenDimensions(800, 600);

        sf::RenderWindow Window;
        Window.create(sf::VideoMode(screenDimensions.x, screenDimensions.y), "My First Sfml Game");

        //Window.setKeyRepeatEnabled(false);

        Window.setVerticalSyncEnabled(true);

        sf::Texture bTexture;
        sf::Sprite bImage;

        if(!bTexture.loadFromFile("Background.png"))
                std::cout << "Could not load backgorund image" << std::endl;

        bImage.setTexture(bTexture);

        sf::RectangleShape rect(sf::Vector2f(20, 20));
        rect.setFillColor(sf::Color::Red);

        sf::Clock clock;

        float moveSpeed = 2000.0f;

        sf::View view;
        view.reset(sf::FloatRect(0, 0, screenDimensions.x, screenDimensions.y));
        view.setViewport(sf::FloatRect(0, 0, 1.0, 1.0));

        sf::Vector2f position(screenDimensions.x / 2, screenDimensions.y / 2);
        view.setCenter(position);

        while(Window.isOpen())
        {
                clock.restart();
                sf::Event Event;
                while(Window.pollEvent(Event))
                {
                        switch(Event.type)
                        {
                        case sf::Event::Closed:
                                Window.close();
                                break;
                        case sf::Event::KeyPressed:
                                if(Event.key.code == sf::Keyboard::Escape)
                                        Window.close();
                                break;
                        }
                }
       
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
                        rect.move(moveSpeed * clock.getElapsedTime().asSeconds(), 0);
                else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
                        rect.move(-moveSpeed * clock.getElapsedTime().asSeconds(), 0);

                if(rect.getPosition().x + 10 > screenDimensions.x / 2)
                        position.x = rect.getPosition().x + 10;
                if(rect.getPosition().y + 10 > screenDimensions.y / 2)
                        position.y = rect.getPosition().y + 10;

                view.setCenter(position);
                Window.setView(view);

                Window.draw(bImage);
                Window.draw(rect);
                Window.display();
                Window.clear();
        }
}

 

3
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 :)

4
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]

5
Audio / Failed to open the audio device
« on: January 06, 2011, 05:55:15 am »
Hi. I'm trying to you music in my program but somethings wrong with
the audio class.

I include it
Code: [Select]

#include <SFML/Audio.hpp>


and whenever I create my music file I get an error in the console window that says

"Failed to open the audio device"

I've added the audio to the linker.
I've defined SFML_DYNAMIC.
I have everything in the right folder.
Graphics and stuff work fine. I just started on music today and now I can't figure out the problem.

Say I have a code like this

Code: [Select]

#include <SFML/Audio.hpp>

int main () {
sf::Music Music;
return 0;
}


I get the same error .. so what's going on with the Audio class?
[/code]

Pages: [1]
anything