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

Pages: [1]
1
Hm, I don't know what player.h is, so im guessing

maybe, just maybe, its because 2.f is a small number, so you can't see the difference, try 20 for example
No, 2.f is two whole pixels, and this is per frame, from what I can tell, so that's not it.

Can you post a complete and minimal code that reproduces the problem so we can compile it and test it ourselves?

https://gist.github.com/OwenMin/5244931

That's the full works right now, all you need to do is copy and paste them into the corresponding file names and it should compile.

EDIT: Oops, forgot to add my ImageManager, it's all functional now.

2
General / Moving sprite objects of a class from within another class
« on: March 26, 2013, 01:39:55 am »
I'm making a base class for re-use in future projects. Basically a template that i could copy and paste to cut the initial time it takes to start a new project in SFML.

It's all working so far, and i can display my Player object's sprite to the screen. I added a function to my player class so that i can move the sprite around the screen by calling it from my base class, but when i do, it doesn't move. It draws from the base class but won't move when i call player->PlayerControl() from the base class.

Here's my code so you can see what i mean.

Main.cpp
#include <SFML/Graphics.hpp>
#include "Engine.h"

int main()
{
        Engine * engine = new Engine();

        engine->Go();

        return EXIT_SUCCESS;
}

Engine.cpp
void Engine::Go()
{
        if(!Init())
        {
                //Error here
        }
}

bool Engine::Init()
{
        window = new sf::RenderWindow(sf::VideoMode(800, 600, 32), "RPG game");
        window->setFramerateLimit(30);

        if(!window)
                return false;
        LoadImages();
        MainLoop();

        return true;
}

void Engine::LoadImages()
{
        sf::Texture playerTexture;
        playerTexture.loadFromFile("Link_front.png");

        imageManager.AddImage(playerTexture);

        player = new Player(imageManager.GetImage(0));
}

void Engine::MainLoop()
{
        while(window->isOpen())
        {
                ProcessInput();
                Update();
                RenderFrame();
        }
}

ProcessInput();
void Engine::ProcessInput()
{
        sf::Event Event;

        if(window->pollEvent(Event))
        {
                if(Event.type == sf::Event::Closed)
                        window->close();

                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
                        window->close();
        }
        player->PlayerControl();
}

When i call player->PlayerControl(), nothing happens and the sprite doesn't move at all. Here is the Player.cpp move function:

void Player::PlayerControl()
{
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
                playerSprite.move(0, -2.f);

        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
                playerSprite.move(0, 2.f);

        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
                playerSprite.move(-2.f, 0);

        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
                playerSprite.move(2.f, 0);
}

Sorry if this is hard to understand, it's not documented at all, but it should be simple enough to see what's going on as i have placed the functions in the order they are called so top from bottom is the way my game runs.

Why won't my sprite move when the function is called from ProcessInput() ?

3
General / Re: Declaring a global RenderWindow
« on: March 12, 2013, 03:15:32 am »
I scrapped the idea of having a global RenderWindow as i realized there was no need for it and it's just overall bad practice.

I now have a Game class that initializes a window for me.

void Face::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
    target.draw( *m_LeftEye );
    target.draw( *m_RightEye );
    target.draw( *m_Mouth );
    target.draw( *m_Nose );
}
 

So basically a class that has multiple calls to the draw function making up the face then when you do window.draw(face), this would produce a full face (theoretically) ?

If it works like that then yes, it would be a good feature to implement in the future when i get the hang of SFML.

4
General / Declaring a global RenderWindow
« on: March 12, 2013, 02:02:23 am »
Is it wise to do so? I know it's usually bad practice to use global variables, but seeing as i will eventually have lots of things being drawn to this window from different classes/functions, can i declare it globally without causing any significant problems ?

5
General / Re: Drawing & Moving a player/sprite object.
« on: March 10, 2013, 04:19:15 am »
Ah, i see now. I completely forgot that when i was passing the object to the function, i was only passing a copy.

Thank you.

6
General / [SOLVED]Drawing & Moving a player/sprite object.
« on: March 10, 2013, 03:41:01 am »
I have a player class setup with each object having it's own sprite. It draws to the screen like i want it to and to the position i set it to, but when i try to move the object around like you normally would by using something like 'player.move(x, y);', it just refuses to move.

I'm quite new to programming and game development in general so i'm quite hesitant to share my code in fear of looking like an idiot, but here goes.

This is my player class.

class Player
{
private:
        int health;
        bool isAlive;
        Sprite playerSprite;
public:
        Player(int h, Sprite &pSprite){ health = h; playerSprite = pSprite; }
        ~Player(){}

        void drawSprite();
        void setPos(float x, float y);
        void makeMove(float velx, float vely);
};

Excuse all the common errors you will see in my class, it will be refined over time.

Anyway, the way i have it setup is that, i call a function in the main game loop called 'playerControl' and pass my player object to it, then inside the function, i have this:

void playerControl(Player player)
{
        if(Keyboard::isKeyPressed(Keyboard::Left)){
                player.makeMove(-1.5f, 0);
        }
        else if(Keyboard::isKeyPressed(Keyboard::Right)){
                player.makeMove(1.5f, 0);
        }
        else if(Keyboard::isKeyPressed(Keyboard::Space)){
                player.makeMove(0, -2.5f);
        }
}

.makeMove is a function from the 'Player' class:

void Player::makeMove(float velx, float vely){
        playerSprite.move(velx, vely);
}

Using this setup, i though i would be able to move the Player object that i passed to the function around. Nothing happens though. It draws to the screen but after that, it won't move.

Am i going about this the wrong way? Well, i know i am but how wrong?

Pages: [1]
anything