How to define enum property in Cocos Creator

How to define enum property in Cocos Creator
0.0 0

#1

Hi! How can I define enum or string list property in a component? So that developer can pick one of predefined values?


#2

hi, try this

var EnGameState;
EnGameState = cc.Enum({
  Pause: 0,
  GameStarted: 1,
  GamePlaying: 2,
  RobotDeath: 3,
  GameOver: 4
});

cc.Class({
  "extends": cc.Component,
  properties: {
    GameState: {
      "default": EnGameState.GameStarted,
      type: EnGameState
    }
  },
  onLoad: function() {
 this.GameState = EnGameState.GameStarted
 }
});

#3

Thanks it works!