cocos creator 数组_CoCos Creator中的数据类型
常用到的基本數據類型有Integer、String、Vec2、Color,下面的是它們最基本的使用展示:
properties: {
myNumber:{
default:0,
type:cc.Integer,
},
myString:{
default:'HaHa',
},
myVec2:{
default:cc.Vec2.ZERO,
},
myColor:{
default:cc.Color.RED,
},
myOtherNumber:0,
myOtherString:'BBB',
myOtherVec2:cc.Vec2.ONE,
myOtherColor:cc.Color.WHITE,
},
組件類型:
properties: {
myNode:{
default:null,
type:cc.Node,
},
mySprite:{
default:null,
type:cc.Sprite,
},
myLabel:{
default:null,
type:cc.Label,
},
myComponent:{
default:null,
type:MyCustomComponent,
},
mySprite:{
default:null,
type:cc.Sprite,
},
mySpriteFrame:{
default:null,
type:cc.SpriteFrame,
},
mySpriteAtlas:{
default:null,
type:cc.SpriteAtlas,
},
myPrefab:{
default:null,
type:cc.Prefab,
},
myAudioClip:{
default:null,
type:cc.AudioClip,
},
},
這其中的MyCustomComponent是自定義的類型。首先我們在Canvas節點下新建一個空節點,命名為mycomponent,在節點上添加一個用戶腳本文件,取名為MyCustomComponent。在腳本中需要使用的時候,使用const MyCustomComponent=require('MyCustomComponent'),賦值的時候則把對應的那個mycomponent節點拖進去就行了。
我們在創建String類型的數據的時候,如果不想在編輯器中看到的話,則可以將visible設置為false,這樣String類型的數據只能在腳本中進行修改操作。
cc.Class({
extends: cc.Component,
properties: {
nonSeriableText:{
default:'',
visible:false,
},
seriableText:'',
mLabel1:{
default:null,
type:cc.Label,
},
mLabel2:{
default:null,
type:cc.Label,
},
},
// LIFE-CYCLE CALLBACKS:
onLoad () {
this.nonSeriableText='Can only set in script';
this.mLabel1.string=this.nonSeriableText;
this.mLabel2.string=this.seriableText;
},
start () {
},
update (dt) {},
});
總結
以上是生活随笔為你收集整理的cocos creator 数组_CoCos Creator中的数据类型的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 程序人生:这5个程序员,改变了世界,你都
- 下一篇: cacti安装配置详解_MySQL实战0