question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to offset Texture when Sprite.achor is not (0,0) [SOLVED]

See original GitHub issue

The logic of Sprite.calculateVertices() is :

        if (trim)
        {
            // if the sprite is trimmed and is not a tilingsprite then we need to add the extra
            // space before transforming the sprite coords.
            w1 = trim.x - (anchor._x * orig.width);
            w0 = w1 + trim.width;

            h1 = trim.y - (anchor._y * orig.height);
            h0 = h1 + trim.height;
        }

But I want to that logic like this :

        if (trim)
        {
           //  trim.x needs `* anchor._x`
            w1 = anchor._x * trim.x - (anchor._x * orig.width);
            w0 = w1 + trim.width;

            h1 = anchor._y * trim.y - (anchor._y * orig.height);
            h0 = h1 + trim.height;
        }

Is there a way to do that ? or equivalent method ?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
finscncommented, Feb 17, 2017

If don’t change current logic in Sprite , there is another way to do same thing:

    var baseTexture = PIXI.BaseTexture.from(img);
    var textureFrame = new PIXI.Rectangle(sx, sy, sw, sh);

    var orig, trim;
    if (offset) {
        orig = new PIXI.Rectangle(sx + offset[0], sy + offset[1], sw - offset[0], sh - offset[1]);
        trim = new PIXI.Rectangle(-offset[0], -offset[1], sw, sh);
    }
    texture = new PIXI.Texture(baseTexture, textureFrame, orig, trim);
0reactions
lock[bot]commented, Feb 24, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to offset Texture when Sprite.achor is not (0,0) [SOLVED]
The logic of Sprite.calculateVertices() is : if (trim) { // if the sprite is trimmed and is not a tilingsprite then we need...
Read more >
Tiled sprite with scale factor & anchor stretching does not work ...
Quick and dirty answer to this: Change the pixels per unit import setting on the sprite to scale it as desired, then set...
Read more >
PIXI.Sprite - PixiJS API Documentation
The anchor sets the origin point of the sprite. The default value is taken from the Texture and passed to the constructor. The...
Read more >
How to Sort 2D Sprite Rendering Order ~ Godot Tutorial
Learn how to automatically organize your sprite rendering order ... Timestamps: 0 : 00 The Sorting Problem 1:18 Y-Sort Node Solution 2:08 ...
Read more >
Three JS issue with texture offset and repeat for positioning ...
Solved it. For future reference, this is what I ended up with to get a sprite sheet working with a texture atlas in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found