Doubt with collision
fgb01

Good night people...
I am trying to make the collisions for my game but I am not able to understand how this wade collision works.
Could you please help me, because I can not understand the tutorials?

Thank you!

All 6 Comments
Gio

Hi

Which tutorial(s) are you following?

Have you seen this one?

How to make HTML5 games - angry birds

That covers some basic physics stuff including collisions.

In short:

- Enable physics in the editor, this will add a couple of files to your project

- In the Behaviors tab of your SceneObjects, you should now have the option to select PhysicsObject. Do that.

- Change parameters of physics objects (i.e. are objects static, dynamic, how heavy, etc)

- Your physics objects will now receive onCollisionEvents. In their onCollision functions you get some data that tells you what they are colliding with
 

Gio

I should also say that if you do not want to use a physics simulation and keeps thing simple, and you only care about sprites overlapping rather than actual collisions between physics objects, you can also check for overlaps with

var overlappingObjects = myObject.getOverlappingObjects();

There are a couple of parameters you can pass to getOverlappinObjects to fine-tune its behavior. See the API documentation for more details.

fgb01

Good Morning...
Could you give me an example of usage please ... if it is in Update that uses and etc ...
Thank you very much.

fgb01

I got it ...
Many thanks for the explanation ...

Var collision = this.getOverlappingObjects (true);
For (i = 0; i <colisao.length; i ++)
     Wade.removeSceneObject (collision [i]);
     Wade.removeSceneObject (this);
}

Now what if it were to collide with a specific object?
Thank you very much

Gio
var collidingObjects = wade.getOverlappingObjects(true);
for (var i=0; i<collidingObjects.length; i++)
{
    if (collidingObjects[i].getName() == 'some specific object name')
    {
         wade.removeSceneObject(collidingObjects[i]);
         break;
    }
}

If you want to only detect collisions with a specific type of object, then set a custom property on the object(s) that you care about. This is done in the SceneObjects Properties tab. Set any custom property, for example set collideWithMe = true

Then in the above code, replace the if (...) condition with

if (collidingObjects[i].collideWithMe)

 

fgb01

I got it ...
Many thanks for the explanation ...

 

Post a reply
Add Attachment
Submit Reply
Login to Reply