Be a Supporter!

hitTest with linkage ID

  • 404 Views
  • 7 Replies
New Topic Respond to this Topic
scuddle666
scuddle666
  • Member since: Dec. 25, 2008
  • Offline.
Forum Stats
Member
Level 04
Blank Slate
hitTest with linkage ID 2010-01-13 11:37:11 Reply

I have multiple MC's and there all attached to the screen dynamically (attachMovie();) and there in seperate groups A and B, when A encounters B or vise versa A and or B attacks the other, but what my problem is, since i cannot apply a hitTest code on each one if they hit each of the enemies attacks, i was wondering if there was a way if you could apply a hitTest via a linkage ID IE
if ("Linkage ID".hitTest("annother Linkage ID){
deduct life
}
If thats possible, please let me know, ATTACHED PROBLEM, Is there a way to attach a code to a dynamically attached MC, if so how? IE _root.location.attachMovie("MC_ID","MC",
10+=MCcount);
"MC".(insert actions)
because i cannot seem to apply a code like
_root.(attached MC)._x +=12; or something. So if anyone has any help on either problem, lemme know.

Johnny
Johnny
  • Member since: Apr. 17, 2004
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to hitTest with linkage ID 2010-01-13 11:51:01 Reply

One way (and one of the better ways) to do it is store all of the enemies/objects in arrays and and use that.

If enemies and bullets are 2 arrays filled with things on screen;

for(i = 0; i < enemies.length; i++)
{
for(j = 0; j < bullets.length; j++)
{
if(enemies[i].hitTest(bullets[j]))
{
//stuff
}
}


Perpetually looking for time to return to the arts.

BBS Signature
scuddle666
scuddle666
  • Member since: Dec. 25, 2008
  • Offline.
Forum Stats
Member
Level 04
Blank Slate
Response to hitTest with linkage ID 2010-01-13 11:54:39 Reply

I think I get what your sayin' I'll try that out

scuddle666
scuddle666
  • Member since: Dec. 25, 2008
  • Offline.
Forum Stats
Member
Level 04
Blank Slate
Response to hitTest with linkage ID 2010-01-13 12:03:21 Reply

I'm still not entirely sure what to do, if anyone can still help me out.

Yambanshee
Yambanshee
  • Member since: Oct. 5, 2008
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to hitTest with linkage ID 2010-01-13 13:19:09 Reply

what he's saying is store all the items you added into an array and then loop through the arrays to carry out a hitTest
i assume AS3, since you can use instance names on AS2

var AAray:Array = new Array ()
var BArray:Array = new Array ()

function AddA ()
{
var item:A = new A()
addChild (item)
AArray.push (item)
}

function AddB ()
{
var item:B = new B()
addChild (item)
BArray.push (item)
}

function hitTestCheck ()
{
var aLength = AArray.length
var bLength = BArray.length
for (var i:uint; i<aLength; ++i)
{
for (var p:uint; p<bLength; ++p)
{
if (AArray[i].hitTestObject(BArray[p]))
{
hitTestFunction ()
}
}
}
}

as me specific bits if you dont understand


AS2||AS3||Motox
Thanks to hdxmike for the sig :]

BBS Signature
Innermike
Innermike
  • Member since: Sep. 11, 2009
  • Offline.
Forum Stats
Member
Level 14
Blank Slate
Response to hitTest with linkage ID 2010-01-13 13:41:01 Reply

At 1/13/10 01:19 PM, Yambanshee wrote: function hitTestCheck ()
{
var aLength = AArray.length
var bLength = BArray.length
for (var i:uint; i<aLength; ++i)
{
for (var p:uint; p<bLength; ++p)
{
if (AArray[i].hitTestObject(BArray[p]))
{
hitTestFunction ()
}
}
}
}

as me specific bits if you dont understand

Whoa whats up with the formating on that script ? theres blank lines everywhere


nobody

Yambanshee
Yambanshee
  • Member since: Oct. 5, 2008
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to hitTest with linkage ID 2010-01-13 13:59:32 Reply

At 1/13/10 01:41 PM, hdxmike wrote: Whoa whats up with the formating on that script ? theres blank lines everywhere

written in the bbs

and i like spacing my things out :]


AS2||AS3||Motox
Thanks to hdxmike for the sig :]

BBS Signature
Innermike
Innermike
  • Member since: Sep. 11, 2009
  • Offline.
Forum Stats
Member
Level 14
Blank Slate
Response to hitTest with linkage ID 2010-01-13 14:03:12 Reply

At 1/13/10 01:59 PM, Yambanshee wrote:
At 1/13/10 01:41 PM, hdxmike wrote: Whoa whats up with the formating on that script ? theres blank lines everywhere
written in the bbs

and i like spacing my things out :]

Suit yourself , i like to cuddle my code with curly braces so theyll grow up loving and warm


nobody