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

Pages: [1]
1
Oh , I was thinking about that book but since you clarified what it has I'll just try to buy the digital version.

2
the ones where?

3
Thanks for the reply, the only reason I was fallowing his tutorial was to see how I would implement a way to manage everything separately for example to have : an Inputmanager, contentmanager, and even a player class to the current little game I have where its a top down shooter. The code that I have is all over the place and in Main.cpp, I want to see how I would organize  it better you know so the code could actually look like it was done for a game not a cake of things everywhere.

4
After a little more hard thinking and a hour later I think i found the solution but please correct me if this is wrong . I only assume is correct since I dint receive any compile error :D

SFML 2.1
InputManager.h
   bool KeyDown(sf::Keyboard::Key key);
   bool KeyDown(std::vector<sf::Keyboard::Key> keys);
 
and InpuManager.cpp
bool InputManager::KeyDown(sf::Keyboard::Key key)
{
        if (sf::Keyboard::isKeyPressed(key))
                return true;
        return false;

}

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

So far that was my pain in the behind. Also and to explain what I did to justify if I'm actually right or not or just to explain my way of thinking on why I did it that way. Well, after 20 minutes of plundering the Docs there was only one way to implement Keyboard::isKeyPressed(Key key) <---- I didn't notice that until 20+ more minutes later before that rock hit my head, I kept doing what I showed you in the first post without any success. So the solution was that if i passed a sf::Keyboard::Key type to the function and in the cpp I utilized the magic of isKeyPressed everything would work. Sorry if my way of explaining is harsh to grasp, my c++ wording isn't at it's perfection yet.


PS. If there's a better way please tell me :D

5
So I have stumbled into a minor blockade again fallowing an old tutorial that I have managed to slowly convert into 2.1.
The problem here is that since window.GetInput() is no Longer Usable since that function is from SFML 1.6, I found that the new way to do things in 2.1 is different. I'll post the sample of code in case someone in the future is fallowing the CodingMade Easy Platformer tutorials.


SFML 1.6
InputManager.h
#ifndef INPUTMANAGER_H
#define INPUTMANAGER_H

#include <vector>
#include <SFML/Window.hpp>
#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,int key);
        bool KeyDown(sf::RenderWindow &Window, std::vector<int> keys);
private:
        sf::Event event;
};

#endif
InputManager.cpp
#include "InputManager.h"


InputManager::InputManager()
{
}


InputManager::~InputManager()
{
}

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

bool InputManager::KeyPressed(int key)
{
        if (event.Key.Code == key)
                return true;
}

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

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

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

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

}

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

You can Notice the difference Since in 1.6 you have to put "event.Key.Code" in capitals while in 2.1 is lower case.

SFML 2.1
The Guy has alot of errors in his "C++ Sfml Platformer Made Easy Tutorial 6 - InputManager [Part 1]" tutorial but he probably covers them in part 2.

The really problem that I'm trying to solve is How would I implement "sf::Keyboard::isKeyPressed"  in the header file would replacing things to this help:

        bool KeyDown(sf::Keyboard::isKeyPressed,int key);
        bool KeyDown(sf::Keyboard::isKeyPressed, std::vector<int> keys);

        //or would removing int key, and the vector help ?
 
if everything works Ill post the sfml 2.1 converted version here.

6
General / Re: Getting Error when creating a Singleton class
« on: January 04, 2014, 02:35:09 am »
:D The Guy Explained on the Video on why its bad, but it had a good use for what the tutorial was going to use them for.

7
General / Re: Getting Error when creating a Singleton class
« on: January 04, 2014, 01:53:38 am »
Okay, thanks you again :D

8
General / Re: Getting Error when creating a Singleton class
« on: January 04, 2014, 01:50:52 am »
This might sound dumb but what exactly ampersand (&) do?

Thank you for last responce, worked.

9
General / Getting Error when creating a Singleton class
« on: January 04, 2014, 01:44:10 am »
So I'm fallowing the CodingMadeEasy Platformer tutorial, but I have been doing sfml for a couple of days now so I know the syntax between 1.6 and 2.1 wont be much of a problem. But what is really getting to me is this problem.

Here is the Code First:
 ScreenManager.h
#ifndef SCREENMANGER_H
#define SCREENMANGER_H
#pragma once

#include <string>
#include <iostream>
class ScreenManager
{
public:
       
        ~ScreenManager();
        static ScreenManager GetInstance();

        void SetText(std::string text);
        void DrawText();
private:
        ScreenManager();
        ScreenManager(ScreenManager const&);
        void operator = (ScreenManager const&);

        std::string text;

};

#endif

 

ScreenManager.cpp
#include "ScreenManager.h"

ScreenManager &ScreenManager::GetInstance()
{
        static ScreenManager instance;
                return instance;
}

ScreenManager::ScreenManager()
{
}


ScreenManager::~ScreenManager()
{
}

 

The link to the video is

The compiler is telling me
Error   1       error LNK2019: unresolved external symbol "public: static class ScreenManager __cdecl ScreenManager::GetInstance(void)" (?GetInstance@ScreenManager@@SA?AV1@XZ) referenced in function "void __cdecl `dynamic initializer for 'sm''(void)" (??__Esm@@YAXXZ)     C:\Users\Vcjr\documents\visual studio 2013\Projects\Pwn or Die Trying\Pwn or Die Trying\ScreenManager.obj       Pwn or Die Trying

        3       IntelliSense: declaration is incompatible with "ScreenManager ScreenManager::GetInstance()" (declared at line 12 of "c:\users\vcjr\documents\visual studio 2013\projects\pwn or die trying\pwn or die trying\ScreenManager.h")  c:\Users\Vcjr\Documents\Visual Studio 2013\Projects\Pwn or Die Trying\Pwn or Die Trying\ScreenManager.cpp       3       31      Pwn or Die Trying

 

I know that c++ code could be outdate but I'm also very new to making classes and such.

Pages: [1]
anything