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

Pages: [1]
1
General / Re: State Machine Question
« on: June 30, 2014, 02:44:42 am »
I guess what I'm wondering is whether or not it would be perfectly fine to do something like this instead:


     m_factories[ id ] = std::move( State::StatePtr state( new T( *this, m_context ) ) );

 

2
SFML projects / Re: Marvin - A Desktop Platformer
« on: June 30, 2014, 01:08:29 am »
Doesn't seem to work for me. As soon as I pick the first level, it freezes at the loading screen :(

That's odd. Can you provide more information maybe? Does it give you an error message? Where exactly in the loading screen does it freeze?


No error message or anything, it just says the program isn't responding and then I have to force close it through task manager. In the console, it seems that the level is getting loaded fine but the screen just stays stuck at the loading screen. And it's the loading screen right after picking the very first level.

3
SFML projects / Re: Marvin - A Desktop Platformer
« on: June 30, 2014, 12:09:37 am »
Doesn't seem to work for me. As soon as I pick the first level, it freezes at the loading screen :(

4
General / State Machine Question
« on: June 29, 2014, 10:48:40 pm »
So reading through the SFML book, I came across some code regarding the Finite State Machine that I do not comprehend. I understand that what I am about to ask may be a C++ question and not necessarily an SFML question but I couldn't find any helpful resources online anywhere that would better my understanding.

My question is in regards to these bits of code:


// StateStack.hpp

typedef std::unique_ptr< State > StatePtr;

class StateStack
{
     //.....

     std::map< States::ID, std::function< State::StatePtr() > > m_factories;
};

template< typename T >
void StateStack::registerState( States::ID )
{
     m_factories[ id ] = [ this ] () { return State::StatePtr( new T(*this, m_context ) ); };
}

 


//StateStack.cpp

State::StatePtr StateStack::createState( States::ID id )
{
     auto found = m_factories.find( id );
     
     assert( found != m_factories.end() );

     return found -> second();
}

 

I guess you could say I'm wondering why std::function is used inside of the m_factories map instead of just say, an std::unique_ptr< State > ? Would it not be possible to use that method and store a new smart pointer in the registerState() method, then just return the smart pointer stored in there by reference in the createState() method? Or is there a specific reason as to why using std::function is more effective? Also I thought that std::function was to be used with functors or functions? Does this mean that a unique_ptr can be used as one of those?

Again sorry if this is more of a C++ question but seeing as it's part of an SFML project I thought I could get some help here. Thanks

5
SFML projects / Re: Galactic Defender
« on: June 28, 2014, 07:51:05 pm »
For your first game, thats quite good, I like it!

Three small things:
  • Please either enable vSync or set a frametime limit, so save computer power, no need for hundreds of frames :D
  • A pause feature would be nice, and not closing by hitting escape.
  • More variety / challenge or just a goal would be nice, you can't really achieve something, because after 100 seconds you lose anyway :P

Thanks for the feedback :) For our next game, we'll definitely incorporate these features

6
SFML projects / Re: Galactic Defender
« on: June 28, 2014, 02:21:43 pm »
beat it. loved it!

Thanks, glad you enjoyed it :)

7
SFML projects / Galactic Defender
« on: June 27, 2014, 02:33:55 am »
Hey guys, just thought I'd share with you my first completed game I made with a friend of mine. Took us about a week to make it. It's pretty crappy but we're both proud of it and really hope you guys will enjoy playing it :) There's a lot of stuff that could be different or added but we decided to make this the finished product. A lot of thanks to Laurent and the rest of the SFML community for their support and help. And also a big thanks to all of those who helped write the SFML book, which was used as a resource in learning some of the stuff needed to make this game. There are some screenshots below to check out what it looks like :)

All assets used in this game are freeware and not owned by me or my friend.

Here's a link to download it:

http://www.mediafire.com/download/i2cbp38bkea66bz/GalacticDefender.rar

Also, if it doesn't work for some reason on your computer please let me know. I wasn't sure if I added the right libs and files in the release so sorry in advance.

8
General / Re: Question About Fixed Time Step
« on: June 18, 2014, 10:33:31 pm »
Yeah, I was definitely over thinking it.

Anyways, thanks for the responses guys

