Enjoy programming more!
Kidspod is a post site which supports young programmers.
First step to join us.
Register as a member
For members

2015/07/01 20:27:08

MixJuice GET URL : kidspod.club/mj/14

ぽぽぽぽ HelloWorld

マイアプリで作りました。いっぱいHelloworldの文字がでます。

SOURCE CODE

var res = {
    
};

var MyLayer = cc.KidspodLayer.extend({
 	hello:null,
  	count:0,

	init:function(){
		this._super();
		this.schedule(this.update);
		var size = cc.director.getWinSize();
      
      	this.hello = cc.LabelTTF.create("Hello world!");
      	this.hello.setPosition(size.width/2, size.height/2);
      	this.addChild(this.hello);

		return true;
	},

	update:function(dt){
      	this.count++;
      	if (this.count==10){
          	var size = cc.director.getWinSize();
      		var dx = Math.floor(Math.random()*100);
      		var dy = Math.floor(Math.random()*100);
          	
           	var m = 0
            m = Math.random();
          	if (m <= 0.5 ){
              dx = dx * (-1);
          	}
          	m = Math.random();
          	if (m <= 0.5 ){
              dy = dy * (-1);
          	}
      		this.hello.setPosition(size.width/2+dx, size.height/2+dy);
          	this.count=0;
      	}
	},
 
	onMouseDown:function(event){
		
	},

	onKeyPressed:function(key, event){
		
	},
  
	onTouchBegan:function(touch, event){
  		
	},

	onAccelerometer:function(accelero, event){
    	
  	},
  
});



var MyScene = cc.Scene.extend({
	onEnter:function (){
    	this._super();
    	var layer = new MyLayer();
    	layer.init();
    	this.addChild(layer);
  	}
});

COMMENT