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

Pages: [1]
1
General / Re: [SFML2] Handling several keypresses
« on: May 16, 2012, 08:54:19 am »
Laurent;
Thanks.

Didn't even think of changing from the arrows to other keys, thought they all could take the same amount keypresses...

2
General / [SFML2] Handling several keypresses
« on: May 15, 2012, 12:50:13 pm »
So, here I am again, missed me? ;)

I'm trying to handle several keypresses by using if/else if-statements and have one problem;

When I'm trying to get it to make a certain thing when pressing Space, it will actually do what it is supposed to do... unless I'm pressing space, up and left or space, down and right at the same time.

Then it will ignore space, and only do what it's supposed to do for up and left and what it is supposed to do for down and right...

#include <SFML2\Graphics.hpp>


class Player
{
public:
        Player()
        {
                t.loadFromFile("human.bmp");
                spPl.setTexture(t);
                spPl.setPosition(200, 200);
                spPl.setOrigin(t.getSize().x / 2, t.getSize().y / 2);
        }

        sf::Sprite getSprite()
        {
                return spPl;
        }
        sf::Vector2f getPosition()
        {
                return spPl.getPosition();
        }
        void move(int x, int y)
        {
                spPl.move(x, y);       
        }
private:
        sf::Texture t;
        sf::Sprite spPl;
};

class Zombie
{
public:
        Zombie(sf::Vector2f pos)
        {
                t.loadFromFile("zombie.bmp");
                spZm.setTexture(t);
                spZm.setPosition(pos);
        }
        sf::Sprite getSprite()
        {
                return spZm;
        }
private:
        sf::Texture t;
        sf::Sprite spZm;
};

int main (void)
{
        sf::RenderWindow w(sf::VideoMode(800, 600, 32), "lol");
        w.display();

        Player * p = new Player();
        Zombie * zm[10];
        for(int i = 0; i < 10; i++)
                zm[i] = nullptr;

        sf::Clock c;
        c.restart();

        sf::Event ev;
        while(w.isOpen())
        {
                while(w.pollEvent(ev))
                {
                        switch(ev.type)
                        {
                        case sf::Event::Closed:
                                w.close();
                        }
                }

                //my way of handling inputs:
                if(c.getElapsedTime().asMilliseconds() > 100)
                {
                        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
                        {
                                for(int i = 0; i < 10; i++)
                                {
                                        if(zm[i] == nullptr)
                                        {
                                                zm[i] = new Zombie(p->getPosition());
                                                break;
                                        }
                                }
                        }
                        //player movement:
                        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left) && sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
                        {
                                p->move(-5, -5);
                        }
                        else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up) && sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
                        {
                                p->move(5, -5);
                        }
                        else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right) && sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
                        {
                                p->move(5, 5);
                        }
                        else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down) && sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
                        {
                                p->move(-5, 5);
                        }
                        else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
                        {
                                p->move(-5, 0);
                        }
                        else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
                        {
                                p->move(0, -5);
                        }
                        else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
                        {
                                p->move(5, 0);
                        }
                        else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
                        {
                                p->move(0, 5);
                        }
                        c.restart();
                }

                w.clear();
                for(int i = 0; i < 10; i++)
                {
                        if(zm[i] != nullptr)
                                w.draw(zm[i]->getSprite());
                }
                w.draw(p->getSprite());
                w.display();
        }

        for(int i = 0; i < 10; i++)
        {
                if(zm[i] != nullptr)
                        delete zm[i];
        }
        delete p;
}
 

I've also tried to add another if-statement like this:
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space) && sf::Keyboard::isKeyPressed(sf::Keyboard::Up) && sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
 
without any success, it still ignores space when Up and left or Down and Right is pressed. And yes, I did try to have it for both Up and Left, and Down and Right.

Anyone who knows a solution for this?
Just replace human.bmp and zombie.bmp if you don't believe me and want to test.

Laurent; this time I actually knew what the problem is, where to find it... just not how to solve it ;)

3
General / Re: "Unhandled exception" when exiting application
« on: May 14, 2012, 05:41:03 pm »
mateandmetal:
"Unhandled exception at 0x698ba051 in NTI-Zombie_Survival.exe: 0xC0000005: Access violation reading location 0x00000008."

And that's the error it throws at me, when exiting main(). If you're running the application in Release, it won't throw any error like that - only crash and ask if I want to report it to Microsoft ;)

Also, debugging in dbgdel.cpp is something I don't feel that comfortable doing... :P

Rosme:
Going to try and change that and see if it makes any difference, thanks!

