Collision detection with Corey Oneil collision List need advice


hi, i'm stuck school project. use corey oneil dectetion kit.

 

on stage, have decagon. have button add circles in decagon.

 

these circles go randomly in random direction enter_frame , want them bounce on decagon borders , stay in it.

 

this collision function. can see call method limiteballe() object1 wich class balle ( circles)

 

 

 

 

 

public function verifiercolision(pevt:event)

 

{

  

     var collisions:array = listedecollision.checkcollisions();

 

     if(collisions.length > 0)

{

for (var i:int; < collisions.length; i++)

{

     balle(collisions[i].object1.limiteballe());

     trace("toucher");

}

 

}

 

 

 

 

 

in other class :  balle.as, call eventlistener in function limiteballe() circles bounce 1 time before  going out of decagon

 

public var nombrex:number = randomrange(-15,15);

public var nombrey:number = randomrange(15,-15);

 

public function balle()

{

 

     this.addeventlistener(event.added_to_stage,bougeballe);

 

}

 

 

public function bougeballe(pevt:event)

{

 

     this.addeventlistener(event.enter_frame,bougeballe);

     this.x +=  nombrex;

     this.y +=  nombrey;

 

 

}

 

 

public function limiteballe()

{

 

     this.addeventlistener(event.enter_frame,rebondballe);

 

 

}

 

  

 

 

public function rebondballe(pevt:event)

 

{

 

      if (this.x < 0)

     {

     this.x +=  nombrex;

     rebond1();

     }

 

      if (this.y < 0)

     {

     this.y +=  nombrey;

     rebond1();

     }

 

      if (this.x < 0)

     {

     this.x +=  nombrex;

     rebond2();

     }

 

      if (this.x < 0)

     {

     this.y +=  nombrey;

     rebond2();

     }

 

 

 

public function rebond1(){

 

this.x +=  nombrex;

this.y +=  nombrey;

 

 

 

}

public function rebond2(){

 

this.x -=  nombrex;

this.y -=  nombrey;

 

 

 

}

 

 

}

 

 

thanks

fix this:

 

public function balle()

{

 

     this.addeventlistener(event.added_to_stage,bougeballe);

 

}

 

 

public function bougeballe(pevt:event)

{

 

     this.addeventlistener(event.enter_frame,bougeballe);

     this.x +=  nombrex;

     this.y +=  nombrey;

 

 

}

 

to

 

public function balle()

{

 

     this.addeventlistener(event.added_to_stage,init);

 

}

private function init(e:event):void{

   this.addeventlistener(event.enter_frame,bougeballe);

}

 

 

public function bougeballe(pevt:event)

{

 

 

     this.x +=  nombrex;

     this.y +=  nombrey;

 

 

}

 

 

then explain problem see



More discussions in ActionScript 3


adobe

Comments

Popular posts from this blog

Thread: Can not create raid array: mdadm: no raid-devices specified.

Thread: HOW TO: Package and theme GTK+ / Gtkmm apps in Linux for Windows

Thread: Twinview issues