|
-
suvat
duplicated movie clip hit test detection
Hey this movie clip duplicates every time space is hit (i e a new bullet is attached and fired)
How do i detect if this hits an enemy lets say?
the original movie clip is called "missile" but the hit test only detects the original not the new ones that are added. How can i solve this?
do duplicated movie clips have a special instance name like "missile2" for example?
thanks
rory
code:
onClipEvent (enterFrame) {
if (_root.ammomode == 1){ if (Key.isDown(Key.SPACE)){
_root.ammo-=5;
missile++;
_root.missile.duplicateMovieClip("missile"+missile , missile);
_root["missile"+missile]._visible = true;
}else{
if (_root.ammomode == 0){
if (Key.isDown(Key.SPACE)){
missile++;
_root.missile.duplicateMovieClip("missile"+missile , missile);
_root["missile"+missile]._visible = true;
}
}
}
}
}
-
Array
Make the bullets into an array. Once they are in array, use this code.
Code:
for(j in Arrayname){
this[Arrayname[j]]._x+=5
}
Code:
onClipEvent(load){
trace("I am a geek")
}
-
suvat
ok ive since found out that it adds a value to the original name of the mc everytime you duplicate it (ie "missile" will go to "missile2" then "missile3"...and so on)
so if i were to make an array would i not have to punch in the value of evey attached mc that may ever come into existance?
Is there not a piece of action script that will represent any real number like that weird r in maths text?
than my hit test code could be as simple as:
code:
onClipEvent(load){
Dead = false;
p = "code for any real number here"
}
onClipEvent(enterFrame){
if(this.hitTest(_root["missile"+p])){
with(_root.baddy){
Dead = true;
}
}
}
is that possible?
thanks
rory
-
Script kiddie
Eep, big problem here - the movie clip you're duplicating, and the counter variable you're concatenating to the duplicate's name, both have the name 'missile'; I'm surprised you're even able to create them successfully in the first place...
-
suvat
if i change the name of the counter variable it makes no difference to the hit test tho, i will still have the same problem but my new mc's will have a different counter variable wont i?
is it possible to represent any number in flash?
rory
-
 Originally Posted by cornyanimation
Make the bullets into an array. Once they are in array, use this code.
Code:
for(j in Arrayname){
this[Arrayname[j]]._x+=5
}
Is "j" the equivalent of the variable "missile"?
-
Senior Member
j is string representing names in Arrayname. this[Arrayname[j]] will give access to each of the missiles.
-
Thanks, I've managed to hitTest detect duplicates now as long as the hitTest only involves one duplicated movieClip.
However I'm still stuck on how to have a duplicateMovieClip detect another duplicateMovieClip.
for (var y:String in list){
_root[list[y]].onEnterFrame = function(){
for (var f:String in list2){
if(_root[list[y]].hitTest(_root[list2[f]])){
_root[list2[f]].removeMovieClip()
_root[list[y]].removeMovieClip()
}}}}
I can't get the hitTest to work in this, is it becuase I used a for...in loop inside of another for...in loop?
-
Senior Member
Try this way
PHP Code:
_root.onEnterFrame = function() {
for (var y:String in list){
for (var f:String in list2){
if (_root[list[y]].hitTest(_root[list2[f]])) {
_root[list2[f]].removeMovieClip();
_root[list[y]].removeMovieClip();
}
}
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|