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] 4 5 ... 13
31
General / Re: Sprite rotation on tile map
« on: July 14, 2020, 06:59:25 pm »
it could be because you are constantly reseting the sprite origin when you update poll events.
have you tried like this?
void Player::initializePlayer(const sf::Texture& idle_T)
{      
//[...]
        this->player_Sprite.setOrigin(sf::Vector2f(
                this->player_Sprite.getLocalBounds().width / 2.f,
                this->player_Sprite.getLocalBounds().height / 2.f));
}

32
General / Re: need a better collision idea
« on: July 14, 2020, 05:49:25 pm »
hi! thanks for your response
I was trying to come up with some code based on what you said before replying again, but this may take some time. so, i just wanted to thank for the help. i'm going for the second approach. when i have somethign new, i'll post here.  ;D


EDIT: well, i'll need help for that. i have never writen a shader before, nor really used one with SFML.

so, i'll be using this code based on the tilemap tutorial:
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

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

    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-1)*tile_size.y);
            quad[1].position = sf::Vector2f((i+1)*tile_size.x, (j-1)*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("shader.frag", sf::Shader::Fragment);
    shader.setUniform("mouse_position", window.mapPixelToCoords(sf::Mouse::getPosition(window)));
    shader.setUniform("tileset", tileset);

    while (window.isOpen()){
        sf::Event event;
        while (window.pollEvent(event)){
            if(event.type == sf::Event::Closed)
                window.close();
        }
        window.clear();
        window.draw(vertices, &tileset);
        window.display();
    }
    return 0;
}


and this not-yet shader "shader.frag" file
#version 330

uniform vec2 mouse_position;
uniform sampler2D tileset;

void main(){

}
 



what i think should be the next steps:
1- identify the current visible tiles on screen
2- for each one of these, get from the tileset the corresponding tile convert the non-transparent pixels to an unique color, respecting the draw order (left to right, up to down)
3- based on the mouse position, get the current color and convert it to a final tile id.

is it possible to return a number from a glsl shader back to the sfml program? in this case, the final tile id?

33
whats your operational system, version of SFML, code editor, compiler, etc?...

34
General / Re: Weird Behaviour with tilemap
« on: July 13, 2020, 06:12:58 pm »
i'm also not sure of what is "weird and messed up", but it seems to be a problem with your sLevel. is that string the tilemap internally? why not an array or vector of ints? try to change that, because your problem could be an inconsistency between your sLevel x and y size and your intended x and y size.

35
General / [SOLVED] need a better collision idea
« on: July 11, 2020, 04:54:41 pm »
hello!
I'm creating this city like game, but having some trouble with collision between the cursor and the building tiles.
my first idea (which is working now) was to detect collision with only the ground area of each building. but its extremely counter intuitive. video explaining:
http://www.youtube.com/watch?v=6bubui54T_c

by 7 seconds I move the cursor over a building, but the selected tile is the ground behind it.

I need some insight on how to make a better collision detection, considering that buildings have different heights (and street tiles have almost no height at all).
observation: the tiles are made of sf::Quads (shaped as parallelograms/diamonds, NOT rectangles) in a sf::VertexArray.

original tile image:


tiles boundings before rotating the view (notice that most buildings won't use all the tile size).


I don't know if it is of any help, but the building tiles before rotating the view:


and after rotating:


grid lines are for reference.
any idea is apreciated. thanks in advance!  ;D

36
Graphics / Re: Should I use sf::Texture or sf::Image
« on: June 23, 2020, 01:33:37 pm »
there is no sense in doing the first, since you'll need to load it in a texture anyway.
sf::Image is ONLY for when you want to modify that image (like drawing), for everything else use a Texture.

37
Window / Re: Sprite can't be positioned
« on: November 30, 2019, 08:10:54 pm »
why are you using desktop mode, instead of your sf::RenderWindow variable?

I would do it like
sprite.setPosition((float)render_window.getSize().x/2-sprite.getSize().x/2, (float)render_window.getSize().y/2-sprite.getSize().y/2)

38
General / Re: Moving a view with mouse
« on: November 08, 2019, 11:45:45 am »
did you try this from the tutorials?

39
Graphics / Re: Sprites and problems with a onboardgrafic ..
« on: November 06, 2019, 04:53:16 pm »
could be a driver problem.
other than that, we can only help if you create a minimal code to reproduce the problem and post it here.
and your "for information" link is in another language, so it no help at all...

40
System / Re: [Help] I don't understand sf::Time, sf::Clock
« on: November 04, 2019, 03:14:33 pm »
the tutorials are not awful, but you need to have the slightest idea of what you are doing.
what exactly didnt work?

41
System / Re: [Help] I don't understand sf::Time, sf::Clock
« on: November 04, 2019, 10:30:12 am »
I don't think there is much to explain. sf::Time is a specific time, and sf::Clock is a time that change automatically as time passes.

You can make something like:
sf::Clock clock;
sf::String string;
if (clock.getElapsedTime().asSeconds >= sf::seconds(10){
    clock.reset();
}
string.setText(clock.getElapsedTime().asSeconds());
 

I typed from my phone, so I didnt tested it ?

Also, did you check the tutorials?
https://www.sfml-dev.org/tutorials/2.5/system-time.php

42
Graphics / Re: get click on an isometric tile
« on: November 02, 2019, 08:43:38 pm »
actually the article is exactly what you need. you should calculate the tiles position with proper math. the way you are trying to do won't work, simply because a isometric tile has different bounds than the FloatRect.

OR you could do another way: create square tiles, calculate the mouse position, the selected tile, all based on square tiles. and at the end of everything, you just rotate the whole sf::View by 45 dregrees.

43
SFML projects / Re: Screenshot Thread
« on: October 29, 2019, 04:55:55 pm »
I'm working on a isometric tilemap city. so far it works good, and I haven't seen any unexpected bugs in the past few days.
what it does:
-creates a tilemap based on binary space partitioning (or atleast I think it can be described like that  :P)
-gives a "value" atribute to each tile (tiles near to the city center tend to have higher values)
-camera is controlled by holding down the right mouse button and moving it around

building the random/procedural city:


grey tiles are streets:


and a video (warning: it takes 1:45 building the map)
http://www.youtube.com/watch?v=gYVybRyChNQ

next step is to change these square tiles to hexagonal shapes, to fake 3d axes in isometric :)

44
Graphics / Re: strange behaviour with View and Viewport
« on: October 28, 2019, 04:43:06 pm »
works perfectly! thanks again!  ;D

45
Graphics / Re: strange behaviour with View and Viewport
« on: October 28, 2019, 02:34:35 pm »
thank very much to both of you
i got up with this:

if (sf::IntRect(view_one.getCenter().x-view_one.getSize().x/2, view_one.getCenter().y-view_one.getSize().y/2, view_one.getSize().x, view_one.getSize().y).contains(sf::Vector2i(pos_in_view))){


I don't know if this would be used frequently, but wouldn't it be interesting to add such function in the sf::View class?

Pages: 1 2 [3] 4 5 ... 13