OK think Space Invaders and Galaga. I have an enemy squadron at the top of the screen. They move left and right and down the screen as a group. Every now and then an enemy fighter leaves the group and attack's the player's ship. does a few bezier curves, attempts to attack the player's ship. If the enemy fighter misses he (1) fly off the bottom of the screen, hides, moves to the top of the screen, appears and flys back into its position in the squadron. The problem is the enemy fighter flys back into the position where it left the squadron not where its current position should be.
- set variable new_pos
- call action function with delay to handle the bezier flight paths e.g.
action ((bezier), (delay 5 seconds), (hide enemy fighter), (delay 1 second), (move enemy fighter to top of screen), (display enemy fighter), (callfunc to get the enemy fighter's new position in the squadron), (bezier back to new position)
CallFunc seems to get called as soon as the parent function is called. Not after the delay. Is what I am expecting possible?
var epos = 0;
if (enemy_fly_out_from == 0)
this.runAction(cc.Sequence.create(cc.DelayTime.create(enemy_fly_out_duration), cc.CallFunc.create(this.reduce_flied_out, this), cc.MoveTo.create(1, cc.p(ship_pos.x-25, -25)), cc.Hide.create(), cc.MoveTo.create(0, cc.p(ship_pos.x-25, 610)), cc.Show.create(), cc.CallFunc.create(this.get_enemy_pos(which_enemy), this), cc.BezierTo.create(5, [cc.p(ship_pos.x-25, 600), cc.p(pos.x, 600), cc.p(epos.x,epos.y)]), cc.CallFunc.create(this.end_fly_out(which_enemy), this)));
else
this.runAction(cc.Sequence.create(cc.DelayTime.create(enemy_fly_out_duration), cc.CallFunc.create(this.reduce_flied_out, this), cc.MoveTo.create(1, cc.p(ship_pos.x+25, -25)), cc.Hide.create(), cc.MoveTo.create(0, cc.p(ship_pos.x+25, 610)), cc.Show.create(), cc.CallFunc.create(this.get_enemy_pos(which_enemy), this), cc.BezierTo.create(5, [cc.p(ship_pos.x+25, 600), cc.p(pos.x-100, 600), cc.p(epos.x, epos.y)]), cc.CallFunc.create(this.end_fly_out(which_enemy), this)));
},
end_fly_out:function(which_enemy)
{
enemies_array[which_enemy].flied_out = 0;
},
get_enemy_pos:function(which_enemy)
{
epos = enemies_array[which_enemy].getPosition();
},
reduce_flied_out:function()
{
enemies_flied_out = 0;
}