Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Collision detection with Corey Oneil collision List need advice

New Here ,
Nov 18, 2013 Nov 18, 2013

Hi, I'm currently stuck for a school project. I use the Corey Oneil Dectetion Kit.

On my stage, I have a decagon. I have a button who add circles in the decagon.

These circles go randomly in a random direction with an ENTER_FRAME and I want them to bounce on the decagon borders and stay in it.

this is my collision function. As you can see I call the method limiteBalle() for the object1 wich is my class Balle ( my circles)

public function verifierColision(pEvt:Event)

{

  

     var collisions:Array = listeDeCollision.checkCollisions();

     if(collisions.length > 0)

{

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

{

     Balle(collisions.object1.limiteBalle());

     trace("toucher");

}

}

In my other Class :  Balle.as, I call an eventListener in the function limiteBalle() but the circles only bounce one time before  going out of the 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

TOPICS
ActionScript
730
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 18, 2013 Nov 18, 2013

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 what problem you see

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 18, 2013 Nov 18, 2013

my circle is only bouncing one time on the border of the decagon and then pass throught it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 19, 2013 Nov 19, 2013
LATEST

what's this do:

Balle(collisions.object1.limiteBalle());

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines