cc.Class({
extends: cc.Component,
properties: {
},
start () {
//注册Touch事件
this.node.on(cc.Node.EventType.TOUCH_START,this.touchBegin,this);
},
//实现物体移动至Touch的位置
touchBegin:function(event)
{
let sp = cc.find('sprite_splash');
if (sp) {
sp.position = event.getLocation();
}
}
});
本文介绍了一个简单的Cocos Creator脚本,该脚本通过注册Touch开始事件实现了触摸屏幕时移动指定节点到触摸位置的功能。此方法适用于游戏开发中需要响应触摸输入的对象。
2147

被折叠的 条评论
为什么被折叠?



