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.


Topics - Hengad

Pages: [1]
1
General / Smoothest possible movement
« on: September 09, 2015, 03:48:32 pm »
I searched for smooth movement, and I found that one simple and good way is to use delta time. I tried it, but my rectangle movement is still lagging(sometimes it momentarily stops). Is there any better way? How does professional 2d games handle movement?

My example code:
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(500, 500), "Screen");

    sf::Vector2f velocity(0.0f, 0.0f);
    sf::Clock clock;
    float speed = 200.0f;

    sf::RectangleShape player;
    player.setSize(sf::Vector2f(30, 30));
    player.setFillColor(sf::Color::Blue);

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

        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
            velocity.x = -speed;
        else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
            velocity.x = speed;
        else
            velocity.x = 0;


        float deltaTime = clock.restart().asSeconds();

        window.clear();
        player.move(velocity.x * deltaTime, velocity.y * deltaTime);
        window.draw(player);
        window.display();
    }
}

 

2
General / Problem with constructors - game development
« on: September 05, 2015, 09:25:38 pm »
I started making platformer game, and I ran into a problem. It is not a big deal, but if I continue developing this game, it will probably become big problem in future (I guess).

I have struggled with this for 3 hours, without success, so I don't really feel like I want to make this code much shorter, I cut out some parts to make it simpler. It is not too long, but I have stuff in separate files so I put source to pastebin.

http://pastebin.com/2QrfRJ1b

More details about the problem:
It compiles all fine, and it draws the tiles exactly I want them to be drawn. I also have messages coming to console about stuff. And when I run the program console looks like this:


It says twice that WindowManager constructor was called and also window options (that windowproperties class i cut out because i didn't see it's necessary, ignore it). Reason behind this is that I call it once in core class (because i need window for game loop) and once in world class (because i need window dimensions to make calculations and stuff for the world). But I don't want that constructor is called twice... I tried to do things things that prevent it from calling 2 times, it succeeded, but then it didn't draw anything to screen? If I continue developing and this twice calling will happen more, it uses a lot of compile time in the end.

So does anyone know what I should do? The main point is that I need screenDimensions from WindowManager, but if I create instance of it, WindowManager constructor will be called twice. If you read all this, you don't even know how much I appreciate it, thank you.

3
General / Help with error, working with classes
« on: September 02, 2015, 06:45:33 pm »
I am doing something wrong here, don't just know what, when compiling it says drawSnake was not declared in this scope. I have just succeeded making pong game, now I am trying to make snake game.

In Game.cpp I call drawSnake like this:
Quote
drawSnake();

Game.h:

Quote
#include <SFML/Graphics.hpp>

#ifndef GAME_H
#define GAME_H

class Game : public Snake
{
    public:
        Game();
};

#endif // GAME_H


In Snake.cpp I have made the drawSnake() function, it doesn't have errors:

Quote
void Snake::drawSnake()
{
    for(int i = 0; i < snake.size(); i++)
    {
        window.draw(snake);
    }
}

Snake.h:

Quote
#include <SFML/Graphics.hpp>
#include <vector>

#ifndef SNAKE_H
#define SNAKE_H

class Snake : public Game
{
    public:
        Snake();
        void drawSnake();
};

#endif // SNAKE_H


Even they are kind of long I tried to shorten them.

4
General / Small questions about game programming
« on: September 01, 2015, 03:25:47 pm »
Some questions about game programming;

1. How should I build my game loop? Or more specificly where? Should I create it to main directly, or should I have class that has function for game loop, and then I just create object and call the function in main? Is there any performance differences between these 2 options?

2. What is best way to create different cursor? Is it just fine to make cursor invisible and draw own cursor to position of mouse? Or is this too heavy thing to handle?

3. How should I implement drawing inventory? Or anything that contains buttons, should I make class that checks for clicks inside specific coordinates or is there better way to do it?

4. How do I know is my code good/efficient? What can I do to improve it?

5. How I should make character dialogues? If there is lot to talk about, it is pain to write that.. Maybe I should use Lua to write the dialogues and then just implement them to characters with c++?

6. Imagine I have created game. I have all textures in folders. Anyone can go and change them? He could take for example wall texture and make it transparent, and with this he sees through walls? Is there a way to precent this? Same with .exe file that runs the game, is it possible to crack the code and edit it?

Here are questions I am wondering about most. I don't expect to get answers to all of them but it would be nice.

5
Graphics / Best way to detect collision?
« on: August 31, 2015, 06:31:16 pm »
Hello.

First of all, I am probably going to start post questions to this forum frequently.

Then into my question:
I know there are multiple way to detect collision between 2 entities, but which is best (I mean fastest and most efficient) way to detect collision?

I have been using intersects() method, but with fast moving objects, it doesn't seem to be very accurate.

Pages: [1]
anything