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

Pages: [1]
1
General / SFML2.1 No Window.PollEvent
« on: August 12, 2013, 11:33:49 pm »
I don't have a pollEvent function under Window or RenderWindow.
I'm using Ubuntu and my IDE is Qt.

I linked SFML in the project File(.pro) that is made when using Qt
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += main.cpp \
    game.cpp

INCLUDEPATH += \Media\nickkorta\Shared\SFML-2.1\Linux\include
LIBS += -lsfml-system -lsfml-window -lsfml-graphics -lsfml-audio

HEADERS += \
    game.hpp

 

Here is my Game.h
#include "SFML/System.hpp"
#include"SFML/Graphics.hpp"
#include "SFML/Window.hpp"
#include "SFML/Audio.hpp"
#include "SFML/Network.hpp"


#ifndef GAME_HPP
#define GAME_HPP

class Game
{
public:
    Game();
private:
    void Initialize();
    void LoadContent();
    void Update();
    void Draw();
    bool running;
    sf::RenderWindow window;
    sf::Event event;
};

#endif // GAME_HPP
 

Game.cpp
#include "game.hpp"

Game::Game()
{
    Initialize();
    LoadContent();
    while(running)
    {
        Update();
        Draw();
    }
    window.Close();
}

void Game::Initialize()
{
    window.Create(sf::VideoMode(1080,720,32),"Game");
}

void Game::LoadContent()
{
}

void Game::Update()
{
    while (window.pollEvent(event))
    {
    }
}

void Game::Draw()
{
    window.Display();
    window.Clear();
}
 

Everything runs fine. I also noticed that I can move the window around and can use the maximize and minimize buttons. I have done this in windows and I cant do that without using Window.PollEvent(event).

Thanks

2
General / [Solved]Update function not working.
« on: August 07, 2013, 09:44:21 pm »
I have a very simple game class that has a update and draw function that calls on other classes update and function classes.

Game.h
#include <SFML/graphics.hpp>
#include "Unit.h"

#pragma once
class Game
{
public:
        Game(void);
        ~Game(void);
private:
        void Update();
        void Draw();

        sf::RenderWindow window;
        Unit unit;
};
 

game.cpp

#include "Game.h"


Game::Game(void)
{
        window.create(sf::VideoMode(800,600),"Game");

        while (window.isOpen())
        {
                Update();
                Draw();
        }
}


Game::~Game(void)
{
}

void Game::Update()
{
        sf::Event event;
       
        while (window.pollEvent(event))
        {
                if (event.type == sf::Event::Closed || event.key.code == sf::Keyboard::Escape )
                        window.close();
        }
        unit.Update(event);
}

void Game::Draw()
{
        window.clear(sf::Color(116,146,208));
        unit.Draw(window);
        window.display();
}
 

The problem is that my Unit class update function is not working but If I move the "Unit unit" object under game.h to game.cpp everything works just fine.

#include "Game.h"

Unit unit;

Game::Game(void)
{
        window.create(sf::VideoMode(800,600),"Game");

        while (window.isOpen())
        {
                Update();
                Draw();
        }
}


Game::~Game(void)
{
}

void Game::Update()
{
        sf::Event event;
       
        while (window.pollEvent(event))
        {
                if (event.type == sf::Event::Closed || event.key.code == sf::Keyboard::Escape )
                        window.close();
        }
        unit.Update(event);
}

void Game::Draw()
{
        window.clear(sf::Color(116,146,208));
        unit.Draw(window);
        window.display();
}
This brings me to the question is should I make objects and variables under Game.h or Game.cpp. Am im missing something fundamental.

Thanks

3
DotNet / Embed SFML Window in picturebox(Answered)
« on: August 01, 2013, 02:56:33 am »
Hi I'm using SFML.net 2.1. I'm trying to get a SFML window inside a picturebox but I am having no luck.

 public partial class Form1 : Form
    {
        private RenderWindow mapWindow;
        private bool running = true;

        public Form1()
        {
            InitializeComponent();
         
        }

        private void Draw()
        {
            Application.DoEvents();
            mapWindow.Clear(new SFML.Graphics.Color(101, 156, 239));
            mapWindow.Display();
            pictureBox1.Refresh();
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            running = false;
        }

        private void pictureBox1_LoadCompleted(object sender, AsyncCompletedEventArgs e)
        {
            mapWindow = new RenderWindow(this.pictureBox1.Handle);
            while (running)
                Draw();
        }
    }

I did manage to get a SFML RenderWindow embedded inside the form.
 public partial class Form1 : Form
    {
        private RenderWindow mapWindow;
        private bool running = true;

        public Form1()
        {
            InitializeComponent();
         
        }

        private void Draw()
        {
   
            Application.DoEvents();
            mapWindow.Clear(new SFML.Graphics.Color(101, 156, 239));
            mapWindow.Display();
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            running = false;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            mapWindow = new RenderWindow(this.Handle);
            while (running)
                Draw();
        }

    }
Thanks

4
Graphics / Window.Draw error LNK2001(Answered)
« on: July 31, 2013, 07:42:40 pm »
Hi I started using SFML with Visual Studio 2012 today.  Iv have not ran into any problems while rendering a Window , and using events such as keyboard, joystick , window and mouse. I'm trying to display an image on screen using the "Texture" and "Sprite" Class. My image is called "Mage" witch is a png file that is in the same folder as Main. I get this error when I use write "Window.Draw(sprite)".

Error   1   error LNK2001: unresolved external symbol "public: static class sf::RenderStates const sf::RenderStates::Default" (?Default@RenderStates@sf@@2V12@B)   c:\Users\nicho_000\documents\visual studio 2012\Projects\XXX\XXX\Main.obj

My Code
#include<SFML/Graphics.hpp>

void LoadContent();
void Update();
void Draw();

sf::RenderWindow window;
sf::Texture texture;
sf::Sprite sprite;

int main()
{
        window.create(sf::VideoMode(800,600),"Game");
        LoadContent();
        while (window.isOpen())
        {
                Update();
                Draw();
        }
}

void LoadContent()
{
        texture.loadFromFile("Mage.png");
        sprite.setTexture(texture);
}

void Update()
{      
       sf::Event event;
        while (window.pollEvent(event))
        {
                if (event.type == sf::Event::Closed || event.key.code == sf::Keyboard::Escape )
                        window.close();
        }
}

void Draw()
{
        window.clear(sf::Color(116,146,208));
        window.draw(sprite);
        window.display();
}

Thanks

Pages: [1]
anything