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

Pages: [1]
1
General / Re: Sprite Animation help
« on: December 16, 2013, 02:39:39 am »
Well I was planning on implementing the Animation myself, just something I like to do. So I moved everything into the update function. I also tried adding a clock/timer, I'm not sure this is the best or even a good way of implementing the timer but it was the best I could come up with in an hour and a half. but now it just shows all three frames next to the sprite and each frame next to each other. I'm at a loss here.

void SwordSprite::Update(float elapsedTime)
{
        sf::Clock clock;


        sf::Time time = sf::seconds(1.0f);

       

        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
        {
            int maxFrame = 2;
                SPRITE_HEIGHT = 35;
                SPRITE_WIDTH = 44;

                if(clock.getElapsedTime() >= time)
                {
                        for(int curFrame = 0; curFrame <= maxFrame; curFrame++)
                        {
                                GetSprite().setTextureRect(sf::IntRect(SPRITE_WIDTH * curFrame, 0
                                , SPRITE_WIDTH, SPRITE_HEIGHT));
                                GetSprite().setOrigin((GetSprite().getLocalBounds().width / 2) - 9.0f
                                , (GetSprite().getLocalBounds().height / 2) + 2.0f);
                        }                      
                }

                VisibleGameObject::Update(elapsedTime);
                clock.restart();               
        }
}

2
General / Sprite Animation help
« on: December 15, 2013, 09:51:12 pm »
I have been trying to work this out on my own but I cannot figure it out. This gets all the frames in place, but it displays them all at the same time. I wanted it to cycle through them. I tried putting everything in the update function, but then it doesn't display any of the frames in the correct place and it's all at the same time. So I moved it into the Draw function and as I said it displays them all at the same time. Any suggestions?

#include "headers.h"
#include "SwordSprite.h"

SwordSprite::SwordSprite()
{
        Load("images/aGameSwordSpriteSheet.png");
        assert(IsLoaded());
}

SwordSprite::~SwordSprite()
{
}

void SwordSprite::Update(float elapsedTime)
{

}

void SwordSprite::Draw(sf::RenderWindow &swin)
{
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
        {
                int curFrame = 0;
            int maxFrame = 2;
                SPRITE_HEIGHT = 35;
                SPRITE_WIDTH = 44;

                for(curFrame = 0; curFrame <= maxFrame; curFrame++)
                {
                        GetSprite().setTextureRect(sf::IntRect(SPRITE_WIDTH * curFrame, 0
                     , SPRITE_WIDTH, SPRITE_HEIGHT));

                        GetSprite().setOrigin((GetSprite().getTextureRect().width / 2) - 9.0f
                     , (GetSprite().getTextureRect().height / 2) + 2.0f);
                       
                                       
                        VisibleGameObject::Draw(swin);         
                }
               
        }
}
 

3
Yep, at the end of one of my include files, thanks

4
OK so I have another question. This time it's help with the code I'm getting some strange output messages and my code will not compile. this is the output message:
1>  PauseState.cpp
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\sstream(10): error C2143: syntax error : missing ';' before 'namespace'
1>  Application.cpp
1>c:\users\twiggystardust\documents\visual studio 2010\sfml game development\sfmlapplication\application.cpp(11): error C2143: syntax error : missing ';' before 'Application::TimePerFrame'
1>c:\users\twiggystardust\documents\visual studio 2010\sfml game development\sfmlapplication\application.cpp(11): error C2734: 'sf::Time' : const object must be initialized if not extern
1>c:\users\twiggystardust\documents\visual studio 2010\sfml game development\sfmlapplication\application.cpp(11): error C2512: 'PauseState' : no appropriate default constructor available
1>c:\users\twiggystardust\documents\visual studio 2010\sfml game development\sfmlapplication\application.cpp(11): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\twiggystardust\documents\visual studio 2010\sfml game development\sfmlapplication\application.cpp(11): error C2373: 'TimePerFrame' : redefinition; different type modifiers
1>          c:\users\twiggystardust\documents\visual studio 2010\sfml game development\sfmlapplication\application.h(26) : see declaration of 'TimePerFrame'
1>c:\users\twiggystardust\documents\visual studio 2010\sfml game development\sfmlapplication\application.cpp(11): error C2440: 'initializing' : cannot convert from 'sf::Time' to 'int'
1>          No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>c:\users\twiggystardust\documents\visual studio 2010\sfml game development\sfmlapplication\application.cpp(31): error C2146: syntax error : missing ';' before identifier 'timeSinceLastUpdate'
1>c:\users\twiggystardust\documents\visual studio 2010\sfml game development\sfmlapplication\application.cpp(31): error C2065: 'timeSinceLastUpdate' : undeclared identifier
1>c:\users\twiggystardust\documents\visual studio 2010\sfml game development\sfmlapplication\application.cpp(35): error C2146: syntax error : missing ';' before identifier 'dt'
1>c:\users\twiggystardust\documents\visual studio 2010\sfml game development\sfmlapplication\application.cpp(35): error C2065: 'dt' : undeclared identifier
1>c:\users\twiggystardust\documents\visual studio 2010\sfml game development\sfmlapplication\application.cpp(36): error C2065: 'timeSinceLastUpdate' : undeclared identifier
1>c:\users\twiggystardust\documents\visual studio 2010\sfml game development\sfmlapplication\application.cpp(36): error C2065: 'dt' : undeclared identifier
1>c:\users\twiggystardust\documents\visual studio 2010\sfml game development\sfmlapplication\application.cpp(37): error C2065: 'timeSinceLastUpdate' : undeclared identifier
1>c:\users\twiggystardust\documents\visual studio 2010\sfml game development\sfmlapplication\application.cpp(37): fatal error C1903: unable to recover from previous error(s); stopping compilation