*EDIT*
Thanks a lot Rosme! That was the issue, just tried to load a custom font instead of using getDefaultFont() (which appearently was what the default constructor was using... stupid of me that I didn't think of that first time...) and now it closes without throwing errors at me!

So, thanks!

4
General / Re: "Unhandled exception" when exiting application
« on: May 08, 2012, 08:26:12 pm »
Laurent:

Problem is, I cannot exclude any of the code - since I don't know exactly where it's going wrong. Neither can I reproduce the problem in any other projects.

So, I can't really do that much except for posting the full code... Sorry about that. Or, I could make it a guessing game and don't post any code at all! :D

5
General / [SOLVED]"Unhandled exception" when exiting application
« on: May 07, 2012, 09:58:46 pm »
Solution:
Use a custom font for sf::Text...


Hi,

so, now me and some friends have started making a game from scratch using SFML (obviously..) and we have one problem that we cannot solve, neither can our programming teacher ( or he just refuses to explain how to solve this...);
we're getting this error when the program exits from main():
"Unhandled exception at 0x698ba051 in NTI-Zombie_Survival.exe: 0xC0000005: Access violation reading location 0x00000008."

It doesn't matter if we have an array of pointers to the objects or the objects itself, and it didn't help replacing the arrays with std::vector either (same goes for this, doesn't matter if we had a vector of pointers to the object or the object itself stored in the vector) we still got the error.

When did this error start?
No idea, after we made some changes (unfortunately before we started to document all the changes we do...) to the Player class and Zombie class is all that I can say.

Source code:
http://pastebin.com/ZNXLpskQ

If anyone can figure out why this is happening (or, a solution would be even better  ::) )... that'd be awesome.

Thanks in advance.

EDIT:
We are using SFML2 RC, forgot to mention that last night.

6
General / Re: Lots of unresolved externals...
« on: April 12, 2012, 02:01:38 pm »
Laurent:
Well, I can't find anything in this project that has anything to do with SFML1.6 so then that should not be an issue, unless VS11 is too stupid to realize it's a new project and still find the settings for that project (not that likely...).

Well, going to try re-building it again with NMake and follow another tutorial step-by-step and hope that it'll work this time.

Wish me luck, I think I'm gonna need it...

7
General / Re: Lots of unresolved externals...
« on: April 12, 2012, 01:43:51 pm »
Laurent:
It shouldn't matter that I have another project in my Project's folder that uses SFML1.6, or?

Oh, the errors was not from CMake, it was a bug from VS11 (and VS10) that was messing with me for a while, I solved it by not using the pop-up to add "Additional Dependencies" and just add them there.

igorko:
Just trying, if I ever get this working I will remove unused lib's.

8
General / Lots of unresolved externals...
« on: April 12, 2012, 02:15:02 am »
****NOTE****
Thread can be locked, re-built it using CMake and NMake instead of CMake and then build the solution from VS11, that did the trick.
(at least now I know how to do it properly for my next time!)
Anyway, thanks for trying to help me Laurent.

TO THOSE OF YOU WHO HAD THE SAME PROBLEM: http://sfmlcoder.wordpress.com/2011/06/15/building-sfml-2-nmake/
Follow that guide, it's made for VS10 but works just as fine for VS11.

Hi, I'm trying to get SFML2 to actually work for me... but, it refuses to just simply work. Therefore, after googling and searching on the forums (only answer I got from the forum was "make sure you have linked the libs", which I have done)... so, here I am - trying to make this work once and for all.

My problem: I'm using VS11 and it doesn't like my linkings, I guess.
Code: [Select]
1>------ Build started: Project: SFML2-Test, Configuration: Debug Win32 ------
1>Build started 2012-04-12 02:02:33.
1>InitializeBuildStatus:
1>  Touching "Debug\SFML2-Test.unsuccessfulbuild".
1>ClCompile:
1>  main.cpp
1>ManifestResourceCompile:
1>  All outputs are up-to-date.
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::VideoMode::VideoMode(unsigned int,unsigned int,unsigned int)" (__imp_??0VideoMode@sf@@QAE@III@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __thiscall sf::Window::isOpen(void)const " (__imp_?isOpen@Window@sf@@QBE_NXZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Window::display(void)" (__imp_?display@Window@sf@@QAEXXZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Color::Color(unsigned char,unsigned char,unsigned char,unsigned char)" (__imp_??0Color@sf@@QAE@EEEE@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::RenderTarget::clear(class sf::Color const &)" (__imp_?clear@RenderTarget@sf@@QAEXABVColor@2@@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::RenderWindow::RenderWindow(class sf::VideoMode,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,unsigned int,struct sf::ContextSettings const &)" (__imp_??0RenderWindow@sf@@QAE@VVideoMode@1@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@IABUContextSettings@1@@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall sf::RenderWindow::~RenderWindow(void)" (__imp_??1RenderWindow@sf@@UAE@XZ) referenced in function _main
1>c:\users\nti\documents\visual studio 11\Projects\SFML2-Test\Debug\SFML2-Test.exe : fatal error LNK1120: 7 unresolved externals
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.76
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

That's my output log, and here's my testcode to see if everything's working:
Code: [Select]
#include <SFML\Graphics.hpp>

int main()
{
sf::RenderWindow mainWindow(sf::VideoMode(800, 600, 32), "title");
while (mainWindow.isOpen())
{
mainWindow.clear(sf::Color(255, 255, 255));
mainWindow.display();
}

return 0;
}

Additional dependencies for Debug (which is what I'm trying to do right now, so my dependencies for Release doesn't matter right now - though it doesn't work there either..):
sfml-graphics-d.lib
sfml-audio-d.lib
sfml-window-d.lib
sfml-system-d.lib
sfml-network-d.lib

So, can someone tell me where I've screwed up?

At first I just thought it was somewhere with the CMake that didn't go well because I got an error, but I rebuilt it and got past that without any errors at all so I guess it should (observe, SHOULD) be working... in my world at least.

Tell me if you need any more info, and I'll happely give it to you if that might help someone help me.

Regard, me.

NOTE: It's 2:15 here, in the night - so I blame any misspellings and such on the time.

*edit*
Tried to rebuild all dll's and lib's, placing the new ones on a completely different place and I think you can guess how it went...

And I'm using CMake's VS11 Win64 setup for my build. And yes, I am running a 64-bit version of Windows 7. Also using an AMD GPU, seen something about SFML and AMD GPU's, but that'd not cause the linker errors...

Pages: [1]