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 ... 13
1
it seems the font is not in the same place as your cpp files. try changing "arial.ttf" for "Resources/arial.ttf"

2
General / Re: drawing derived classes
« on: September 01, 2020, 01:58:21 am »
my idea was to make derived classes that could handle easily texts, sprites, and some more atributes and methods. i'll just put text and sprite as public access members, then.
(but it is kinda ugly)  :-X

thanks!

3
General / drawing derived classes
« on: August 30, 2020, 05:15:31 pm »
hi
i believe this is a newbie issue related to SFML structure and C++
if I have a class derived from two drawables, like this:
class Board : public sf::Text, public sf::Sprite{
    ///etc;
};

how can I draw this class using a sf::RenderWindow? if I try, for example
window.draw(board.Sprite);
I get an error saying
 invalid use of ‘sf::Sprite::Sprite’
but how do I make the window draw the sprite and then the text? is it mandatory that i override the draw function in Board class, pass a window reference, and then draw each one of the drawables from inside the class?
thanks!

4
Graphics / Re: Sprite is showing outside texture rect
« on: August 13, 2020, 11:45:30 pm »
did you set texture smooth to be true?

5
SFML projects / Re: Screenshot Thread
« on: August 09, 2020, 04:24:13 pm »
finally I have something a little prettier to show  ;D
becoming something between sim city and gangsters 2, I guess




http://www.youtube.com/watch?v=vY-htTALz-8
first, showing map with no filters
second, showing map owner of each building (there is only one for now, blue)
and then showing each buildings value. the greener ones have higher value, and tend to be closest to the center

6
Window / Re: RenderWindow Screen
« on: August 09, 2020, 01:17:55 pm »
there is not. what are you trying to do?

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

8
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.

9
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  :(

10
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"

11
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?

12
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.

13
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.

14
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.

15
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.

Pages: [1] 2 3 ... 13