now, I've checked my code a few time, and honestly as far as I can tell it's identical. Also, one reason I find this output message odd is because of the first error message. Why would a standard library file have an error? Also I looked in the file, there is no namespace in the file at all. I'm at a loss here, any help please?

5
OK, I understand. I had a slight thought that this might be the case. So no worries. I was under the understanding that it was. I did get the code e-mailed to me and have downloaded the updated code on github. Thanks!

6
So I've been working on this book for a little while and I just finished chapter four. My question is: Is there supposed to be different code in the example code than the book? As far as chapter four goes, in the book there's this code, it's the last bit of code in the chapter:

Chapter 4 book pg 111

Player::Player()
{
        mKeyBinding[sf::Keyboard::Left] = MoveLeft;
        mKeyBinding[sf::Keyboard::Right] = MoveRight;

        mActionBinding[MoveLeft].action = [] (SceneNode& node, sf::Time dt)
        {
                node.move(-playerSpeed * dt.asSeconds(), 0.f);
        };

        mActionBinding[MoveRight].action = [] (SceneNode& node, sf::Time dt)
        {
                node.move(playerSpeed * dt.asSeconds(), 0.f);
        };

        FOREACH(auto& pair, mActionBinding) pair.second.category = Category::PlayerAircraft;

}

So then I take a look in the example code and Player::Player() looks like this

Chapter 4 example code Source/Player.cpp
Player::Player()
{
        // Set initial key bindings
        mKeyBinding[sf::Keyboard::Left] = MoveLeft;
        mKeyBinding[sf::Keyboard::Right] = MoveRight;
        mKeyBinding[sf::Keyboard::Up] = MoveUp;
        mKeyBinding[sf::Keyboard::Down] = MoveDown;

        // Set initial action bindings
        initializeActions();   

        // Assign all categories to player's aircraft
        FOREACH(auto& pair, mActionBinding)
                pair.second.category = Category::PlayerAircraft;
}
 


I'd say that's a bit different. And the initializeActions() function, was not even mentioned in the text. Why is this? Am I just supposed to do what the book says, then go back over the code and add everything in the example code to the project? I'm sorry if this is a stupid question or if I missed something, but I really don't know why this would be.

7
General / Re: Help with SFML Game Development book
« on: September 24, 2013, 07:04:29 am »
Hello Nexus and thank you for you quick reply. I checked the code and you are correct. I did not include ResourceHolder.h. I had accidentally included the ResourceIdentifier.h and while I was comparing code, I must not have looked at that part close enough. Thank you very much again.

8
General / Help with SFML Game Development book
« on: September 23, 2013, 08:11:07 am »
Hello, I have recently started building the project in the book and I have made it to chapter 3. But I have a problem, I was presented with this error

sfmlapplication\aircraft.cpp(22): error C2027: use of undefined type 'ResourceHolder<Resource,Identifier>'
1>          with
1>          [
1>              Resource=sf::Texture,
1>              Identifier=Textures::ID
1>          ]

So I go take a look at where the error is, the code looks like:

20  Aircraft::Aircraft(Type type, const TextureHolder& textures)
21  : mType(type)
22  , mSprite(textures.get(toTextureID(type)))
23  {
24        sf::FloatRect bounds = mSprite.getLocalBounds();
25        mSprite.setOrigin(bounds.width / 2.f, bounds.height /2.f);
26  }

It seems that there is a problem with
mSprite(textures.get(toTextureID(type)))
and when I hover over textures with the mouse it pops up with "Error: incomplete type is not allowed" I have no idea why this would be, because as far as I can tell, other than the statistic stuff, my code is Identical to the code that was e-mailed to me. Also I did not include the string helper files, are those even needed? They aren't mentioned in the book so I figured they were for the statistics. Can anyone please help? I can't find any problems.

Pages: [1]