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 19:38:48

MixJuice GET URL : kidspod.club/mj/13

当たり判定やってみた

ココス楽しー

  • No registered tag exist.

SOURCE CODE

var res = {
    
};

var MyLayer = cc.KidspodLayer.extend({
	

    init:function(){
	this._super();
	this.schedule(this.update);
	var size = cc.director.getWinSize();

	var pos_x = size.width/2;
	var pos_y = size.height/2
	var vel_x = 3.5;
	var vel_y = 3.5;
	
	var ball = cc.Sprite.create("res/galaxy/ball.png");	
	ball.setPosition(pos_x,pos_y);
	this.addChild(ball);

	
	this.schedule(function(){
	    pos_x = pos_x + vel_x;
	    pos_y = pos_y + vel_y;
	    if( pos_x < 0 || size.width < pos_x )
	    {
		vel_x = -(vel_x);
	    }
	    if( pos_y < 0 || size.height < pos_y )
	    {
		vel_y = -(vel_y);
	    }
	    ball.setPosition(pos_x,pos_y);
        }, 0.01);
	
	return true;
    },

	update:function(dt){

	},
 
	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