vendredi 10 février 2017

Moving away object when hit each other

I don't wanna to overlap each other the objects.Also I wanna keep the objects in stage limit.The buttons must move away when hit each other.I tried hitTestObject but buttons move like crazy.

Sample move code for fish 2

var fish2x:Number=8;
var fish2y:Number=8;
 
stage.addEventListener(Event.ENTER_FRAME,h42);
function h42(s:Event) {
fish2.x+=fish2x;
fish2.y+=fish2y;
if ((fish2.x>=stage.stageWidth-fish2.width/2)|| (fish2.x <= fish2.width/2 )) {
    fish2x*=-1;
}
if ((fish2.y>=stage.stageHeight-fish2.height/2)|| (fish2.y <= fish2.height/2 )) {
    fish2y*=-1;
}
if (fish2.hitTestObject(fish || fish3 )) {

fish2y*=+4;
message.text="crash";
}
}
fish2.mouseEnabled = false;

Also I tried in diffrent function

stage.addEventListener(Event.ENTER_FRAME,crash);
function crash(s:Event) {
 
if (fish2.hitTestObject(fish || fish3 )) {

fish2y*=-1;
message.text="crash";
}
}

Aucun commentaire:

Enregistrer un commentaire