Closed Mmarzex closed 11 years ago
Entity updates are opt-in, with three levels based on the performance
property:
entity.performance = ig.CONFIG.STATIC
is the default and means the entity will never moveentity.performance = ig.CONFIG.MOVABLE
means the entity can move, but ignores gravity and the collision mapentity.performance = ig.CONFIG.DYNAMIC
means the entity can move, responds to gravity, and has full collisions.More info: http://collinhover.github.io/impactplusplus/ig.EntityExtended.html#performance
p.s. in the r6dev, instead of using ig.CONFIG.STATIC
, use ig.EntityExtended.PERFORMANCE.STATIC
I tried setting it to performance = ig.CONFIG.DYNAMIC and then setting checkingAgainst to ig.global.EntityPlayer and it appears to drop the entity from the spawner but then the bottom of the entity is below where the collision map is and the player can just walk right through it like it is a static image.
checkAgainst
, type
, and group
properties are all bitwise flags, so setting it to ig.global.EntityPlayer
will not work because that is a class. The short version is to do this in your collectable:
ig.EntityCollectable = ig.global.EntityCollectable = ig.EntityExtended.extend({
...
initTypes: function () {
this.parent();
ig.utils.addType( ig.EntityExtended, this, "checkAgainst", "PLAYER" );
}
...
});
Check out #65 and http://collinhover.github.io/impactplusplus/ig.utils.html#addType for examples on the type system.
As for your entity dropping below or into the collision map, does it have an offset? If not, can you post an image showing this issue?
That's what it is looking like. The entity has no offset. So I add a Type for checkAgainst in my Collectable do I have to add a "PLAYER" type to my actual player?
If your player entity is extending ig.Player
abstract, it automatically adds the PLAYER type in the player's initTypes
method. And ig.Player
extends ig.Character
, which itself adds the CHARACTER type in its own initTypes
method.
Can you turn on debug collision boxes and post the same screen shot please?
Here it is, and for reference here is the code I'm using for it.
/**
* Created by maxmarze on 10/9/13.
*/
ig.module(
'game.entities.test-item'
)
.requires(
'plusplus.core.entity',
'plusplus.core.config',
'game.entities.player'
)
.defines(function(){
ig.EntityTestItem = ig.global.EntityTestItem = ig.EntityExtended.extend({
animSheet: new ig.AnimationSheet('media/re/im_1.PNG', 32, 32),
animSettings: {
idle: {
frameTime: 1,
sequence: [0]
}
},
performance: ig.CONFIG.DYNAMIC,
checkAgainst: ig.global.EntityPlayer,
initProperties: function() {
this.parent();
this.currentAnim = this.animSettings.idle;
},
update: function() {
this.parent();
}
});
});
Oh, simple fix! The size
property of your test-item is too small. Notice how the apple has a box around 1/4 of the image?
That is because your animation sheet is 32x32:
animSheet: new ig.AnimationSheet('media/re/im_1.PNG', 32, 32)
and you haven't set a size, so the default is 16x16. You need to add:
size: {x:32,y:32}
p.s. your check against in the test-item is still wrong, make sure you use the initTypes
method in my earlier reply.
The size fixed it, I guess I assumed it set the size based on the image. I changed it and used initTypes, am I doing it right now?
ig.EntityTestItem = ig.global.EntityTestItem = ig.EntityExtended.extend({
animSheet: new ig.AnimationSheet('media/re/im_1.PNG', 32, 32),
animSettings: {
idle: {
frameTime: 1,
sequence: [0]
}
},
size: {x:32,y:32},
//collides: ig.EntityExtended.GROUP.ANY
performance: ig.CONFIG.DYNAMIC,
initTypes: function() {
this.parent();
ig.utils.addType(ig.EntityExtended, this, "checkAgainst", "PLAYER");
},
checkAgainst: ig.EntityPlayer.TYPE,
initProperties: function() {
this.parent();
this.currentAnim = this.animSettings.idle;
//this.performance = ig.CONFIG.DYNAMIC;
//this.collidingWithMap = true;
//this.gravityFactor = 1;
},
update: function() {
this.parent();
},
check: function() {
ig.log('HITTTTT');
}
});
Looks correct, is it getting you the collision and checks you expect?
No the check isn't working, Do I have to put something in my Player entity? I don't see the log output when I overlap the item.
Remove the line:
checkAgainst: ig.EntityPlayer.TYPE,
from your test item. You're already adding the player type in the initTypes
method, and the above line is going to cause errors.
That fixed it, Thanks! I have more of a design question involving this now I guess. I'm spawning the Collectable with a spawner similar to the spawnerLibraried you used in the Collider demo. How would I go about killing the collectable when it is checked against the player so that the spawner count and everything resets?
Anything spawned from a spawner is managed by that spawner, so you can just kill the collectable and the spawner will return it to the pool and subtract one from the spawn counts. If you need to fully reset the spawner, just call its deactivate method, but note that this also unspawns all spawned entities as well. If you need to auto respawn things, set the respawnDelay in the spawner. You can check out all the options in the docs.
I am trying to just make a collectable such as a coin using a basic EntityExtended entity but I am a little curious as to how to get physics to work. If my spawner is spawning this collectable enity and I set the gravity to 1 for the entity shouldn't it fall? It doesn't though it just stays in the 'air' where my spawner target is.