Hello ,
I m stuck with swapping the entity .... is there anyway way to swap the entity when a collision occurs ...
Currently I tried approaching by running all the entities together and hide the entity which is not required and when collision occurs replace with hidden entity ... even that seems to not work cause i m unable to hide the entity ....
Please suggest how can I achieve this ..
Thanks
1 decade ago
by Arantor
In the entity's check() method, check that collision occurs as you want it to be, if it is, call ig.game.spawnEntity() for the new entity to replace it with, then call this.kill() to remove the entity you're getting rid of.
I'm not entirely sure why you're doing this, though...
Thnx Arantor ....
Actually i am doing a biker rally game .... In the game if the biker hits a obstacle then the biker riding entity would be replaced by biker falling entity after biker falling animation is over i need to replace back with biker riding entity.....
I could achieve this in a single sprite animation of an entity but this doesn't seem to work on mobile devices the latency issue comes to play ... rather than having a single entity comprising of all the sprite ... i thought it would be better i could swap the entity where ever required so the performance would be better on the mobile devices....
anyways Thanx for ur efforts in helping me out..... Previous thread suggestion provided by you worked pretty well .... I am pretty much new to this framework and gaming that's why i am struggling....Thanks for ur active support in the blog ... encouraging me to move forward :)
1 decade ago
by Arantor
I'm really not sure what performance benefit switching entities will give you, if anything it's probably going to make it worse, not better.
What kind of latency are you seeing exactly? Did you try using the debugger on a desktop environment to see what's causing the latency?
In desktop the performance is pretty good ... whereas the game is targeted for mobile devices especially iPhone 3GS .... when the player entity size crosses above 700 kb the latency issue comes to play ..... if compress the size it seems to work but graphics is distorted .... whereas we are targeting keep the graphics in good quality ....
I feel we can achieve this by splitting the player entity into multiple instances so the required instance would be called when ever required, by replacing the current entity instance... I am not sure whether i m right ... Please provide any valuable suggestions ... how to proceed from your side....
Meanwhile on the coding part ... I could spawn the biker falling entity where ever required and killed the instance of biker riding entity... But i need to biker riding entity even after killing the instance .... how do i do tht
check: function(other) {
if(other.name=='obstacle' )
{
//Set fall condition true
bikerFallFlag = true;
}
}
update: function() {
if(bikerFallFlag == true){
//Spawn the player fall entity
ig.game.spawnEntity( EntityPlayer_fall, this.pos.x ,this.pos.y );
player_riding.kill(); // Kill the riding player
var player_fallNew= ig.game.getEntitiesByType( EntityPlayer_fall )[0];
player_fallNew.currentAnim = player_fallNew.anims.run;
bikerFallFlag =false;
}
else if (bikerFallFlag == false)
{
ig.game.spawnEntity( EntityPlayer, this.pos.x +10 ,this.pos.y ); //spawn player ridin
player_fall.kill(); //kill the falling player
}
Please look out at the code i think i m doing wrong..
Thanks
1 decade ago
by Arantor
when the player entity size crosses above 700 kb the latency issue comes to play
Yes, I realise this. Using separate entities will solve one problem but give you another. Instead, use the right tool for the job, the correct approach here will be to use multiple Animations in the entity rather than a single massive sprite image.
That way, you have a single entity, with all its proper behaviours, in one place. The manual explains how to use Animations if you read up on ig.Animation, it's essentially doing what addAnim does, but manually because you need to indicate it for multiple images (so you define multiple animSheets inside the object and add the animations from those animSheets by hand)
Page 1 of 1
« first
« previous
next ›
last »