collinhover / impactplusplus

Impact++ is a collection of additions to ImpactJS with full featured physics, dynamic lighting, UI, abilities, and more.
http://collinhover.github.com/impactplusplus
MIT License
276 stars 59 forks source link

Question about collideable fixed objects #155

Closed codecomp closed 10 years ago

codecomp commented 10 years ago

I'm trying to make some Mario stylre coins that are not affected by gravity, but I'm just wondering what is the best/right way of making such an entity with plusplus.

I've made a new entity, set its performance to static, I guss I'm just not sure much about what has changed in plusplus in reguards to collisions. The only work I've done with collisions so far in plus plus is by using utils addType but I'm not sure f that is viable in this situation (or the best method to go)

collinhover commented 10 years ago

The collides property of entities is basically the same. If you set an entity's performance to static or movable, it will ignore gravity. You can also set its gravity factor to 0 to achieve the same effect, but setting the performance gives the benefit of speeding up the update cycle of your game.

If you want only certain types of entities to collide, you can use types and groups. Types in ++ are just an extended version of impact's original types, which are A, B, and BOTH I think. With ++ you can define up to 29 more, to help create complex interactions. Don't forget, types are bitwise flags so they can be combined using bitwise operators.

Pattentrick commented 10 years ago

Hey @Ralliare,

@collinhover already explained everything important. But just in case that you need an example on how to check for collision here is a quick coin example:

javascript // ... in your coin.js

initTypes: function() {

this.parent();

_ut.addType(ig.EntityExtended, this, 'type', "COLLECTABLE");

}

// ... in your player.js

initTypes: function() {

this.parent();

_ut.addType(ig.EntityExtended, this, 'checkAgainst', "COLLECTABLE");

}

check: function( entity ) {

this.collectCollectable();  

}



`_ut` is a reference to the `ig.utils`. So make sure that you have a `var _ut = ig.utils;` defined in your class. In the example above i made up a new type called `COLLECTABLE` that all entities will have that are in some way collectable by the player (coins, powerups, fruit ... ). The player will check for collectables on collision. The `collectCollectable` method is just a example. Add your own game logic there.

You can of course check for the type in the `check` at any time via `entity.type`. Hope that helps you.