Forum Topic: Multiple MC collision

(94 views • 12 replies)

This topic is 1 page long.

<< < > >>
None

rednekSVK

Reply To Post Reply & Quote

Posted at: 2/6/09 05:38 AM

rednekSVK LIGHT LEVEL 17

Sign-Up: 04/20/07

Posts: 46

Hi
I am sure this has been asked thousand times before, but I can't find it anywhere on the forums :C...
If you just could answer it once again, or link to the old discussions, I would be really thankful :3

So, I have a simple script to detect the collision

if (_root.player hitTest(_root.ball)) {
do something
}

But what if I have like 100 balls on the screen? And I want to detect the collision with all of them?
Something like:

if (_root.player hitTest(_root.AnyOfBallsOnTheScreen)) {
do something
}

How am I supposed to do that? Thanks for any help


None

CrustySheet

Reply To Post Reply & Quote

Posted at: 2/6/09 05:54 AM

CrustySheet LIGHT LEVEL 03

Sign-Up: 05/03/06

Posts: 532

you need to look into arrays and for loops


None

rednekSVK

Reply To Post Reply & Quote

Posted at: 2/6/09 06:11 AM

rednekSVK LIGHT LEVEL 17

Sign-Up: 04/20/07

Posts: 46

What does that mean? Could you be more specific please?


None

CrustySheet

Reply To Post Reply & Quote

Posted at: 2/6/09 06:18 AM

CrustySheet LIGHT LEVEL 03

Sign-Up: 05/03/06

Posts: 532

arrays will hold data

say you have fruit.. banana apple grape orange

instead of having 4 variables you use and array

fruit[];

so you get
fruit[0] = banana
fruit[1] = apple
fruit[2] = grape
fruit[3] = orange

and you use a for look through them all

do a google search on actionscript array tutorial you will understand


None

rednekSVK

Reply To Post Reply & Quote

Posted at: 2/6/09 07:02 AM

rednekSVK LIGHT LEVEL 17

Sign-Up: 04/20/07

Posts: 46

I do understand what is array, but how will it help to solve my problem?


None

CrustySheet

Reply To Post Reply & Quote

Posted at: 2/6/09 07:10 AM

CrustySheet LIGHT LEVEL 03

Sign-Up: 05/03/06

Posts: 532

At 2/6/09 07:02 AM, rednekSVK wrote: I do understand what is array, but how will it help to solve my problem?

ok something like this

for (i=0; i< platforms.length[]; i++){

  if(_root.character.hitTest(platorms[])){

//do stuff

}

}

dont copy paste cos it wont work

but basically as long as i is less than the amount of platforms in the array it will run the hittest

but im not going to explain all about arrays cos i havnt used them in ages and also i can see that if you dont know how they will help you then you dont know too much about them and it will take awhile


None

rednekSVK

Reply To Post Reply & Quote

Posted at: 2/6/09 07:15 AM

rednekSVK LIGHT LEVEL 17

Sign-Up: 04/20/07

Posts: 46

Aaaah, so simple
I understand now, thanks, you rock :]

One last question, what is that lenght[]? Is it another variable? Why is it in there?


None

Murudai

Reply To Post Reply & Quote

Posted at: 2/6/09 07:19 AM

Murudai FAB LEVEL 09

Sign-Up: 04/15/08

Posts: 371

At 2/6/09 07:15 AM, rednekSVK wrote: Aaaah, so simple
I understand now, thanks, you rock :]

One last question, what is that lenght[]? Is it another variable? Why is it in there?

It's there to confuse you :) Like Crusty said, that is not the proper code, it has errors. You must learn for yourself how to do it, but what Crusty said is the direction you should follow.

It's frustrating, but you learn more this way :)

Murudai: Indie Game Developer
I make Xbox 360 games. And the odd Flash game.
Website: http://murudai.com/

BBS Signature

None

CrustySheet

Reply To Post Reply & Quote

Posted at: 2/6/09 07:21 AM

CrustySheet LIGHT LEVEL 03

Sign-Up: 05/03/06

Posts: 532

At 2/6/09 07:15 AM, rednekSVK wrote: Aaaah, so simple
I understand now, thanks, you rock :]

One last question, what is that lenght[]? Is it another variable? Why is it in there?

umm i'm going to say to you

open flash press f1 and search .length

it will show you how it works and give you examples


None

CrustySheet

Reply To Post Reply & Quote

Posted at: 2/6/09 07:26 AM

CrustySheet LIGHT LEVEL 03

Sign-Up: 05/03/06

Posts: 532

At 2/6/09 07:19 AM, Murudai wrote:
At 2/6/09 07:15 AM, rednekSVK wrote: Aaaah, so simple
I understand now, thanks, you rock :]

One last question, what is that lenght[]? Is it another variable? Why is it in there?
It's there to confuse you :) Like Crusty said, that is not the proper code, it has errors. You must learn for yourself how to do it, but what Crusty said is the direction you should follow.

It's frustrating, but you learn more this way :)

yeah im so crap at AS without flash open and syntax highlighting.. but

basically it sets i to 0
then it checks the condition... is i less than the length of the array .. u have 100 platforms in there so platforms is.. uhh either 99 or 100 in length(it starts at 0).. sorry alot of rum tonight

now cos i is equel to 0 it is less than platforms so it runs the code

it finishes the code and adds 1 to i (i++)

then it runs the for (loop) again it does this UNTIL i is equel to the platforms length

woah too much for me tonight


None

henke37

Reply To Post Reply & Quote

Posted at: 2/6/09 07:42 AM

henke37 NEUTRAL LEVEL 23

Sign-Up: 09/10/04

Posts: 3,590

i preffer the for each .. in loop

for each(var enemy in enemies){
 trace(enemy);
}

Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.


None

CrustySheet

Reply To Post Reply & Quote

Posted at: 2/6/09 07:47 AM

CrustySheet LIGHT LEVEL 03

Sign-Up: 05/03/06

Posts: 532

At 2/6/09 07:42 AM, henke37 wrote: i preffer the for each .. in loop

for each(var enemy in enemies){
trace(enemy);
}

alot do but for each goes over my head


None

ThePeasant

Reply To Post Reply & Quote

Posted at: 2/6/09 11:08 AM

ThePeasant NEUTRAL LEVEL 08

Sign-Up: 08/30/07

Posts: 447

Another way to do it without using a long array is to

1) create a seperate layer with only the balls in it
2) use this condition:

if (layer.hitTestPoint(Player.x,Player.y,true)){
// do your collision thing here
}

That's what it looks like in AS3 anyways... I assume it's similar in AS2.


All times are Eastern Standard Time (GMT -5) | Current Time: 10:15 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!