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

Pages: [1] 2
1
General / Re: SFML2.1 No Window.PollEvent
« on: August 13, 2013, 12:29:32 am »
I download GCC-2 under Linux here. http://www.sfml-dev.org/download/sfml/2.1/
I'm pretty sure i'm using 2.1. I just re downloaded it and linked it up and everything is the same.

Edit: I went to windows and that is using SFML 2.1(Visual Studio) witch was downloaded at the same page.

2
General / Re: SFML2.1 No Window.PollEvent
« on: August 13, 2013, 12:07:55 am »
error: 'class sf::RenderWindow' has no member named 'PollEvent'

I does not show up under other members when typing window.

3
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

4
General / Re: Update function not working.
« on: August 09, 2013, 10:34:51 pm »
Makes sense. Thanks again. I should have caught that.

5
General / Re: Update function not working.
« on: August 09, 2013, 03:32:25 am »
[Answer]
setting Time to 0 did the trick. I still don't understand that it worked when the Unit object was declared in the .cpp file and not the header file.

Thanks

6
General / Re: Update function not working.
« on: August 08, 2013, 06:20:15 pm »
Ya the problem persists. I'm using Windows 8 and Visual studio 2012. Your animation with the shape was working when Unit unit was in the header file or the cpp file. Mine only works when Unit unit is declared in the cpp file.
Thanks for the help so far.

7
General / Re: Update function not working.
« on: August 08, 2013, 05:18:31 am »
I got rid of #pragma once in my Game.h and nothing happened. I also used std::cout and all the functions are being hit. I tested this in Unit Update and Draw, draw in spritebatch, and update in animatin2D. I also put break points and looked at what happening different and I found nothing.  With this said I am really Lost. Is it wrong practice to declare classes inside of .cpp files instead of the header files. I never had to worry about this in C# so code structuring your code correctly in C++ is new to me.

Thanks

8
General / Re: Update function not working.
« on: August 08, 2013, 01:26:06 am »
I moved the Unit.Update(event) method into the while loop. Still the same as before. As I said in my first and second post is if I move  "Unit unit" from Game.h to Game.cpp everything works. Why is that?

9
General / Re: Update function not working.
« on: August 07, 2013, 11:09:51 pm »
Here is my proper Game.Cpp update function(Not sure what happened and I should have noticed it).
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);
}

Unit.cpp
#include "Unit.h"

Unit::Unit(void)
{
        fileName = "Content//Myrmidon.png";
        position.x = 0; position.y = 0;
        origin.x = 0;
        origin.y = 0;
        scale.x = 1;
        scale.y = 1;
        rotation = 0;

        animation2D.UpdateAnimationInfo(0,0,32,32,2,250,true);
}


Unit::~Unit(void)
{
}

void Unit::Update(sf::Event &_event)
{
        animation2D.Update();
}

void Unit::Draw(sf::RenderWindow &_window)
{
        spriteBatch.Draw(_window,fileName,position,animation2D.SourceRectangle(),origin,scale,rotation);
}

Here is my animation.cpp and spriteBatch.cpp code since you may need to look at that.
Aimation
#include "Animation2D.h"


Animation2D::Animation2D(void)
{
}

Animation2D::~Animation2D(void)
{
}

void Animation2D::Update()
{
        sourceRectangle.left = currentFrame * frameWidth;
        sourceRectangle.top = currentRow * frameHeight;
        sourceRectangle.width = frameWidth;
        sourceRectangle.height = frameHeight;

        if (animate)
        {
                time+=1;
                if (time >= interval)
                {
                        time = 0;
                        currentFrame++;
                        if (currentFrame > maxFrames)
                                currentFrame = 0;
                }
        }
        else
        {
                time = 0;
        }
}

void Animation2D::UpdateAnimationInfo(int _currentFrame, int _currentRow, int _frameWidth, int _frameHeight, int _maxFrames, float _interval, bool _animate)
{
        currentFrame = _currentFrame;
        currentRow = _currentRow;
        frameWidth = _frameWidth;
        frameHeight = _frameHeight;
        maxFrames = _maxFrames;
        interval = _interval;
        animate = _animate;
}

sf::IntRect Animation2D::SourceRectangle()
{
        return sourceRectangle;
}
 

SpriteBatch
#include "SpriteBatch.h"

SpriteBatch::SpriteBatch(void)
{
}


SpriteBatch::~SpriteBatch(void)
{
}

void SpriteBatch::Draw(sf::RenderWindow &_window ,std::string _fileName, sf::Vector2f _position,sf::IntRect _sourceRect,sf::Vector2f _origin, sf::Vector2f _scale, float _rotation)
{
        texture.loadFromFile(_fileName);
        sprite.setTexture(texture);
        sprite.setPosition(_position.x,_position.y);
        sprite.setTextureRect(_sourceRect);
        sprite.setOrigin(_origin.x,_origin.y);
        sprite.setScale(_scale.x,_scale.y);
        sprite.setRotation(_rotation);
        _window.draw(sprite);
}
 

Thanks for putting up with my stupidity.
 

10
General / Re: Update function not working.
« on: August 07, 2013, 10:50:14 pm »
Sorry I used C# highlighting because I'm used to it, wasn't thinking clearly.

Under my Header file for Game(Game.h) I am declaring a new Unit class called unit.
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;
};

Under my Game.cpp I have to functions witch are Update and Draw that are called while the game is running.
The Update function is calling my Units Update function and the Draw function is calling the unit's draw function.
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()
{
        unit.Update(event);
}

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

What's suppose to happen is that my unit should appear on screen and animate but it appears on screen but does not animate ,but If I declare the Unit class inside game.cpp  instead of the header file then everything works.

Hope this is more clear, sorry.

11
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

12
DotNet / Re: Embed SFML Window in picturebox
« on: August 02, 2013, 02:44:02 am »
Thanks it works!!!

13
DotNet / Re: Embed SFML Window in picturebox
« on: August 01, 2013, 04:17:07 pm »
I see the SFML Window quickly appear and disappear. It does this when I embed the window to the form as well. So I know something is happening. The picture box does not change at all. It stays on its default settings.

Someone managed to do it here.
http://en.sfml-dev.org/forums/index.php?topic=9178.0

Thanks for the reply.

14
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

15
Graphics / Re: Window.Draw error LNK2001
« on: July 31, 2013, 10:23:07 pm »
Thanks Laurent. Works now.
Yemeni Cpluspluser thanks as well. I'm new to C++ (Been using C# for a year) and never needed to worry about inline functions, but I remember them now in the C++ book I went through, I should have remembered to use them.

Edit: How do I mark this question as answered?

Pages: [1] 2