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

The ball not collision to other ball.

Explorer ,
Jun 12, 2017 Jun 12, 2017

I'triyng to collision the ball with other balls.There is a 2 diffrent ball we have.Balls created from the system,and creating by the player.I have only one ball collision.It's not collide with other balls.How can I collide for other circle.

aeg.gif

import flash.geom.Point;

var NUMBER_OF_CIRCLES:Number = 2;

var NUMKEKKO:Number = 1;

var circle_array:Array;

var boru_array:Array;

var vector_array:Array;

var mass_array:Array;

var mouseuo:Boolean=false;

var the_kall:kall;      //Big ball ( make by player)

var mcKall:boru;

var barz:circle;//

var drag:Boolean=false;

var mcKallCont:MovieClip;

  var kao:Number=10;

  var kao2:Number=10;

  var topisler:Number=2;

  var gonzo:Number=0;

  var topyap:Boolean=true;

stage.addEventListener(Event.ENTER_FRAME, init);

function init(e:Event){

if(topyap==true){

  circle_array = new Array();

  vector_array = new Array();

  mass_array = new Array();

  boru_array = new Array();

  for(var i:Number = 0; i < NUMBER_OF_CIRCLES; i++){

  circle_array = new circle();

  circle_array.width = 25;// circle_array.width = (Math.random() * 50);

  circle_array.height = circle_array.width;

  circle_array.x = (circle_array.width/2) + (Math.random() * (550 - circle_array.width*(3/2)));

  circle_array.y = (circle_array.height/2) + (Math.random() * (400 - circle_array.height*(3/2)));

  var new_color:uint = 0x000077 * Math.random();

  new_color += 0x000088;

  switch(i%3){

  case 0:

  new_color = new_color << 16;

  break;

  case 1:

  new_color = new_color << 8;

  break;

  }

  //new_color = new_color << 16;

  var myColor:ColorTransform = this.transform.colorTransform;

  myColor.color = new_color;

  circle_array.inner.transform.colorTransform = myColor;

  addChild(circle_array);

  circle_array.id = i;

  vector_array = new Array(Math.random() * 10, Math.random() * 10);

  mass_array = circle_array.width * 0.10;

  }

}

topyap=false;

  stage.addEventListener(Event.ENTER_FRAME, circle_update);

}

function circle_update(e:Event){

  for(var i:Number = 0; i < NUMBER_OF_CIRCLES; i++){

  circle_array.x += vector_array[0];

  circle_array.y += vector_array[1];

  //bounding wall collisions

  if(circle_array.x + (circle_array.width * 0.50) >= 550){ vector_array[circle_array.id][0] *= -1; circle_array.x = 550 - circle_array.width * 0.50; }

  if(circle_array.x - (circle_array.width * 0.50) <= 0){ vector_array[circle_array.id][0] *= -1;  circle_array.x = circle_array.width * 0.50; }

  if(circle_array.y + (circle_array.width * 0.50) >= 400){ vector_array[circle_array.id][1] *= -1; circle_array.y = 400 - circle_array.height * 0.50;  }

  if(circle_array.y - (circle_array.width * 0.50) <= 0){ vector_array[circle_array.id][1] *= -1; circle_array.y = circle_array.height * 0.50;   }

  }

  //ball to ball collisions

  for(var g:Number = 0; g < NUMBER_OF_CIRCLES; g++){

  var g_pos:Point = new Point(circle_array.x, circle_array.y)

  for(var k:Number = g + 1; k < NUMBER_OF_CIRCLES; k++){

  var dist = Point.distance(g_pos, new Point(circle_array.x, circle_array.y));

  if( dist < ((circle_array.width * 0.50) + (circle_array.width * 0.50)) ){

  //they're colliding!

  //elastic response

  var mass1:Number = mass_array;

  var mass2:Number = mass_array;

  var mass_sum = mass1 + mass2;

  var velX1:Number = vector_array[0];

  var velX2:Number = vector_array[0];

  var velY1:Number = vector_array[1];

  var velY2:Number = vector_array[1];

  var new_velX1 = (velX1 * (mass1 - mass2) + (2 * mass2 * velX2)) / mass_sum;

  var new_velX2 = (velX2 * (mass2 - mass1) + (2 * mass1 * velX1)) / mass_sum;

  var new_velY1 = (velY1 * (mass1 - mass2) + (2 * mass2 * velY2)) / mass_sum;

  var new_velY2 = (velY2 * (mass2 - mass1) + (2 * mass1 * velY1)) / mass_sum;

  vector_array[0] = new_velX1;

  vector_array[0] = new_velX2;

  vector_array[1] = new_velY1;

  vector_array[1] = new_velY2;

  circle_array.x += new_velX1;

  circle_array.y += new_velY1;

  circle_array.x += new_velX2;

  circle_array.y += new_velY2;

  }

  }

  }

  gonzo=dist;

  

  var kallboyut:Number = the_kall.width +1;

  var kallvector:Number = 7;

  var ikiarray:Number = 9;

  //Kall to ball collisions

  for(var s:Number = 0; s < topisler; s++){

  var t_pos:Point = new Point(the_kall.x, the_kall.y)

  for(var t:Number = s + 1; t < topisler; t++){

  var distf = Point.distance(t_pos, new Point(circle_array.x, circle_array.y));

  if( distf < ((the_kall.width * 0.50) + (circle_array.width * 0.50)) )

  {

  dmm.text = "touched";

  //elastic response

  kao +=0;

    kao2 +=0;

  

  drag=false;

  mouseuo=false;

  }

  }

  }

}

