mardi 29 décembre 2015

AS3 tween object not working with .hitTestObject()

I am having a major problem in my new browser app.

Okay so I made game where different cubes (squares) spawn at the top of the screen and I use the Tween class to make them go down the screen and then disappear.

However I want to detect a collision when a cube hits the player (that is also a flying cube).

I tried everything, truly everything but it does not seem to work. The problematic thing is that when I remove the "Tween" function it does detect collision with the hitTestObject method but when I add the "Tween" line collision won't be detected anymore.

It looks like this:

       function enemiesTimer (e:TimerEvent):void
  {
      newEnemy = new Enemy1();
      layer2.addChild(newEnemy);
      newEnemy.x = Math.random() * 700;
      newEnemy.y = 10;

      if (enemiesThere == 0)
      {
          enemiesThere = true;
          player.addEventListener(Event.ENTER_FRAME, collisionDetection)
      }



      var Tween1:Tween = new Tween(newEnemy, "y", null, newEnemy.y, newEnemy.y+distance, movingTime, true);
  }

And the collision detection part:

private function collisionDetection (e:Event):void
  {


      if (player.hitTestObject(newEnemy))
      {
          trace("aaa");
      }






  }

I am desperate for some information/help on the topic, it's been bugging me for days.

Thanks for your time, I would be very happy if someone could help me out^^

Aucun commentaire:

Enregistrer un commentaire