I wanted to create an android app using accelerometer in as3 based on the template.
**I have 2 MC : **
-ball (the red one)
-balla (the green one)
The accelerometer things are fine,but what I want is both of the balls collide not overlaying each other.
What sort of code that I need to write?:q:
Here’s my current code :
import flash.events.Event;
var accelX:Number;
var accelY:Number;
var fl_Accelerometer:Accelerometer = new Accelerometer();
fl_Accelerometer.addEventListener(AccelerometerEvent.UPDATE, fl_AccelerometerUpdateHandler);
function fl_AccelerometerUpdateHandler(event:AccelerometerEvent):void
{
accelX = event.accelerationX;
accelY = event.accelerationY;
}
ball.addEventListener(Event.ENTER_FRAME, moveBall);
function moveBall(evt:Event){
ball.x -= accelX*20;
ball.y += accelY*20;
if(ball.x > (480-ball.width/2)){
ball.x = 480-ball.width/2;
}
if(ball.x < (0+ball.width/2)){
ball.x = 0+ball.width/2;
}
if(ball.y > (800-ball.width/2)){
ball.y = 800-ball.width/2;
}
if(ball.y < (0+ball.width/2)){
ball.y = 0+ball.width/2;
}
}
balla.addEventListener(Event.ENTER_FRAME, moveBalla);
function moveBalla(evt:Event){
balla.x -= accelX*20;
balla.y += accelY*20;
if(balla.x > (480-balla.width/2)){
balla.x = 480-balla.width/2;
}
if(balla.x < (0+balla.width/2)){
balla.x = 0+balla.width/2;
}
if(balla.y > (800-balla.width/2)){
balla.y = 800-balla.width/2;
}
if(balla.y < (0+balla.width/2)){
balla.y = 0+balla.width/2;
}
}
Thank you.