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

Pages: [1] 2 3
1
SFML projects / Re: Check out my Engine!
« on: July 25, 2013, 01:03:58 pm »
Some tips:
  • c class prefixes are questionable -- simply omit them, the class names are descriptive enough
  • Use constructor initializers list instead of assignments
  • Perform initialization in constructor instead of public Initiate() method
  • Use RAII (std::unique_ptr) instead of manual memory management (new/delete)
  • Consider the rule of three (no need to declare destructor with RAII)
  • Methods don't need to end with semicolon
  • Identifiers like __ENGINE_HPP__ are reserved (two underscores or underscore + uppercase letter is forbidden)
  • Don't include whole <SFML/Graphics.hpp> header, rather the specific parts you need
  • Some headers are not used, e.g. <iostream>
  • Use forward declarations to reduce compile-time dependencies
  • For better encapsulation, make variables private instead of protected; use protected methods
  • void in empty parameter lists is unusual in C++ (it's a relict from C)
  • Avoid static variables in functions if you actually need member variables
  • Types are not consistently named (exitData_t vs. cEngine) -- I wouldn't try to follow the standard library with _t postfixes
  • Use type inference: replace std::map< std::string, cGenericScene* >::iterator with auto
  • Avoid C and function-style casts, especially where no conversion is necessary: exitData = cGenericScene::exitData_t( cGenericScene::EXIT_CONTINUE );
Thanks Nexus, I've read over what you've said and changed what I have.

https://github.com/AndrewBerry/R9/tree/580c69f6e885e07567a180407235aec5475b2cc5
How's that look?

2
SFML projects / Check out my Engine!
« on: July 25, 2013, 09:36:32 am »
Hey Guys,

I've decided to scrap what I have on my current project and start again. I'm making the new project open source to hopefully force myself to think about other developers and keep my code neat and readable.

Here is a link to the GitHub project: https://github.com/AndrewBerry/R9/
First commit of the engine working: https://github.com/AndrewBerry/R9/tree/cd4a3547cec9e1312b9c35db66a7ba3838ed6850

Any feedback is greatly appreciated, I've looked over this code a million times -- it would really help to get a second pair of eyes on it.

Thanks, Andrew

3
General / sf::Window::setFramerateLimit vs sf::Clock
« on: February 05, 2013, 01:19:02 am »
Is there any difference in precision using sf::Window::setFrameLimit compared to using my own sf::clock to limit the frame rate?

Thanks, Andrew.

4
Graphics / Re: Jittering/Shaking sprites when moving with 'forces'
« on: February 05, 2013, 12:07:51 am »
I still don't know what you mean with "shaking", but if you refer to small irregularities in the movement, then be aware that sf::RenderWindow::setFramerateLimit() is not 100% accurate, it doesn't guarantee a FPS of 60.

Hm I didn't even think about that. Would it be better if I used a sf::Clock to limit the frames myself or would it have the same effect?

5
Graphics / Re: Jittering/Shaking sprites when moving with 'forces'
« on: February 04, 2013, 12:25:34 am »
#include <SFML/Graphics.hpp>

void getVelocity(sf::Vector2f&);

int main(int argc, char** argv)
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "Movement Test");
        window.setFramerateLimit(60);

        sf::Texture tex;
        tex.loadFromFile("player.png");

        sf::Sprite player(tex);
        player.setPosition(400.f, 300.f);

        sf::Vector2f velocity(0.f, 0.f);

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

                getVelocity(velocity);

                // friction
                velocity.x *= 0.92;

                player.move(velocity);

        window.clear(sf::Color::Black);
                window.draw(player);
        window.display();
    }

    return 0;
};

void getVelocity(sf::Vector2f &velocity)
{
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
        {
                velocity.x -= 0.22f;
        };
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
        {
                velocity.x += 0.22f;
        };
};

This is the same method that I was originally using. The shaking is noticeable at random times if you move left/right.

6
Graphics / Re: Jittering/Shaking sprites when moving with 'forces'
« on: February 03, 2013, 02:56:06 pm »
Pfft sorry I was distracted with something else at the time of writing that, I was meant to also show you the original method that I was using to move the player.

PS. I realise that I didn't limit the frames per second on that example and that's the reason it wasn't moving.

7
Graphics / Re: Jittering/Shaking sprites when moving with 'forces'
« on: February 03, 2013, 02:30:15 pm »
#include <SFML/Graphics.hpp>

sf::Vector2f getVelocity();

int main(int argc, char** argv)
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "Movement Test");

        sf::Clock dt;

        sf::Texture tex;
        tex.loadFromFile("player.png");

        sf::Sprite player;
        player.setTexture(tex);
        player.setPosition(400.f, 300.f);

    while (window.isOpen())
    {
                dt.restart();

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

                player.move(getVelocity() * dt.getElapsedTime().asSeconds());

        window.clear(sf::Color::Black);
                window.draw(player);
        window.display();
    }

    return 0;
};

