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

Pages: [1]
1
General / Getting an object from another file
« on: April 14, 2011, 03:08:45 am »
I haven't known C++ for long. I am learning by making a game with SFML.

I tried making a pointer of the instance of the sf::RenderWindow class. I couldn't quite get it to work. I also tried declaring the instance inside of my Window class, but I couldn't access it in my Input.cpp, so I just put it inside of an unnamed namespace (learned that from someone else's code).

2
General / Getting an object from another file
« on: April 12, 2011, 03:48:19 am »
I am trying to make a window class and an input handling class. I created an instance of sf::RenderWindow in the Window.cpp. I need to use this object in my Input.cpp file. What would be the best way of doing this?
Window.cpp
Code: [Select]

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

namespace
{
       sf::RenderWindow window; //This is the object I need
       sf::Event Event;
}

Window::Window(int sizeX, int sizeY)
{
       width = sizeX;
       height = sizeY;
       scaleX = (scaleX * (width / 800));
       scaleY = (scaleY * (height / 600));
}


Input.cpp
Code: [Select]

#include "Input.hpp"
#include "Window.hpp"

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

namespace
{
       const sf::Input &input = window.GetInput(); //window not declared in this scope
}

Input::Input()
{
      while (input.IsKeyDown(sf::Key::Left)){
              Input::LeftKeyDown = true;}
      Input::LeftKeyDown = false;

Pages: [1]
anything