I have a 'water' entity:
ig.module('game.entities.water')
.requires(
'impact.entity'
)
.defines(function() {
EntityWater = ig.Entity.extend({
_wmDrawBox: true,
_wmScalable: true,
_wmBoxColor: 'rgba(0,0,0,0.5)',
});
});
And a player entity
ig.module('game.entities.player')
.requires(
'impact.entity',
'game.entities.water'
)
.defines(function() {
EntityPlayer = ig.Entity.extend({
//...
update: function() {
var water = ig.game.getEntitiesByType(EntityWater);
water = water[0];
if (this.touches(water)) {
//doesn't work :\
}
}
});
});
Now when I move my character inside my water entity, it won't register.
'touches' always returns false anyway.
Why?
1 decade ago
by Joncom
Have you tried enabling the 'impact.debug.debug'
module and checking "show collision boxes"? Might make it easier to confirm visually that the entities are indeed touching. Sometimes an entity may look like it is in one place, but the actual position is somewhere else...
I tried to check. It seems that very large entities do not get a collision box. My water entity spanned 960px wide and 30 px tall.
I sized it down such that the entire water could be visibly drawn on the screen at once and now it works.
I suppose I need to split my water up in chunks?
1 decade ago
by Joncom
I&039;m not sure why size would make a difference. As far as I know your entities should be capable of any size and still retain #.touches
functionality...
Hm. strange. Well, I fixed that easily for now by simply sizing them down and using multiple 'water' entities.
I agree with Joncom, size does not make a difference. The touches
method is only a bounding box intersection test, so whether or not it is bigger than the screen should not matter. I suspect there is something else going on, and that splitting the entity into multiple smaller entities is just fixing the symptom instead of the source.
1 decade ago
by dominic
Indeed, the size of the Entity shouldn&039;t be an issue for #.touches()
.
I suspect that your ig.game.getEntitiesByType(EntityWater);
went wrong somehow. Maybe you had multiple water entities in the level and water[0]
was always the wrong one?
Dominic brings up a good point, to which I&039;d add: don't use #getEntitiesByType
at all. One way of doing it that doesn&039;t need the #touches
and doesn&039;t care which water entity you're intersecting would be using the #checkAgainst
and type
properties and the check
method.
For example: have the player checkAgainst
the type
of entity (not class) that the water entity is. Then in the check
method of the player (which is called automatically on two touching entities when one checks against the other), set a property such as inWater
based on whether the other entity (first argument passed to the check
method) is a water entity. And at the end of the player&039;s #update
, always set the inWater
property to false, because the check
method gets called after the update and will set the property back to true if the player is in the water.
Page 1 of 1
« first
« previous
next ›
last »