gpt4 book ai didi

javascript - 位图逐渐移动到点击(easeljs)

转载 作者:行者123 更新时间:2023-12-03 04:09:31 26 4
gpt4 key购买 nike

我希望我的位图转到单击位置,但我希望看到 bitmap.x/bitmap.y 和 click.x/click.y 之间的进展我怎样才能制作这个动画?

非常感谢

最佳答案

单击舞台时,您可以使用 TweenJS 创建补间:

stage.on("stagemousedown", function(event) {
// Tween to the new position. Override old tweens on the same object.
createjs.Tween.get(bitmapInstance, {override:true}).to({x:event.stageX, y:event.stageY}, 500, createjs.Ease.quadIn);
})

这是一个快速 fiddle :http://jsfiddle.net/jemohtgh/

或者您可以存储单击的位置,并且基本上具有形状总是尝试到达该位置( fiddle ):

var pos = new createjs.Point();
stage.on("stagemousedown", function(event) {
pos.setValues(event.stageX, event.stageY);
})
function tick(event) {
// Move towards the position
s.x += (pos.x - s.x) / 2;
s.y += (pos.y - s.y) / 2;
stage.update(event);
}

您还可以使用鼠标跟随而不是单击来执行相同的操作 ( fiddle ):

function tick(event) {
s.x += (stage.mouseX - s.x) / 5;
s.y += (stage.mouseY - s.y) / 5;
stage.update(event);
}

干杯。

关于javascript - 位图逐渐移动到点击(easeljs),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44387355/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com