stage.addEventListener(MouseEvent.MOUSE_DOWN,mousePressed);

function mousePressed(e:MouseEvent) {

  the_kall = new kall();

  the_kall.x=mouseX;

  the_kall.y=mouseY;

  addChild(the_kall)

  drag=true;

  mouseuo=true;

  stage.addEventListener(MouseEvent.MOUSE_UP,mousebrk)

}

stage.addEventListener(Event.ENTER_FRAME,Update);

function Update(e:Event) {

  

  

  if(drag==true){

  the_kall.width =kao;

  the_kall.height =kao2;

     kao ++;

    kao2 ++;

  }

  

  

  if(drag==false){

  removeChild(the_kall)

  }

  

  

   if(drag==false && mouseuo==true){

  mcKallCont = new MovieClip () ;

  stage.addChild(mcKallCont);

  mcKall = new boru ();

  mcKallCont.x =the_kall.x ;

  mcKallCont.y = the_kall.y;

  mcKall.width =the_kall.width;

  mcKall.height =the_kall.height;

  mcKallCont.addChild ( mcKall );

  mouseuo=false;

  topisler +=1;

  removeChild(the_kall)

  }

}

  

  

  

  

  

stage.addEventListener(MouseEvent.MOUSE_UP,mousebrk);

function mousebrk(e:MouseEvent) {

  drag=false;

  kao =1;

  kao2 =1;

  //for ( var p = 0; p < mcKallCont.numChildren; p++ )

  //var mcKall1:* = mcKallCont.getChildAt( p );

  

}

stage.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoved);

function mouseMoved(e:MouseEvent) {

  if(drag==true){

  the_kall.x=mouseX;

  the_kall.y=mouseY;

  

  }

}

TOPICS
ActionScript
906
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 ,
Jun 12, 2017 Jun 12, 2017

the first problem i see is init() is called repeatedly and that doesn't appear correct.  is there some reason you're executing init() more than once?

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
Explorer ,
Jun 12, 2017 Jun 12, 2017

No reason is not that.I control with topyap class.

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 ,
Jun 12, 2017 Jun 12, 2017

remove that enterframe listener then and see if that fixes the problem.

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
Explorer ,
Jun 12, 2017 Jun 12, 2017

