Skip to content

PIXI 8 tilemap moves the wrong distance when app.stage.position updated #167

@HoPGoldy

Description

@HoPGoldy

I added the following code in examples/demo/basic.js to make it support mouse dragging, but the tilemap moved incorrectly by twice the distance.

await app.init({
    width: 800,
    height: 600,
    preference: searchParams.get('preference') || 'webgl',
    hello: true
});
const tilemap = new PIXI.tilemap.CompositeTilemap();

// ------------------------------------------------- added code ------------------------------------------------- 

let panPos = undefined;

app.canvas.addEventListener('mousemove', (e) => {
    if (!panPos) return;

    app.stage.position.x += e.pageX - panPos.x;
    app.stage.position.y += e.pageY - panPos.y;
    panPos = { x: e.pageX, y: e.pageY };
});

app.canvas.addEventListener('mousedown', (e) => {
    panPos = { x: e.pageX, y: e.pageY };
});

app.canvas.addEventListener('mouseup', (e) => {
    panPos = undefined;
});

// ------------------------------------------------- added code end ------------------------------------------------- 

document.body.appendChild(app.canvas);
app.stage.addChild(tilemap);

examples of issue

example

It can be found that the Sprite added directly on the stage can follow the movement of the mouse very well, but the tilemap moves at twice the distance. After my test, modifying the stage.scale also has similar problems.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions