frankvHoof93 / TikTokLiveSharp

Port of TikTok live library for C#
https://vanhoof.dev
Other
150 stars 31 forks source link

pivot is not in the center of sprite #42

Closed IgorAherne closed 11 months ago

IgorAherne commented 1 year ago

Hello, the following does get the sprite, but its pivot is incorrect (sometimes Vector2(19291,10188), other times another amount). And the spriteRenderer will draw it several thousand units away.

If I then pause the gameplay and manually check the sprite that's in the SpriteRenderer (via unity Inspector), the pivot is reasonable (for example, 82,82) etc.

This means sprite's values are incorrect during the callback. They are only correct if I read them inside a next Update( ).

Thank you

    public void RequestSprite( SpriteRenderer spriteRender,  Picture picture ){
        Dispatcher.RunOnMainThread(() =>{
            if (!TikTokLiveManager.Exists){return;}
            TikTokLiveManager.Instance.RequestSprite(picture, spr =>{
                if (spriteRender != null  &&  spriteRender.gameObject != null  &&  spriteRender.gameObject.activeInHierarchy)
                    spriteRender.sprite = spr; 
                    // spr.pivot  has incorrect values, until the next Update().
            });
        });
    }//end()
frankvHoof93 commented 12 months ago

The third argument pivot determines what becomes the center of the Sprite. This is a Vector2 relative to the rect where Vector2(0.0f, 0.0f) is the bottom left and Vector2(1.0f, 1.0f) is the top right.

Oops.. I'm currently setting it to width/2f & height/2f. Turns out it should just be 0.5f, 0.5f 😇. Will resolve with next update.

frankvHoof93 commented 11 months ago

Resolved in V1.0.0