Okay,I delete enterframe and just using function init(e:Event){ ,but normal balls disappear.

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 ,
Jun 12, 2017 Jun 12, 2017

copy and paste your formatted your code and remove excess empty lines so your code is more legible.

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
Explorer ,
Jun 12, 2017 Jun 12, 2017

import flash.geom.Point;

var NUMBER_OF_CIRCLES:Number = 2;

var NUMKEKKO:Number = 1;

var circle_array:Array;

var boru_array:Array;

var vector_array:Array;

var mass_array:Array;

var mouseuo:Boolean=false;

var the_kall:kall;      //Big ball ( make by player)

var mcKall:boru;

var barz:circle;//

var drag:Boolean=false;

var mcKallCont:MovieClip;

  var kao:Number=10;

  var kao2:Number=10;

  var topisler:Number=2;

  var gonzo:Number=0;

  var topyap:Boolean=true;

function init(e:Event){

if(topyap==true){

  circle_array = new Array();

  vector_array = new Array();

  mass_array = new Array();

  boru_array = new Array();

  for(var i:Number = 0; i < NUMBER_OF_CIRCLES; i++){

  circle_array = new circle();

  circle_array.width = 25;// circle_array.width = (Math.random() * 50);

  circle_array.height = circle_array.width;

  circle_array.x = (circle_array.width/2) + (Math.random() * (550 - circle_array.width*(3/2)));

  circle_array.y = (circle_array.height/2) + (Math.random() * (400 - circle_array.height*(3/2)));

  var new_color:uint = 0x000077 * Math.random();

  new_color += 0x000088;

  switch(i%3){

  case 0:

  new_color = new_color << 16;

  break;

  case 1:

  new_color = new_color << 8;

  break;

  }

  //new_color = new_color << 16;

  var myColor:ColorTransform = this.transform.colorTransform;

  myColor.color = new_color;

  circle_array.inner.transform.colorTransform = myColor;

  addChild(circle_array);

  circle_array.id = i;

  vector_array = new Array(Math.random() * 10, Math.random() * 10);

  mass_array = circle_array.width * 0.10;

  }

}

topyap=false;

  stage.addEventListener(Event.ENTER_FRAME, circle_update);

}

function circle_update(e:Event){

  for(var i:Number = 0; i < NUMBER_OF_CIRCLES; i++){

  circle_array.x += vector_array[0];

  circle_array.y += vector_array[1];

  //bounding wall collisions

  if(circle_array.x + (circle_array.width * 0.50) >= 550){ vector_array[circle_array.id][0] *= -1; circle_array.x = 550 - circle_array.width * 0.50; }

  if(circle_array.x - (circle_array.width * 0.50) <= 0){ vector_array[circle_array.id][0] *= -1;  circle_array.x = circle_array.width * 0.50; }

  if(circle_array.y + (circle_array.width * 0.50) >= 400){ vector_array[circle_array.id][1] *= -1; circle_array.y = 400 - circle_array.height * 0.50;  }

  if(circle_array.y - (circle_array.width * 0.50) <= 0){ vector_array[circle_array.id][1] *= -1; circle_array.y = circle_array.height * 0.50;   }

  }

  //ball to ball collisions

  for(var g:Number = 0; g < NUMBER_OF_CIRCLES; g++){

  var g_pos:Point = new Point(circle_array.x, circle_array.y)

  for(var k:Number = g + 1; k < NUMBER_OF_CIRCLES; k++){

  var dist = Point.distance(g_pos, new Point(circle_array.x, circle_array.y));

  if( dist < ((circle_array.width * 0.50) + (circle_array.width * 0.50)) ){

  //they're colliding!

  //elastic response

  var mass1:Number = mass_array;

  var mass2:Number = mass_array;

  var mass_sum = mass1 + mass2;

  var velX1:Number = vector_array[0];

  var velX2:Number = vector_array[0];

  var velY1:Number = vector_array[1];

  var velY2:Number = vector_array[1];

  var new_velX1 = (velX1 * (mass1 - mass2) + (2 * mass2 * velX2)) / mass_sum;

  var new_velX2 = (velX2 * (mass2 - mass1) + (2 * mass1 * velX1)) / mass_sum;

  var new_velY1 = (velY1 * (mass1 - mass2) + (2 * mass2 * velY2)) / mass_sum;

  var new_velY2 = (velY2 * (mass2 - mass1) + (2 * mass1 * velY1)) / mass_sum;

  vector_array[0] = new_velX1;

  vector_array[0] = new_velX2;

  vector_array[1] = new_velY1;

  vector_array[1] = new_velY2;

  circle_array.x += new_velX1;

  circle_array.y += new_velY1;

  circle_array.x += new_velX2;

  circle_array.y += new_velY2;

  }

  }

  }

  gonzo=dist;

  

  var kallboyut:Number = the_kall.width +1;

  var kallvector:Number = 7;

  var ikiarray:Number = 9;

  //Kall to ball collisions

  for(var s:Number = 0; s < topisler; s++){

  var t_pos:Point = new Point(the_kall.x, the_kall.y)

  for(var t:Number = s + 1; t < topisler; t++){

  var distf = Point.distance(t_pos, new Point(circle_array.x, circle_array.y));

  if( distf < ((the_kall.width * 0.50) + (circle_array.width * 0.50)) )

  {

  dmm.text = "touched";

  //elastic response

  kao +=0;

    kao2 +=0;

  

  drag=false;

  mouseuo=false;

  }

  }

  }

}

////////////********MOUSE EVENTS*******************/////////////////

stage.addEventListener(MouseEvent.MOUSE_DOWN,mousePressed);

function mousePressed(e:MouseEvent) {

  the_kall = new kall();

  the_kall.x=mouseX;

  the_kall.y=mouseY;

  addChild(the_kall)

  drag=true;

  mouseuo=true;

  stage.addEventListener(MouseEvent.MOUSE_UP,mousebrk)

}

stage.addEventListener(Event.ENTER_FRAME,Update);

function Update(e:Event) {

  

  

  if(drag==true){

  the_kall.width =kao;

  the_kall.height =kao2;

     kao ++;

    kao2 ++;

  }

  

  

  if(drag==false){

  removeChild(the_kall)

  }

  

  

   if(drag==false && mouseuo==true){

  mcKallCont = new MovieClip () ;

  stage.addChild(mcKallCont);

  mcKall = new boru ();

  mcKallCont.x =the_kall.x ;

  mcKallCont.y = the_kall.y;

  mcKall.width =the_kall.width;

  mcKall.height =the_kall.height;

  mcKallCont.addChild ( mcKall );

  mouseuo=false;

  topisler +=1;

  removeChild(the_kall)

  }

}

  

  

 

stage.addEventListener(MouseEvent.MOUSE_UP,mousebrk);

function mousebrk(e:MouseEvent) {

  drag=false;

  kao =1;

  kao2 =1;

  //for ( var p = 0; p < mcKallCont.numChildren; p++ )

  //var mcKall1:* = mcKallCont.getChildAt( p );

  

}

stage.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoved);

function mouseMoved(e:MouseEvent) {

  if(drag==true){

  the_kall.x=mouseX;

  the_kall.y=mouseY;

  

  }

}

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 ,
Jun 12, 2017 Jun 12, 2017

that's still difficult to read, but i don't see where you call init().  is that done somewhere?

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
Explorer ,
Jun 12, 2017 Jun 12, 2017

Sorry but same problem.Can you check at link please ? I upload fla

Dropbox - circle_collision44544.fla

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 ,
Jun 12, 2017 Jun 12, 2017

are you calling init()?

did you check for errors in your code?

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
LEGEND ,
Jun 12, 2017 Jun 12, 2017

init() is at the end of his script. Didn't quite make it into the post.

Do what I said about Publish Settings, and permit debugging. If you even just do a Test Movie you will see lots of errors in the output window, along with the line number of the thing causing a problem.

First thing you'll need to do is comment out these lines in in the kall symbol timeline:

import Tekno;

Tekno.kantel = true;

Or given us that class file too.

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
Explorer ,
Jun 12, 2017 Jun 12, 2017

The Tekno class does not work to anything.I forgotten from past project I'm sorry.i clear to kall as and make the test.Here is the bug list.

TypeError: Error #1009:

  at circle_collision44544_fla::MainTimeline/circle_update()

TypeError: Error #2007: child parametresi boş olmamalıdır.

  at flash.display::DisplayObjectContainer/removeChild()

  at circle_collision44544_fla::MainTimeline/Update()

  When player ball(the kall) collision to other ball.

  TypeError: Error #1010: Bir terim tanımsız ve özelliÄŸi yok.

  at circle_collision44544_fla::MainTimeline/circle_update()

ArgumentError: Error #2025: Sağlanan DisplayObject çağıranın alt öğesi olmalıdır.

  at flash.display::DisplayObjectContainer/removeChild()

  at circle_collision44544_fla::MainTimeline/Update()

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
LEGEND ,
Jun 12, 2017 Jun 12, 2017

You still don't have permit debugging turned on, so it's hard to see what line the error is on.

Amongst the errors you have, two to start with are:

In some cases you're trying to get the width of an object that doesn't yet exist. That may be because you have init() at the end of the script, after you're already assuming that it has been run.

You're trying to do a removeChild() of something that isn't yet a child of anywhere.

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
Explorer ,
Jun 12, 2017 Jun 12, 2017
Attempting to launch and connect to Player using URL C:\APK\bouncegame\circle_collision44544.swf

[SWF] C:\APK\bouncegame\circle_collision44544.swf - 46575 bytes after decompression

TypeError: Error #1009: Boş nesne başvuru özelliğine veya yöntemine erişilemiyor.

at circle_collision44544_fla::MainTimeline/circle_update()[circle_collision44544_fla.MainTimeline::frame1:208]

Debug session terminated.

This is the debug.

https://forums.adobe.com/people/Colin+Holgate  wrote

You're trying to do a removeChild() of something that isn't yet a child of anywhere.

I use addChild(the_kall) at :frame1:295

In some cases you're trying to get the width of an object that doesn't yet exist.

https://forums.adobe.com/people/Colin+Holgate  wrote

In some cases you're trying to get the width of an object that doesn't yet exist. That may be because you have init() at the end of the script, after you're already assuming that it has been run.

Yes because the call get active when user press the mouse.

So,what should I do now.

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
LEGEND ,
Jun 12, 2017 Jun 12, 2017

The first error is because of this line:

var kallboyut:Number = the_kall.width +1;

You're trying to get the width of the_kall in the update function, but the_kall isn't created until the mouse down function.

Likewise, in two places in the update function you are doing this:

removeChild(the_kall);

but the_kall doesn't exist at yet, and so you get another error.

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
Explorer ,
Jun 13, 2017 Jun 13, 2017

Okay I delete those var kallboyut and three of them and make to comment this lines and no debug error.But now ball is not collising to any ball.!

//removeChild(the_kall)

//removeChild(the_kall)

    //Kall to ball collisions /*  

for(var s:Number = 0; s < topisler; s++){
var t_pos:Point = new Point(the_kall.x, the_kall.y)
for(var t:Number = s + 1; t < topisler; t++){
var distf = Point.distance(t_pos, new Point(circle_array.x, circle_array.y));
if( distf < ((the_kall.width * 0.50) + (circle_array.width * 0.50)) ) {
dmm.text = "touched";  //elastic response kao +=0; kao2 +=0;  drag=false; mouseuo=false;    } } }

*/
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
LEGEND ,
Jun 13, 2017 Jun 13, 2017

You will need to do the removeChild(), just don't try to remove the_kall before it exists. You probably should set up your update listener after the init() has run, but you could also work around the problem with a hack:

if(the_kall) removeChild(the_kall);

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
Explorer ,
Jun 13, 2017 Jun 13, 2017
LATEST

I change this and now ball collided to ball made from the player's.

  if(drag==false && mouseuo==true){

  var i:Number = NUMBER_OF_CIRCLES;

   NUMBER_OF_CIRCLES+=1;

   circle_array = new circle();

   circle_array.width = the_kall.width;

   circle_array.height = circle_array.width;

   circle_array.x = the_kall.x;

   circle_array.y = the_kall.y;

   /*var myColor:ColorTransform = this.transform.colorTransform;

   myColor.color = 0x000077 * Math.random() + 0x000088;

   circle_array.inner.transform.colorTransform = myColor;*/

   addChild(circle_array);

   circle_array.id = i;

   vector_array = new Array(0,0);

   mass_array = circle_array.width * 0.10;

   removeChild(the_kall)

  

  

  

  

  }

But it still not collide one ball (red) ball what is the problem now ?

bandicam-2017-06-13-17-40-36-110.gif

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
LEGEND ,
Jun 12, 2017 Jun 12, 2017

There are quite a lot of mistakes in the code. If you go into Publish Settings you can check the permit debugging option, and then do Debug Test Movie. When an error happens you're take to the line that went wrong, and there is a list of variables that you can inspect to help figure out what went wrong.

Eventually you will fix al of the errors, then it would be easier to concentrate on why one particular thing isn't working.

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