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

Pages: 1 [2]
16
Window / Problem trying setup and draw window using multiple files
« on: October 04, 2010, 07:07:59 pm »
I'm a beginner programmer looking to try and create a simple game engine in SFML.

I've successfully managed to compile a program that has a movable sprite on a screen while putting everything inside main, but when I want to split it into seperate source files I can't get it to work.

Currently I have three files main.cpp, myengine.h, myengine.cpp

main.cpp
Code: [Select]

#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include "myengine.h"

int main()
{
    // Create window and initialise game
    MyEngine game;

    game.Init(800,600);

    // Start the game loop
    while (game.Running())
        {
            game.Events();
            game.Draw();
        }

    return EXIT_SUCCESS;

}


myengine.h
Code: [Select]

#ifndef MYENGINE_H
#define MYENGINE_H

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

using namespace std;

class MyEngine
{
    private:

    public:

    void Init(int height, int width);
    void Events();
    void Input();
    void Update();
    void Draw();
    void Cleanup();

    sf::RenderWindow& GetWindow();
    sf::Event Event;
    sf::RenderWindow App;

    bool m_running;

bool Running()
{
    return m_running;
}
void Quit()
{
    m_running = false;
}

};

#endif


myengine.cpp
Code: [Select]

#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include "myengine.h"

void MyEngine::Init(int height, int width)
{
    sf::RenderWindow App(sf::VideoMode(height, width, 32), "MyEngine");
    App.SetActive();
    App.SetFramerateLimit(60);
    m_running = true;
}

void MyEngine::Events()
{
    while (App.GetEvent(Event))
    {
        // Close window : exit
        if (Event.Type == sf::Event::Closed)
        Quit();

    }
}

void MyEngine::Draw()
{
    App.Clear();
    App.Display();
}


The object is to just draw a black window to screen. I'm aware there are probably a plethora of problems with this code, but advice on which direction to look in would be greatly appreciated!

Pages: 1 [2]