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

hitTestObject movieclips FAILS

New Here ,
Jul 27, 2013 Jul 27, 2013

Hello everyone,

i am getting a trouble with the hitTestObject method.

I have three movie clips- p1_mc,p2_mc,ground_mc

lifea and lifeb are dynamic text boxes. They will record the life of players(it is a fighting game)

variables a & b will record which way the players are facing(left(0) , right(1))

But when i test the movie, hitTestobject only works on   condi(a boolean variable) and cond(a boolean variable)

*PS: this is a part of my whole actions code.

CODE:

import flash.events.*;

lifea.text='100'

lifeb.text='100'

var a = "1";

var b = "0";

MovieClip(root).addEventListener(Event.ENTER_FRAME,etf);

function etf(e:Event) {

          var condit = MovieClip(p2_mc.bk).hitTestObject(p1_mc.a_mc)

          if ( condit) {

                    if (b=="1") {

                              p2_mc.gotoAndStop(9);

                    }

                    if (b=="0") {

                              p2_mc.gotoAndStop(1);

                    }

                    lifea.text= String( Number(lifea.text)-10)

                    p1_mc.alpha -=  0.1;

          }

 

          var cond = (! p2_mc.hitTestObject(ground_mc))

          if ( cond ) {

                    p2_mc.y +=  3;

          } else {

                    k.p2up = false;

          }

 

          var condi = p1_mc.ak.hitTestObject(p2_mc.b_mc)

          if (condi) {

                    if (a=="1") {

                              p1_mc.gotoAndStop(1);

                    }

                    if (a=="0") {

                              p1_mc.gotoAndStop(9);

                    }

                    lifeb.text= String( Number(lifeb.text)-10)

                    p2_mc.alpha -=  0.1;

          }

 

          var co = (! p1_mc.hitTestObject(ground_mc))

          if (co) {

                    p1_mc.y +=  3;

          } else {

                    k.p1up = false;

          }

 

}

TOPICS
ActionScript
579
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 ,
Jul 27, 2013 Jul 27, 2013

What do you have that shows the hitTestObject is failing?  You should use the trace() function to keep track of the hitTest values so that you can see whether or not it is those or some other logic that is not doing what you expect.

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
New Here ,
Jul 27, 2013 Jul 27, 2013

I have written 'a text box shows " hit" when hit.' at two if statement

But only one works......

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 ,
Jul 27, 2013 Jul 27, 2013
LATEST

Use the trace() function to check the values that make up your conditionals to see if they are what they should be and if they are actually being tested  (meaning... trace("condi = " + condi); etc)   If the trail of traces is too much then use more textfields to have the values displayed

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