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

Pages: [1]
1
Thank you for your help!

About threads, I have been thinking and you are right, maybe I want to learn too much at the same time, when I only know the base of C++.
About "bullets", I asked because I had the strange feel that they had to be dinamic memory through pointers, but you are right one more time, it is easier to avoid pointers and manage them through containers. I think Stroustrup and collegues are driving C++ into that direction: avoid traditional pointers and try to manage memory in automatic mode (vectors, maps, sets, unique_ptr, shared_ptr, etc).
I purchased two books and tried to follow them: "SFML Game Development" and "SFML Game Development by example". I think they are great books and I have improved my code a lot, but they turned too hard for me, so now I am following them sometimes when I am looking for very concrete help. I think they are in a "professional" or "semi-professional" level (maybe I am wrong) but certainly I like them.

About game designing, it is probably not the best place to ask due the forum is oriented to SFML and not general game design as you said. I will consider it in the future  ;)

2
General / How to organise data? And what about dinamic/static memory?
« on: July 27, 2018, 02:16:26 pm »
Hi,

Sorry if this thread doesn't suit the topic of the forum, but I have not seen any better place to post it. Maybe these kind of topic is too general, so tell me if it is the case.

I have been working on a game, which now I have debugged collision and it is working, I want to let the player to shoot an arrow or a bullet.
As a beginner in C++ I don't now how to do that, but I can wonder some methods:

1. Create one or more static objects "Arrow" inside class "Player", which are set to visible and set to a position (and some properties more) when the player attacks.
2. Create a dinamic object (through unique_ptr) and wonder how not to destroy it when I went out of scope there I created it (saving status and loading status in the next call)
3. Investigate threads and how to launch these objects with them.

Another thing about I am thinking is if it is possible to run animations, like when the player dies, through threads, due these animations don't interact with the player (I think enemies are harder to program into a thread because they have to interact with the player, arrows, etc).

Thank yo for your help!

3
General / Re: Presentation and question (initialise sf::Texture)
« on: July 25, 2018, 04:20:48 pm »
Very useful!! Thanks fo all!  ;D ;D ;D ;D

4
General / Re: Presentation and question (initialise sf::Texture)
« on: July 23, 2018, 10:12:46 pm »
Thank you again for your response!

At the very first time, when I was looking for sprites I found a lot of "Atlas sprite", which I thought it was a awkward way to organise images to load them into a game. Then, I found individual sprites, which I am using in my project.
With your answers it makes sense to put the atlas sprite into a texture and move the rectangle to show what I need each moment, but I will consider this in the futur. By now, although I know there are some libraries like Thor, 2DBox, and now, Selba Ward's Gallery Sprite, I want to do most of the things on my own with SFML as starting point. I know it is like trying to invent the wheel, as these libraries are much better than the one I could program, but I think it is a good way to learn how to program and how the API, C++ and the game animation works.

But when I get tired of programming that part, or mucho more interested in another parts of the project, I am pretty sure I will use them.

5
General / Re: Presentation and question (initialise sf::Texture)
« on: July 23, 2018, 09:51:12 am »
When you set the texture of a sprite, it also sets the sprite's size based on the size of the texture and its texture rectangle (part of the texture to use). When you comment out that line, the texture is zero in size when you set the sprite so the sprite stays 0x0 size until changed, which you don't do.

You'll find that if you set the texture after loading each time, this should fix your strangeness. Basically, the sprite needs setting to the texture when it has a size so needs to be loaded.

Actually, this is not strictly true because you can set the texture rectangle at any time and that can be used to size the sprite. So, a simple
sprite.setTextureRectangle(sf::IntRect(0, 0, width, height));
would set the size of the sprite in advance (it could replace the original loading of the texture, for example).

So, that's why.

Thank you for your help! It makes sense! As I am not using the rectangle attached to the sprite class I didn't think about it.

However, there are some things you should really considering changing in this code, especially linked to your texture usage.
The big one is that you load texture from files every frame/cycle of the main loop. Loading from file is not only significant enough to slow down the program but also not necessary more than one: simply load before the main loop any textures you will need and then switch amongst them in the program.

Load them in before the loop:
sf::Texture texture0;
sf::Texture texture1;
if (!texture0.loadFromFile("0.png")) ||
    !texture1.loadFromFile("1.png")))
    return EXIT_FAILURE;

Switch between them in the program:
if (delay < 1) sprite.setTexture(texture0);
if (delay > 1) sprite.setTexture(texture1);

Thank you for your advices! By now I am doing the "loadingFromFile" in the constructor of the objects and inserting them into a map with a string (the path) as key value and the sf::Texture as the mapped value.
Until now I was drawing by moving the same sprite and setting the texture, but now I am going to create a vector of sprites to avoid move them, in order to simplify collision detection.


6
General / Presentation and question (initialise sf::Texture)
« on: July 22, 2018, 11:45:54 am »
Hi!

My name is Gaaza. Nice to meet all of you. I have done my presentation here because I didn't see any presentations topic.
I am not a english speaker, so I have to apologise for my english.
Also, I am a completely beginner in C++, learning through reference books and SFML.

Next, the question. I did a little program to see how textures are working before programming a class for sprite animation. The program is changing a texture (so, the drawing) every second.
What I found is that if I comment the line in red (texture.loadFromFile("0.png");) the screen turns completely black and it doesn't work, but if I uncomment that line works fine.

Do I need to initialise a texture before to assign it to a sprite?

#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <iostream>

class Ejemplo{

public:
    void setTexture(sf::Texture& tex);
    sf::Sprite getSprite();

private:
    sf::Sprite sprite;

};

void Ejemplo::setTexture(sf::Texture& tex){
    sprite.setTexture(tex);
    std::cout << "Direccion tex: " << &tex << std::endl;
}
sf::Sprite Ejemplo::getSprite(){
    return sprite;
}


int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");

    Ejemplo ejemplo;
    sf::Texture texture;
    sf::Sprite sprite;

    sprite.setPosition(0, 0);

    texture.loadFromFile("0.png"); //this is the strange line to comment or uncomment
    ejemplo.setTexture(texture);

    sf::Clock clk_temp;
    sf::Time timer_temp;;

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

        timer_temp = clk_temp.getElapsedTime();
        float delay = timer_temp.asSeconds();

        if(delay < 1) texture.loadFromFile("0.png");
        if(delay > 1) texture.loadFromFile("1.png");
        if(delay > 2) clk_temp.restart();

        sprite = ejemplo.getSprite();

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

    std::cout << "Direccion texture: " << &texture << std::endl;

    return 0;
}
 

Pages: [1]
anything