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

Pages: [1] 2 3 ... 12
1
since I have no idea how you structured the rest of your code, i'm going to just suggest you to make a bool inside your class named "m_animation_playing" or something like that. when your character dies, you wait for the deah animation to finish and then turn the bool off. while it is off, you dont change the EntityRect position.

2
General / Re: [SOLVED] need a better collision idea
« on: August 02, 2020, 07:01:44 pm »
hi, I just wanted to show the results here. not optimized yet, but its beautiful

http://www.youtube.com/watch?v=JkBzk3SzpEM
Quote
n is the current tile where the mouse is
id is color id of that tile (always n + 1)
r, g and b are the corresponding colors of that id
x and y are the tile position on the map
m_stamp_sprite are the positions of the sprite's vertices (x and y)
identified building is... well, the building identified by the color
also, i got rid of the rendertexture.i simply draw the colorized tiles to screen, process what is needed, clear the screen and draw what will be visible to the user.

3
System / Re: Limitations of repeated key events
« on: August 02, 2020, 02:10:06 pm »
ops, you're right. it's just one event checked at a time.
but as Laurent said, I tested it in a text editor and it gives the exact same results  :(

4
System / Re: Limitations of repeated key events
« on: August 01, 2020, 10:26:21 pm »
no, the problem is the line
else if (event.key.code == sf::Keyboard::B)
by using "else if", this code is going to be executed only if A is NOT pressed. if you want both to be checked, just remove the "else"

5
General / Re: Jumping and collision problem
« on: July 31, 2020, 02:36:43 am »
i don't understand what is the problem. isn't the plataform supposed to stop the player movement?

6
Graphics / Re: Render Texture with a View
« on: July 30, 2020, 10:37:18 pm »
can't you post some image of the problem and code? its hard to guess whats happening.

7
General / Re: Jumping and collision problem
« on: July 30, 2020, 10:34:11 pm »
if the problem is the player jumping higher when he is close to the plataform, i have a guess that it is because he is "stepping" in the plataform for a brief period of time (like 1ms), but it is enough to restart the jumping cycle. you can put some delay to the jumping method, avoiding the player to jump again in the first second, for example.

8
Graphics / Re: Render Texture with a View
« on: July 30, 2020, 06:09:13 pm »
it's hard to tell without any code, but my guess is that you are drawing this sprite to the same coordinates in the window view everytime.

9
General / Re: need a better collision idea
« on: July 25, 2020, 07:08:31 pm »
weird, in GCC (Linux, Debian Testing) +14 and +17 it seems not to be emplacing new itens in the Add method.
anyway, its working for me now, so i consider it solved. also need optimizations, but this test works:

#include <string>
#include <fstream>
#include <iostream>

#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>

int main(){
    sf::RenderWindow window(sf::VideoMode(512, 256), "Tests");
    sf::Vector2u tile_size(32, 32);
    sf::Vector2u map_size(16, 8);

    sf::Texture tileset;
    tileset.loadFromFile("terrain-6.png");

    sf::VertexArray vertices;
    vertices.setPrimitiveType(sf::Quads);
    vertices.resize(map_size.x*map_size.y*4);

    const int level[] ={
        0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
        0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0,
        1, 1, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3,
        0, 1, 0, 0, 2, 0, 3, 3, 3, 0, 1, 1, 1, 0, 0, 0,
        0, 1, 1, 0, 3, 3, 3, 0, 0, 0, 1, 1, 1, 2, 0, 0,
        0, 0, 1, 0, 3, 0, 2, 2, 0, 0, 1, 1, 1, 1, 2, 0,
        2, 0, 1, 0, 3, 0, 2, 2, 2, 0, 1, 1, 1, 1, 1, 1,
        0, 0, 1, 0, 3, 2, 2, 2, 0, 0, 0, 0, 1, 1, 1, 1,
    };


    for (unsigned int i = 0; i < map_size.x; ++i){
        for (unsigned int j = 0; j < map_size.y; ++j){
            int tileNumber = level[i+j*map_size.x];
            int tu = tileNumber % (tileset.getSize().x / tile_size.x);
            int tv = tileNumber / (tileset.getSize().x / tile_size.x);
            sf::Vertex* quad = &vertices[(i+j*map_size.x)*4];

            quad[0].position = sf::Vector2f(i*tile_size.x, (j)*tile_size.y);
            quad[1].position = sf::Vector2f((i+1)*tile_size.x, (j)*tile_size.y);
            quad[2].position = sf::Vector2f((i+1)*tile_size.x, (j+1)*tile_size.y);
            quad[3].position = sf::Vector2f(i*tile_size.x, (j+1)*tile_size.y);

            quad[0].texCoords = sf::Vector2f(tu*tile_size.x, tv*tile_size.y);
            quad[1].texCoords = sf::Vector2f((tu+1)*tile_size.x, tv*tile_size.y);
            quad[2].texCoords = sf::Vector2f((tu+1)*tile_size.x, (tv+1)*tile_size.y);
            quad[3].texCoords = sf::Vector2f(tu*tile_size.x, (tv+1)*tile_size.y);
        }
    }

    sf::Shader shader;
    shader.loadFromFile("shaders/test.frag", sf::Shader::Fragment);
    shader.setUniform("texture", tileset);

    sf::RenderTexture buffer;
    buffer.create(window.getSize().x, window.getSize().y);
    sf::Sprite buffer_spr(tileset);

    sf::RenderStates rs;
    rs.texture = &tileset;
    rs.shader = &shader;

    while (window.isOpen()){
        buffer.clear();
        for (size_t y=0; y<map_size.y; y++){
            for (size_t x=0; x<map_size.x; x++){
                // Calc ID
                int ID = 1 + y * map_size.x + x;
                int r = (ID & 0x000000FF) >> 0;
                int g = (ID & 0x0000FF00) >> 8;
                int b = (ID & 0x00FF0000) >> 16;

                shader.setUniform("color_id", sf::Glsl::Vec4(r / 255.0f, g / 255.0f, b / 255.0f, 255));

                int tileNumber = level[y*map_size.x+x];
                int tu = tileNumber % (tileset.getSize().x / tile_size.x);
                int tv = tileNumber / (tileset.getSize().x / tile_size.x);

                buffer_spr.setTextureRect(sf::IntRect(tu*tile_size.x, tv*tile_size.y, tile_size.x, tile_size.y));
                buffer_spr.setPosition(x*tile_size.x, y*tile_size.y);
                buffer.draw(buffer_spr, rs);
            }
        }
        buffer.display();
        sf::Event event;
        while (window.pollEvent(event)){
            if(event.type == sf::Event::Closed) window.close();
            if(event.type == sf::Event::MouseButtonPressed && event.mouseButton.button == sf::Mouse::Left){
                unsigned char data[4];
                glReadPixels(sf::Mouse::getPosition(window).x, window.getSize().y-sf::Mouse::getPosition(window).y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &data);
                std::cout << " id:" << (data[0] + data[1] * 256 + data[2] * 256 * 256) - 1;
            }
        }
        window.clear(sf::Color::White);
        window.draw(vertices, &tileset);
        sf::Sprite test_sprite(buffer.getTexture());
        //window.draw(test_sprite);
        window.display();
        sf::sleep(sf::milliseconds(10));
    }
    return 0;
}
 

funny fact that maybe the developers could explain: I tought that glReadPixels would get pixels that are in the screen, not in textures or other render targets; but we are drawing the colorized sprites to a RenderTexture. still, the function reads it correctly (of course, if nothing else is drawn to the screen yet in that frame, in which case the id colors would be overlaid). maybe both RenderTargets are seen as the same thing for OpenGL?

anyway, thank you for the help! i'm going to focus on improving the performance, but the issue is completely solved.


EDIT: I forgot to mention, i think the shader isn't really optimized also, so it could be a bottleneck too? I simply made something that could work, but the newer versions of GLSL doesn't even accept things like gl_FragColor and gl_TexCoord.

10
General / Re: Idea for Collision
« on: July 24, 2020, 03:55:16 pm »

11
General / Re: Idea for Collision
« on: July 24, 2020, 03:04:34 pm »
well... the logic is simple:...
BEFORE the player move, test if he is going to collide with something. if true, the player don't move. if false, he moves.

so you don't move the player right from the start. you first test for collisions.

12
General / Re: need a better collision idea
« on: July 24, 2020, 02:58:47 pm »
great! i'll try to put it to my code
one question, tough: does the code from your last post works for you? I get a segmentation fault at line 88:
return lhs.pos.y < rhs.pos.y;

for some reason I can't debug a code that contains shader, so i don't know what could be the cause

13
Window / Re: Display window for a few seconds without event polling
« on: July 22, 2020, 02:17:38 pm »
hi
have you tried
sf::sleep(sf::seconds(2));
instead of
usleep(2000000);
?

14
I dont know if there is Visual Studio for MAC, but it would be something like that. you just take your code and compile it again in a OSX. you don't need to copy/paste all the code, just use the same files (.c, .cpp, .h, .hpp, etc). they are text files, so they work everywhere.
an easier way would be using crosscompilers. OR you can use a virtual machine to compile your program.

15
do you mean to convert your windows .exe to a mac aplication? I wouldn't agree to that. its better to simply compile it again in an OSX. same for Linux based distros...

Pages: [1] 2 3 ... 12
anything