|
|
@@ -22,12 +22,13 @@ exports.component = function(self) {
|
|
|
});
|
|
|
|
|
|
self.subscribeToEvent("MultiGesture", function(event) {
|
|
|
- if(event.numFingers >= 2) {
|
|
|
+ if(event.numFingers >= 2 && !self.started) {
|
|
|
self.runBall();
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- self.node.position2D = [self.node.position2D[0], -Atomic.graphics.height/2.5*Atomic.PIXEL_SIZE];
|
|
|
+ self.zoom = self.node.scene.getMainCamera().zoom;
|
|
|
+ self.node.position2D = [self.node.position2D[0], -Atomic.graphics.height/2.5*Atomic.PIXEL_SIZE/self.zoom];
|
|
|
}
|
|
|
self.createStartBall = function() {
|
|
|
//create startBall prefab
|
|
|
@@ -42,14 +43,14 @@ exports.component = function(self) {
|
|
|
//get rigidBody component of ours ball
|
|
|
var body = self.startBall.getComponent("RigidBody2D");
|
|
|
//let's run our ball!
|
|
|
- body.applyForceToCenter([20 + Math.random(), 20 + Math.random()], true);
|
|
|
+ body.applyForceToCenter([20/self.zoom + Math.random(), 20/self.zoom + Math.random()], true);
|
|
|
self.startBallComponent.started = true;
|
|
|
self.started = true;
|
|
|
}
|
|
|
|
|
|
self.update = function(delta) {
|
|
|
//if we haven't ball started
|
|
|
- if(!self.started) {
|
|
|
+ if (!self.started) {
|
|
|
//check mouse button click
|
|
|
if(Atomic.input.getMouseButtonPress(Atomic.MOUSEB_LEFT) || Atomic.input.getKeyDown(Atomic.KEY_SPACE)) {
|
|
|
self.runBall();
|
|
|
@@ -60,14 +61,14 @@ exports.component = function(self) {
|
|
|
if (Atomic.platform == "Android" || Atomic.platform == "iOS") {
|
|
|
//get touches
|
|
|
var numTouches = Atomic.input.getNumTouches();
|
|
|
- //if we don't have touches, return
|
|
|
- if (numTouches <= 0) return;
|
|
|
- //get the last touch state
|
|
|
- var touchState = Atomic.input.getTouch(numTouches-1);
|
|
|
+ //we want use only one finger, so return if there's more
|
|
|
+ if (numTouches != 1) return;
|
|
|
+ //get the first touch state
|
|
|
+ var touchState = Atomic.input.getTouch(0);
|
|
|
//get current mouse position, and project screen coordinates to the world coordinates
|
|
|
var pos = Atomic.renderer.getViewport(0).screenToWorldPoint(touchState.position[0], 0, 0);
|
|
|
//set y value to -3
|
|
|
- pos[1] = -Atomic.graphics.height/2.5*Atomic.PIXEL_SIZE;
|
|
|
+ pos[1] = -Atomic.graphics.height/2.5*Atomic.PIXEL_SIZE/self.zoom;
|
|
|
// set paddle position to the calculated one
|
|
|
self.node.position2D = pos;
|
|
|
} else {
|
|
|
@@ -85,16 +86,16 @@ exports.component = function(self) {
|
|
|
//get current mouse position, and project screen coordinates to the world coordinates
|
|
|
var pos = Atomic.renderer.getViewport(0).screenToWorldPoint(Atomic.input.getMousePosition()[0], 0, 0);
|
|
|
//set y value to -3
|
|
|
- pos[1] = -Atomic.graphics.height/2.5*Atomic.PIXEL_SIZE;
|
|
|
+ pos[1] = -Atomic.graphics.height/2.5*Atomic.PIXEL_SIZE/self.zoom;
|
|
|
// set paddle position to the calculated one
|
|
|
self.node.position2D = pos;
|
|
|
}
|
|
|
}
|
|
|
- if(self.node.position2D[0] < -Atomic.graphics.width / 2*Atomic.PIXEL_SIZE) {
|
|
|
- self.node.position2D = [-Atomic.graphics.width / 2*Atomic.PIXEL_SIZE, -Atomic.graphics.height/2.5*Atomic.PIXEL_SIZE];
|
|
|
+ if(self.node.position2D[0] < -Atomic.graphics.width / 2*Atomic.PIXEL_SIZE/self.zoom) {
|
|
|
+ self.node.position2D = [-Atomic.graphics.width / 2*Atomic.PIXEL_SIZE/self.zoom, -Atomic.graphics.height/2.5*Atomic.PIXEL_SIZE/self.zoom];
|
|
|
}
|
|
|
- if(self.node.position2D[0] > Atomic.graphics.width / 2*Atomic.PIXEL_SIZE) {
|
|
|
- self.node.position2D = [Atomic.graphics.width / 2*Atomic.PIXEL_SIZE, -Atomic.graphics.height/2.5*Atomic.PIXEL_SIZE];
|
|
|
+ if(self.node.position2D[0] > Atomic.graphics.width / 2*Atomic.PIXEL_SIZE/self.zoom) {
|
|
|
+ self.node.position2D = [Atomic.graphics.width / 2*Atomic.PIXEL_SIZE/self.zoom, -Atomic.graphics.height/2.5*Atomic.PIXEL_SIZE/self.zoom];
|
|
|
}
|
|
|
}
|
|
|
}
|