拖动问题

canvas: Node = null;

StartPos: Vec3 = new Vec3();

onLoad() {
    this.canvas = find("Canvas");
    this.StartPos = this.node.position;

    this.node.on(Node.EventType.TOUCH_START, this.Tool_Start, this);
    this.node.on(Node.EventType.TOUCH_MOVE, this.Tool_Move, this);
    this.node.on(Node.EventType.TOUCH_END, this.Tool_End, this);
    this.node.on(Node.EventType.TOUCH_CANCEL, this.Tool_End, this);


}

start() {
    // [3]

}

update(deltaTime: number) {
    // [4]
    //log(this.StartPos)
}

Tool_Start(event: EventTouch) {
    Tween.stopAllByTarget(this.node);
    this.node.getComponent(Animation).stop();
    tween(this.node).to(0.2, { scale: v3(1, 1) }).start();
    let posV2: Vec2 = event.getUILocation();
    let posV3 = this.canvas.getComponent(UITransform).convertToNodeSpaceAR(v3(posV2.x, posV2.y));
    this.node.active = true;
    this.node.setPosition(posV3);

}

Tool_Move(event: EventTouch) {
    let posV2: Vec2 = event.getUILocation();
    let posV3 = this.canvas.getComponent(UITransform).convertToNodeSpaceAR(v3(posV2.x, posV2.y));
    this.node.setPosition(posV3);
}

Tool_End(event: EventTouch) {
    Tween.stopAllByTarget(this.node);
    log(this.StartPos)
    tween(this.node).to(0.5, { position: this.StartPos, scale: v3(0.8, 0.8) }).call(() => {
        this.node.getComponent(Animation).play();
    }).start();
}

这个StartPos在拖动时一直在变,还有拖完一次后就不能再拖了,这个脚本是挂在拖拽物体本身上的,求大佬解救

StartPos只是在一开始赋值了下,为什么在updata里打印的时候却一直在变 :sob:

我把tween去掉就好了,这是什么鬼0.0

有大佬知道吗

StartPos的问题解决了,但是这个tween是咋回事0.0

tween完后,target身上的button都不能点了 :upside_down_face:

大佬们,人呢0.0

顶顶顶0.0

ToolsDrag.ts.zip (1.6 KB) 就是这个脚本,为啥只能拖一次0.0

新手提问:

v3(posV2.x, posV2.y)

这是什么?是不是少了个z分量?

2D的,就没管z :upside_down_face:

哥,你知道为啥只能拖一次吗,而且去掉tween就能拖很多次,只是为啥0.0

顶顶顶=.=

这个换成 试试
this.StartPos = this.node.getPosition();

这个解决了this.StartPos = v3(this.node.position);还剩个只能拖一次的问题0.0

Tool_End(event: EventTouch) {
Tween.stopAllByTarget(this.node);
log(this.StartPos)
tween(this.node).to(0.5, { position: this.StartPos, scale: v3(0.8, 0.8) }).call(() => {
this.node.getComponent(Animation).play();
}).start();
}

scale: v3(0.8, 0.8) } 看清楚 这行代码。这个 错了 应该是 scale: v3(0.8, 0.8,1) }

就是 设置 scale z 不能为 0 你试试吧 马上就好了 我昨天遇到的

注意你上面的这些代码 答案就在这里

我靠,好了,谢谢

所以最终就是要注意v3对象的分量要齐全

emmmm再也不偷懒了 :upside_down_face:

该主题在最后一个回复创建后14天后自动关闭。不再允许新的回复。