Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drag bad working after select a child #422

Closed
meghe2000 opened this issue Jan 10, 2023 · 12 comments · Fixed by #430
Closed

drag bad working after select a child #422

meghe2000 opened this issue Jan 10, 2023 · 12 comments · Fixed by #430

Comments

@meghe2000
Copy link

meghe2000 commented Jan 10, 2023

image

When I drag on an empty stage, it moves fine.
But when I do this on my children, it gets annoying.

const viewport = new Viewport({
    screenWidth: window.innerWidth,
    screenHeight: window.innerHeight,
    worldHeight: 1000,
    worldWidth: 1000,

    // interaction: app.renderer.plugins.interaction // the interaction module is important for wheel to work properly when renderer.view is placed or scaled
})
viewport.drag({}).pinch({}).wheel({}).decelerate({}).setZoom(0.5)
pixi-viewport": "^4.38.0
pixijs": "^7.1.1
os: windows 11 - chrome 109
@davidfig
Copy link
Owner

What do you mean? How is it annoying?

@meghe2000
Copy link
Author

meghe2000 commented Jan 11, 2023

google drive video
Video of the problem has been sent.
When we select the box and understand if the pointer is removed from the box. Drag is generally disabled.

@meghe2000
Copy link
Author

Did you notice the problem?

@davidfig
Copy link
Owner

(I think) you need to call event.stopPropagation() in your pointerdown function for when you start drag of your object. Otherwise viewport's pointerDown will trigger.

@meghe2000
Copy link
Author

I tested this, but it didn't work

@davidfig
Copy link
Owner

If you're handling the event, then the viewport shouldn't get the pointerdown, which triggers the drag. You'll have to debug the events to see what's going on. pointermove on viewport will not trigger unless it also receives the pointerdown event.

@meghe2000
Copy link
Author

meghe2000 commented Jan 22, 2023

import { Application, Sprite, Texture } from 'pixijs';
import { Viewport } from 'pixi-viewport'


const app = new Application({
    backgroundAlpha: 1,
    width: innerWidth, height: innerHeight,
    antialias: true,
})
document.body.appendChild(app.view)

const stage = new Viewport({
    screenWidth: window.innerWidth,
    screenHeight: window.innerHeight,
    worldHeight: 1000,
    worldWidth: 1000,
})
app.stage.addChild(stage)
stage.drag().pinch().wheel().decelerate().setZoom(0.5).clampZoom({ maxScale: 2, minScale: 0.3 }).interactiveChildren = true

for (let x = 0; x < 25; x++) {
    for (let y = 0; y < 25; y++) {
        Spawn(x, y)
    }
}

function Spawn(x, y) {
    const box = Sprite.from(Texture.WHITE)
    box.position.set(x * Texture.WHITE.width, y * Texture.WHITE.height)
    box.scale.set(0.90)
    box.on('click', () => console.log('box clicked!'))
    box.interactive = true
    stage.addChild(box)
}

I want to move on the boxes and click on them as well.

@TimWillebrands
Copy link

TimWillebrands commented Feb 14, 2023

@davidfig
I seem to run into the same issue. When you're dragging and the cursor intersects with an object that has the 'interactive' property the drag action sometimes cancels.
In our case we're not attempting to block any event-propagation as it's just a little on-hover effect to guide the user.

The drag doesn't seem to cancel immediately, when you're dragging fast enough or slowly it seems to take a while before it cancels. Also when the drag remains within a limited amount of objects it doesn't cancel either, only reliably when it's more than 3ish.

Interactive off:
ib9TPMt8NV

Interactive on (at no point do I cause a pointerup event when the drag cancels):
HEMGpHE1cr

NB: We're on this branch: https://github.com/cuire/pixi-viewport/tree/v5 but since the issue seems very similar I still though to comment

@voidrender
Copy link

I'm running into similar problems on the v5 branch, where if I drag a sprite too quickly it will stop following the cursor. I switched from onpointermove to onglobalpointermove and it resolves it outside of a viewport, but when I put it inside of a viewport it moves with the viewport. So...not really a fix, but might be a new path to explore.

@meghe2000
Copy link
Author

This is one of the biggest problems with pixi-viewport!

@littleboarx
Copy link
Contributor

littleboarx commented Mar 2, 2023

I check the source code and find out it is due to the incorrect pointerout event handler pop from the child element. A pr may come later.

@davidfig
Copy link
Owner

davidfig commented Mar 2, 2023

Yes, this is caused by pointerout calling cancel. I'll pull together a PR.

littleboarx added a commit to littleboarx/pixi-viewport that referenced this issue Mar 3, 2023
add support for global point move
@littleboarx littleboarx mentioned this issue Mar 3, 2023
davidfig added a commit that referenced this issue Mar 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants