Пример #1
0
    testEdgeCollision: function () {
        var vel = util.copy(this.velocity),
            box = this.boundingBox,
            // Get size of canvas
            winSize = cocos.Director.sharedDirector.winSize

        // Moving left and hit left edge
        if (vel.x < 0 && geom.rectGetMinX(box) < 0) {
            // Flip Y velocity
            vel.x *= -1
        }

        // Moving right and hit right edge
        if (vel.x > 0 && geom.rectGetMaxX(box) > winSize.width) {
            // Flip X velocity
            vel.x *= -1
        }

        // Moving up and hit top edge
        if (vel.y < 0 && geom.rectGetMaxY(box) > winSize.height) {
            // Flip X velocity
            vel.y *= -1
        }

        // Moving down and hit bottom edge - DEATH
        if (vel.y > 0 && geom.rectGetMaxY(box) < 0) {
            // Restart game
            this.parent.restart()
        }

        this.velocity = vel
    }
Пример #2
0
	testEdgeCollision: function() {
		var vel = util.copy(this.get('velocity')),
		    ballBox = this.get('boundingBox'),
		    // Get size of canvas
		    winSize = cocos.Director.get('sharedDirector').get('winSize');
		 
		// Moving left and hit left edge
		if (vel.x < 0 && geom.rectGetMinX(ballBox) < 0) {
		    // Flip X velocity
		    vel.x *= -1;
		}
		 
		// Moving right and hit right edge
		if (vel.x > 0 && geom.rectGetMaxX(ballBox) > winSize.width) {
		    // Flip X velocity
		    vel.x *= -1;
		}
		 
		// Moving up and hit top edge
		if (vel.y < 0 && geom.rectGetMinY(ballBox) < 0) {
		    // Flip Y velocity
		    vel.y *= -1;
		}

		this.set('velocity', vel);
	},
Пример #3
0
	testBounds: function() {
	    var vel = util.copy(this.get('velocity')),
            box = this.get('boundingBox'),
            winSize = cocos.Director.get('sharedDirector').get('winSize');

            if (vel.x < 0 && geom.rectGetMinX(box) < 0) {
                //Flip X velocity
                vel.x = 0;
            }

            if (vel.x > 0 && geom.rectGetMaxX(box) > winSize.width) {
                vel.x = 0;
            }

            if (vel.y < 0 && geom.rectGetMinY(box) < 0) {
                vel.y *= 0;
            }

            if (vel.y > 0 && geom.rectGetMaxY(box) > winSize.height) {
                vel.y *= 0;
            }

            this.set('velocity', vel);
        }