Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Suggestion] Getting the positions of a layer
#1
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.
Reply
#2
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!
Reply
#3
(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
Reply
#4
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?
Reply
#5
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,
Reply
#6
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/...er.c#L1128

Is it better? And can I do a pull request to your repository? Thanks for your answers.
Reply
#7
Did you ever make the pull request for this? Would love these features to be added to the main project.
Reply
#8
(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.
Reply
#9
(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.
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)