自学cocos creator两个月,在学习中开发自己的第一款软件,然后遇到了如下问题,在网上找了好久没得到解决方法,希望大佬能指点一下。
我想实现这样一个功能:在屏幕上点击一次或者触摸一次bar0(它是node类型),在bar0处生成一个NewNote(它是prefab类型)。
我的代码如下:
cc.Class({
extends: cc.Component,
properties: {
NewNotePrefab:{
default:null,
type:cc.Prefab
},
bar0:{
default:null,
type:cc.Node
},
},
setNoteFunction:function(){
var NewNote = cc.instantiate(this.NewNotePrefab);
NewNote.parent = this.bar0;
NewNote.setPosition(0,0);
},
onLoad () {
this.bar0.on("touchstart",function(){
this.setNoteFunction(); //请问这行代码不执行的原因是什么呢?
});
},
start () {
},
});
