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

Pages: [1]
1
General / How to pass current instance of a window for input?
« on: January 12, 2012, 11:53:49 pm »
Ok, I just looked over your tut. on the service provider. I am going to implement that idea into my program and let you know how it goes. I do not have my tile engine up and running yet, but if all complies fine then it's a good start.

2
General / How to pass current instance of a window for input?
« on: January 12, 2012, 08:29:11 pm »
Ok, I appreciate your reply. You made several good points. I will have to keep this in mind. I'll have to review your tutorial as it seems it goes over exactly what i'm trying to accomplish.

If I understand you right this is how I could create a buffer between my code and SFML:

/////Only reason I define functions in the same file as the header is to save space////
Code: [Select]

class SFMLInput
{
private:

public:
bool IsKeyDown(sf::Input & Input, sf::Key::Code KeyCode)
{return (input.IsKeyDown(Keycode));}
//...
};

class GenInput
{
private:
//...
public:
bool IsKeyDown(Keycode keycode)
{return (SFMLInput.IsKeyDown(keycode));}
}


Is this somewhat what you're talking about? With this example it seems I would run into the problem of separating Keycodes from SFML's keycodes.  The first solution I see is to create my own enum of keycodes, but that is kind of redundant and doesn't reuse code, so probably a bad idea.

So unless I can use a reference or pointer to an enum (i've never really tried), i'm going to have to think this through further. I could use a get function to return the value of the key, so:

Code: [Select]

class SFMLInput
{
public:
//Get functions for all keys I would use
int GetKeyW() {return sf::Key::W;}
//...
};

class GenInput
{
bool IsKeyDown(int KeyCode)
{return SFMLInput.IsKeyDown(KeyCode);}

//And Could Be Used As Such///

class SomethingToDoWithSpriteMovement
{
private:
vector2 position;
GenInput genInput;
SFMLInput sfmlInput;
public:
void move() {
if (genInput.IsKeyDown(sfmlInput.GetKeyW()))
    position.x += speed;

};





If I don't get this implemented 100% I won't mind but it is good practice to try anyway.

I am more concerned with my game's architecture and class structure.

[EDIT]

I just realized I messed this up because I was not passing sf::Input to SFMLInput.IskeyDown.

So this doesn't work.  :(

3
General / How to pass current instance of a window for input?
« on: January 12, 2012, 06:35:06 am »
Hey all,
I'm trying to construct an input class so that my game can be cleanly separated from SFML in-case the framework changes or I change frameworks.

However, i'm having a problem figuring out how to pass the current instance of a window to another class.

I have a main game class that contains all the usual init, game loop, update, draw and cleanup functions. This class also initializes the current window.

I wrote a function that returns the current window in hopes I could use it to write my input class (since sf::input is partnered with a window instance):

Code: [Select]

sf::Window & getWindow()
 {return window;}


However, when I go to my input class I still need to write this:

Code: [Select]

Game game
sf::Input input = game.getWindow().GetInput();


Which is really awkward and actually doesn't work. I think I'm complicating this matter too much.

How can I pass an instance of a window to an input class?

I could write a function like:

Code: [Select]

bool leftKeyDown;

bool LeftKeyDown(sf::Input & input)
{
return (leftkeyDown = input.IsKeyDown(sf::Key::Left);)
}


Would this be more correct?

4
General / SFML Linker error vs 2010
« on: January 12, 2012, 06:24:21 am »
I forgot to add all of the dependencies. Here is a helpful tutorial that worked for me:

http://www.gamefromscratch.com/page/Game-From-Scratch-CPP-Edition-Part-1.aspx

5
General / SFML Linker error vs 2010
« on: January 10, 2012, 04:12:54 am »
Got it working.

6
General / SFML Linker error vs 2010
« on: January 10, 2012, 01:37:58 am »
Hey guys,
I'm trying to get SFML working on VS 2010 but i'm having problems with the compiler giving linker errors. I'm just trying to run a blank window to check everything is setup fine.

The odd thing is, if I include and run the code for the command line clock, I don't get any linker errors. However, when I try to create a blank window by including SFML/Window.hpp I am getting linker errors.

Are there any tutorials that cover SFML setup with VS 2010 that go through making a blank window?

The odd thing is, using the sf:: scope operator autocomplete recognizes the funtions that return linker errors. There must be something I did wrong with the project setup or files.

Any ideas?

Here is the code too:

Code: [Select]

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

int main()
{
sf::RenderWindow Game(sf::VideoMode(800, 600, 32), "SFML");

sf::Event Event;

while(Game.IsOpened())
{
while(Game.GetEvent(Event))
{
if(Event.Type == sf::Event::Closed)
Game.Close();
}

Game.Clear();

Game.Display();
}

return EXIT_SUCCESS;
}

Pages: [1]
anything