A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: hit test movie clip twice??

  1. #1
    Registered User
    Join Date
    Jul 2022
    Posts
    3

    Talking hit test movie clip twice??

    ok ive got this movieclip "hitbox P2" right now its just on its own in the time line and its just told to move left until it hits the fighter's hurt box so,
    Code:
    onClipEvent(enterFrame) {
    	
    	if (attackActive == true )
    		{
    			this._x += 500;
    		}
    		
    	
    	
    	if(this.hitTest(Object(this._parent).fighter.hurtBoxP1)){
    		
    		attackActive = false;
    
                    }
    Capture.PNG

    it works fine but the only problem is im using more than one hitbox and thats confusing the hittest alot so it does nothing
    so my problem is like is there a line of code that would like let the hit test know its going to be hitting mutiple of the same object or should i just make like 6 new movie clips and have 7 seprate hitboxes
    thanks in advance to anyone who responds

  2. #2
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,834
    You cannot use the same instance names for different objects and expect more than one to be targeted. You need to assign unique names, or you can store references to them in an array and use the array to target them.
    .

  3. #3
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    Hello, with a displayList array you can add each hurtBox's string name & check all of the hurtBoxes in a for loop to see if there is something touching:
    PHP Code:
    onClipEvent(enterFrame) {

    if (
    attackActive == true ){
    this._x += 500;
    }
    var 
    displayList=['hurtBoxP1','hurtBoxP2','hurtBoxP3']
    var 
    affectedHealth=[51050]
    for(var 
    i=0;i<displayList.length;i++){
    if(
    this.hitTest(Object(this._parent).fighter[displayList[i]])){
    trace(true)
    trace("subtracted " affectedHealth[i])

    attackActive false;
    }
    }


    Last edited by AS3.0; 08-05-2022 at 04:41 PM.

  4. #4
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    Here is an extra example I did to identify the body part affected:

    PHP Code:
    onClipEvent(enterFrame) {

    if (
    attackActive == true ){
    this._x += 500;
    }
    var 
    displayList=['hurtBoxP1','hurtBoxP2','hurtBoxP3']
    var 
    affectedHealth=[51050]
    var 
    bodyPart=["Head","Body","Legs"]
    for(var 
    i=0;i<displayList.length;i++){
    if(
    this.hitTest(Object(this._parent).fighter[displayList[i]])){
    trace(true)
    trace("subtracted " affectedHealth[i] + " you were hit from " bodyPart[i])

    attackActive false;
    }
    }



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center