user2069668
user2069668

Reputation: 91

Mario pass through the top of a platform even if the collision was detected (flash CS6)

i am trying to develop a plataform game in flash cs6. I created a class called Plataforma in which a method called enterFrameEvents is responsable for verifying if a platform of such class has collided with mario.

However, no matter what I do, it detects that mario has collided with its top, but mario pass through the platform. But it does not happen when he collids with the bottom and the other sides.

I am pasting a link with my code https://www.4shared.com/rar/jqa5oRGWei/AULA_6.html

In the stage there are two blue platforms which are ocorrences of "plataforma" symbol. Class Plataforma is an actionscript class automatically generated by the flash for "plataforma" symbol.

Here I am pasting the code

   private function enterFrameEvents(event:Event):void{ 
      if(this.hitTestObject(mario)){

        // collision with top
        if(mario.y + mario.height >= this.y &&  mario.y <= this.y &&
         mario.x + mario.width >= this.x + 5 && mario.x <= this.x + this.width - 5 ){

         _root.isJumping = false;
         _root.speedY = 0;
          mario.y = this.y - mario.height;  
      } 
     ...
   }  

I am discount 5 pixels from the corners.

Thank you!

Upvotes: 0

Views: 50

Answers (1)

cameraman
cameraman

Reputation: 252

The problem is the mario.height value.

Explanation: This value constantly changes.

Solution: Add a transparent background to mario MovieClip, slightly bigger than the 4 figures, or add 5 pixels to mario.y after the top collision.

For example:

 mario.y = this.y - mario.height + 5; 

Upvotes: 1

Related Questions