상세 컨텐츠

본문 제목

how to cocos creator single ton via Javascript

개발생활/Cocos2d

by 한국인맛집 2021. 4. 15. 18:04

본문

반응형

Definition

//SingleTon.js

var SingleTon = cc.Class({
  extends: cc.Component,
  
  properties: {
     
  },
  
  statices:{
    instance: null,
    
    getInstance: function(){
       if(SingleTon.instance == null) SingleTon.instance = new SingleTone();
       
       return SingleTon.instance;
    },
  },
  
  foo: function(){
     cc.log("hello world");
  }
  
  // TODO..


});

 

 

usage

//Main.js

var SingleTon = require("SingleTon");
cc.Class({
  extends: cc.Component,
  
  
  
  
  myFunction: function(){
    
    SingleTon.getInstance().foo();
  
  }
  

});

 

반응형

관련글 더보기