Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
my circle is only bouncing one time on the border of the decagon and then pass throught it.
Copy link to clipboard
Copied
what's this do:
Balle(collisions.object1.limiteBalle());
Find more inspiration, events, and resources on the new Adobe Community
Explore Now