sf::Vector2f getVelocity()
{
        sf::Vector2f velocity(0.f, 0.f);
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
        {
                velocity.x = -1.f;
        };
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
        {
                velocity.x = 1.f;
        };

        return velocity;
};

Is that what you meant by using the timer for each frame? Nothing happens with that code ^

8
Graphics / Re: Jittering/Shaking sprites when moving with 'forces'
« on: February 03, 2013, 12:49:03 pm »
I'll whip up something for you and see if I can record it.

Another thing, am I meant to reset dt when no key is being pressed?

9
Graphics / Re: Jittering/Shaking sprites when moving with 'forces'
« on: February 03, 2013, 01:13:28 am »
Nexus, I've just changed over to using the velocity*time method that you posted about and the moving sprites are still shaking.

Could it be a problem with something on my computer?

10
Graphics / Re: Jittering/Shaking sprites when moving with 'forces'
« on: February 03, 2013, 01:01:14 am »
You measure the frame time dt with sf::Clock. Then, you offset the position according to the velocity multiplied with the passed time:
sf::Vector2f velocity = getVelocityFromInput();
sf::Vector2f offset = velocity * dt.asSeconds();
sprite.move(offset);
So getVelocityFromInput() will return a constant value (say 1 or -1) on each axis?

11
Graphics / Re: Jittering/Shaking sprites when moving with 'forces'
« on: February 02, 2013, 01:51:00 pm »
You should measure the time passed per frame and multiply the velocity with it. Also, some other tips:
  • Don't inherit sf::Sprite. Your player is not a sprite, he contains one.
  • The statement in your constructor has no effect, you declare a local variable.
  • For functions and blocks, there is no ; after } necessary.
  • You can use sf::Sprite::move().

How do I go about changing the velocity of the player then? Won't changing the velocity from 1 to -1 cause the sprite to jump from one side of the screen to the other?

How are gravity and friction factored into the velocity? How about acceleration and deceleration?

As to your list;
1. I have player inherit sf::Sprite because of the way I draw the game using an ordered list of many different objects that are all sub-classes of sf::Sprite.
2. That was a miss type, this is not code from my game - I wrote this as an example.
3. A little style habit of mine. My OCD kills me if I see } without a ;.
4. Thanks, I've updated the code in the original post.

12
Graphics / Jittering/Shaking sprites when moving with 'forces'
« on: February 02, 2013, 10:49:55 am »
Hello everyone,

As I'm working on a basic platformer to hone my programming skills I've noticed that my player sprite jitters or shakes as I'm moving.

The current method of moving the sprite is as follows (minimal code example):
// player.hpp
class player : public sf::Spite
{
public:
   player();

   void update();

   sf::Vector2f forces;
};

// player.cpp
player::player()
{
   forces = sf::Vector2f(0.f, 0.f);
}

player::update()
{
   if (sf::Keyboard::isKeyDown(sf::Keyboard::Left)
   {
      forces.x += 0.1f;
   }
   if (sf::Keyboard::isKeyDown(sf::Keyboard::Right)
   {
      forces.x -= 0.1f;
   }

   // friction
   forces.x *= 0.9f;

   move(forces);
}
 

player.update() is called every frame.

It's not just when it's accelerating/decelerating, it seems like it's every second.

Is it because the forces is stored as a float and the precision of the float is causing it to move weirdly on some specific cases?

Thanks for any help, If you know of a better way of controlling sprite movement please let me know.

13
General / Re: Linker problem (only occurring with release)
« on: December 13, 2012, 10:21:39 am »
add SFML_STATIC to preprocessor

Thanks acrobat, I must have only selected debug when setting the preprocessor definitions.

14
General / Re: Linker problem (only occurring with release)
« on: December 13, 2012, 08:32:46 am »


I can also confirm that sfml-graphics-s.lib exists in my lib directory

15
General / [SOLVED] Linker problem (only occurring with release)
« on: December 13, 2012, 05:27:46 am »
Hello everyone I am having the following linker problems:
(I have double checked the linker options in my project properties)

1>colorManager.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Color::Color(void)" (__imp_??0Color@sf@@QAE@XZ)
1>engine.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) private: virtual bool __thiscall sf::RenderWindow::activate(bool)" (__imp_?activate@RenderWindow@sf@@EAE_N_N@Z)
1>engine.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) protected: virtual void __thiscall sf::RenderWindow::onResize(void)" (__imp_?onResize@RenderWindow@sf@@MAEXXZ)
1>engine.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) protected: virtual void __thiscall sf::RenderWindow::onCreate(void)" (__imp_?onCreate@RenderWindow@sf@@MAEXXZ)
1>engine.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual class sf::Vector2<unsigned int> __thiscall sf::RenderWindow::getSize(void)const " (__imp_?getSize@RenderWindow@sf@@UBE?AV?$Vector2@I@2@XZ)
1>engine.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall sf::RenderWindow::~RenderWindow(void)" (__imp_??1RenderWindow@sf@@UAE@XZ)
1>engine.obj : error LNK2001: 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)
1>engine.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Window::setFramerateLimit(unsigned int)" (__imp_?setFramerateLimit@Window@sf@@QAEXI@Z)
1>engine.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Window::close(void)" (__imp_?close@Window@sf@@QAEXXZ)
1>engine.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Texture::~Texture(void)" (__imp_??1Texture@sf@@QAE@XZ)
1>engine.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::VideoMode::VideoMode(unsigned int,unsigned int,unsigned int)" (__imp_??0VideoMode@sf@@QAE@III@Z)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: bool __thiscall sf::Window::pollEvent(class sf::Event &)" (__imp_?pollEvent@Window@sf@@QAE_NAAVEvent@2@@Z)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: bool __thiscall sf::Window::isOpen(void)const " (__imp_?isOpen@Window@sf@@QBE_NXZ)
1>splashState.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Transformable::setPosition(float,float)" (__imp_?setPosition@Transformable@sf@@QAEXMM@Z)
1>splashState.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Window::display(void)" (__imp_?display@Window@sf@@QAEXXZ)
1>splashState.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static class sf::RenderStates const sf::RenderStates::Default" (__imp_?Default@RenderStates@sf@@2V12@B)
1>splashState.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) private: virtual void __thiscall sf::Sprite::draw(class sf::RenderTarget &,class sf::RenderStates)const " (__imp_?draw@Sprite@sf@@EBEXAAVRenderTarget@2@VRenderStates@2@@Z)
1>splashState.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Sprite::setTexture(class sf::Texture const &,bool)" (__imp_?setTexture@Sprite@sf@@QAEXABVTexture@2@_N@Z)
1>splashState.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Sprite::Sprite(void)" (__imp_??0Sprite@sf@@QAE@XZ)
1>splashState.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::RenderTarget::draw(class sf::Drawable const &,class sf::RenderStates const &)" (__imp_?draw@RenderTarget@sf@@QAEXABVDrawable@2@ABVRenderStates@2@@Z)
1>splashState.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::RenderTarget::clear(class sf::Color const &)" (__imp_?clear@RenderTarget@sf@@QAEXABVColor@2@@Z)
1>splashState.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Color::Color(unsigned char,unsigned char,unsigned char,unsigned char)" (__imp_??0Color@sf@@QAE@EEEE@Z)
1>splashState.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall sf::Sprite::~Sprite(void)" (__imp_??1Sprite@sf@@UAE@XZ)
1>testState.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) private: virtual void __thiscall sf::Shape::draw(class sf::RenderTarget &,class sf::RenderStates)const " (__imp_?draw@Shape@sf@@EBEXAAVRenderTarget@2@VRenderStates@2@@Z)
1>testState.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Shape::setFillColor(class sf::Color const &)" (__imp_?setFillColor@Shape@sf@@QAEXABVColor@2@@Z)
1>testState.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static class sf::Color const sf::Color::Green" (__imp_?Green@Color@sf@@2V12@B)
1>testState.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Transformable::setPosition(class sf::Vector2<float> const &)" (__imp_?setPosition@Transformable@sf@@QAEXABV?$Vector2@M@2@@Z)
1>testState.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual class sf::Vector2<float> __thiscall sf::CircleShape::getPoint(unsigned int)const " (__imp_?getPoint@CircleShape@sf@@UBE?AV?$Vector2@M@2@I@Z)
1>testState.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual unsigned int __thiscall sf::CircleShape::getPointCount(void)const " (__imp_?getPointCount@CircleShape@sf@@UBEIXZ)
1>testState.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::CircleShape::CircleShape(float,unsigned int)" (__imp_??0CircleShape@sf@@QAE@MI@Z)
1>testState.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall sf::CircleShape::~CircleShape(void)" (__imp_??1CircleShape@sf@@UAE@XZ)
1>textureManager.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: bool __thiscall sf::Texture::loadFromFile(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class sf::Rect<int> const &)" (__imp_?loadFromFile@Texture@sf@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV?$Rect@H@2@@Z)
1>textureManager.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Texture::Texture(void)" (__imp_??0Texture@sf@@QAE@XZ)
1>textureManager.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Texture::Texture(class sf::Texture const &)" (__imp_??0Texture@sf@@QAE@ABV01@@Z)
1>D:\Projects\Gentlemen_Wanderer\Release\Gentlemen_Wanderer.exe : fatal error LNK1120: 34 unresolved externals

This happens when I try and build my project in release mode, when I build in debug it works fine.
Is there something wrong with my release lib files?

Pages: [1] 2 3