简体   繁体   English

pixi 视口拖坏工作后 select 一个孩子

[英]pixi viewport drag bad working after select a child

在此处输入图像描述

When I drag on an empty stage, it moves fine.当我在一个空的舞台上拖动时,它移动得很好。

But when I do this on my children, it gets annoying.但是当我对我的孩子这样做时,它变得很烦人。

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)
}

Video of the problem 问题视频

I want to move on the boxes and click on them as well.我想移动框并单击它们。

You can prevent the propagation of pointerdown events on the boxes.您可以阻止pointerdown事件在盒子上的传播。 As a result, the viewport dragging will never start since the viewport will not receive said event:结果,视口拖动永远不会开始,因为视口不会接收到上述事件:

box.on('pointerdown', (e) => {
  e.stopPropagation();
});

This is the related documentation. 是相关文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM