Tilengine - The 2D retro graphics engine forum
[Suggestion] Getting the positions of a layer - Printable Version

+- Tilengine - The 2D retro graphics engine forum (http://tilengine.org/forum)
+-- Forum: English forums (http://tilengine.org/forum/forumdisplay.php?fid=3)
+--- Forum: Support (http://tilengine.org/forum/forumdisplay.php?fid=7)
+--- Thread: [Suggestion] Getting the positions of a layer (/showthread.php?tid=1486)



[Suggestion] Getting the positions of a layer - System64 - 03-06-2022

Hello, I don't know if it's the right sub-forum to post suggestions in, but I have a suggestion that might be useful.

We can set the position of a layer with TLN_SetLayerPosition(int layerId, int x, int y)

But sadly we can't get the position of this layer. We can track the X and Y values independantly of the layer, but there is a risk of being out of sync with the layer's position if it's badly coded.

So my suggestion is adding functions to get the positions of the layer, like TLN_GetPosX(int layerId) and TLN_GetPosY(int layerId)

I think it would be way more simpler this way.

I also suggest the similar thing for Sprites.


RE: [Suggestion] Getting the positions of a layer - megamarc - 03-09-2022

Hi!

This is a good suggestion indeed. You suggest to enable standard getters for sprite and layer position. No problem.

Right place may be on github, opening an issue there, but I pay etention here too.
Thanks!


RE: [Suggestion] Getting the positions of a layer - System64 - 03-09-2022

(03-09-2022, 02:37 AM)megamarc Wrote: Hi!

This is a good suggestion indeed. You suggest to enable standard getters for sprite and layer position. No problem.

Right place may be on github, opening an issue there, but I pay etention here too.
Thanks!

alright, I opened an issue on GitHub.
I also did some other suggestions and a bug report


RE: [Suggestion] Getting the positions of a layer - System64 - 04-11-2022

Okay so I tried to make a getter for the positions of a layer.
Code:
int TLN_GetLayerPosX(int nlayer)
{
    Layer* layer;
    if (nlayer >= engine->numlayers)
    {
        TLN_SetLastError(TLN_ERR_IDX_LAYER);
        return 0;
    }

    layer = &engine->layers[nlayer];
    if (layer->width == 0 || layer->height == 0)
    {
        TLN_SetLastError(TLN_ERR_REF_TILEMAP);
        return 0;
    }

    TLN_SetLastError(TLN_ERR_OK);
    if ((layer->tilemap && layer->tilemap->visible) || (layer->objects && layer->objects->visible))
    layer->ok = true;

    return layer->hstart;
}

int TLN_GetLayerPosY(int nlayer)
{
    Layer* layer;
    if (nlayer >= engine->numlayers)
    {
        TLN_SetLastError(TLN_ERR_IDX_LAYER);
        return 0;
    }

    layer = &engine->layers[nlayer];
    if (layer->width == 0 || layer->height == 0)
    {
        TLN_SetLastError(TLN_ERR_REF_TILEMAP);
        return 0;
    }

    TLN_SetLastError(TLN_ERR_OK);
    if ((layer->tilemap && layer->tilemap->visible) || (layer->objects && layer->objects->visible))
    layer->ok = true;

    return layer->vstart;
}

Is it any good? Should I improve something?


RE: [Suggestion] Getting the positions of a layer - megamarc - 04-12-2022

Hi!

Quite well. I would simplify it in two places:

1. Having layer width or height to 0 si not illegal, it just means the layer hasn't been yet setup. It should be returned as is, without setting an error value.
2. Wouldn't check layer visibilityto set the value of "ok" member. A getter shouldn't modify the internal state of an object, it should return just the queried property.

Regards,


RE: [Suggestion] Getting the positions of a layer - System64 - 04-12-2022

I followed your advices and made the functions simpler. I did the same for the sprites. I also commited the changes in my fork :
https://github.com/system64MC/Tilengine/blob/master/src/Layer.c#L1128

Is it better? And can I do a pull request to your repository? Thanks for your answers.


RE: [Suggestion] Getting the positions of a layer - RootBeerKing - 05-18-2022

Did you ever make the pull request for this? Would love these features to be added to the main project.


RE: [Suggestion] Getting the positions of a layer - System64 - 05-19-2022

(05-18-2022, 11:29 PM)RootBeerKing Wrote: Did you ever make the pull request for this? Would love these features to be added to the main project.

Oh that's true I have to make this PR, but I need to correct some things in the samples first (it concerns FPS capping).
But yeah, it would be pretty nice.


RE: [Suggestion] Getting the positions of a layer - System64 - 05-31-2022

(05-18-2022, 11:29 PM)RootBeerKing Wrote: Did you ever make the pull request for this? Would love these features to be added to the main project.

I just did the pull request right now.