9
General / Question About Fixed Time Step
« on: June 18, 2014, 10:14:40 pm »
I have a question about some of the code involved using a fixed time step. Here is some example code:



const float TimePerFrame = 1 / 60.0f;

sf::Time timeSinceUpdate = sf::Time::Zero;

while ( window.isOpen() )
{
        sf::Time elapsed = clock.restart();
        timeSinceUpdate += elapsed;
       
        while ( timeSinceUpdate > TimePerFrame )
        {
                timeSinceUpdate -= TimePerFrame; // This is the part I don't understand. Why do this?
               
                handleEvents();
               
                update( TimePerFrame );
        }
       
        render();
}

 

I don't understand why you do the line that I commented? Also, is this code suppose to run the game at 60 fps? Because when I run it, the frame rate is over 9000. Sorry if it's a very simple question, but maybe I'm over thinking it and don't see something obvious. Thanks.

10
General / Re: creating functions like getGlobalBounds()
« on: June 17, 2014, 04:34:46 am »
You should look into Structures and Classes, and how to return them from a function.

For example:


class MyClass
{
     public:
     
     MyClass() {}
     
     struct Position
     {
          float x;
          float y;
     };

     Position getPosition() { return m_position; }

     private:

     Position m_position;
};

 

In the above code, when you call getPosition() you are returning the member variable "m_position" which itself has two member variables "x" and "y". These can be called using the "." operator right from the function. So for example if you wanted to access the "x" variable inside m_position, you could do:


MyClass obj;

float x = obj.getPosition().x;

 

But again, you should really read up on structures and classes. It's something basic you should know before you try using SFML

11
SFML projects / Re: Feedback wanted - Simple Gravity Game.
« on: June 15, 2014, 04:24:31 am »
I can imagine this becoming a fun addicting little game  :D any plans on releasing the source code to it? I'm interesting in looking at it  :)

12
General / Re: Entity Manager
« on: June 14, 2014, 03:44:41 am »
It's the "same". The auto keyword gets the correct type for you upon compilation.

Oh thats right  ::) I was thinking of something else, but that makes sense

13
General / Re: Entity Manager
« on: June 14, 2014, 03:26:46 am »
Well in my Game.cpp I have methods for updating, rendering, etc.

void Game::update(sf::Time dt) {
    for (auto& it : mEntities)
        it->update(dt);
}

void Game::render() {
    for (const auto& it : mEntities)
        mWindow.draw(*it);
}

void Game::addEntity(Entity* e) {
    mEntities.push_back(e);
}
 

Not sure if I'm right or not, but shouldn't your ranged based loops have the following format instead of how you did it? :


     for ( Entity* e : mEntities )
     {
          /* do stuff */
     }

 

Or is that the same thing as what you already have?

14
Graphics / Re: sf::Text not drawing to window at all
« on: September 16, 2013, 08:39:07 pm »
Ohh that makes sense  ::) So I guess I have to put my own font file in there then? I'll be sure to look at the tutorials to see what else changed.

15
Graphics / sf::Text not drawing to window at all
« on: September 16, 2013, 08:24:20 pm »
It's been a while since I've programmed, and so I though I'd get back into it. I noticed that SFML 2.1 came out so I downloaded it and decided to mess around a bit by doing some basic stuff like rendering text. However, for some reason the text does not draw at all in my window. Maybe someone can tell me what I'm doing wrong by taking a look at my code? Thanks



#include <SFML/Graphics.hpp>

int main()
{
        sf::RenderWindow window( sf::VideoMode( 800, 600 ), "Text Test" );
       
        sf::Event ev;

        sf::Text text;

        text.setString( "Test String" );
        text.setCharacterSize( 30 );
        text.setPosition( 400, 300 );
        text.setColor( sf::Color::Red );

        while ( window.isOpen() )
        {
                while ( window.pollEvent( ev ) )
                {
                        if ( ev.type == sf::Event::Closed )
                        {
                                window.close();
                        }

                        if ( sf::Keyboard::isKeyPressed( sf::Keyboard::Escape ) )
                        {
                                window.close();
                        }
                }

                window.clear();
                window.draw( text );
                window.display();
        }

        return 0;
}

 

Pages: [1]
anything