1

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.

  1. set variable new_pos
  2. 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;
}
lincolnk
  • 11,218
  • 4
  • 40
  • 61
Bruno
  • 17
  • 4
  • Are you sure that the delay is being triggered immediatelly? Have you tried testing each part of your animation separately to make sure every piece is behaving like you believe it should? I believe when you, for example, create the actions `cc.MoveTo.create(1, cc.p(ship_pos.x + 25, -25)),` and later `cc.MoveTo.create(0, cc.p(ship_pos.x + 25, 610)),`, they may not be having the summatory effect thay you expect (secuence animations like this can be quite complex, I've had a few headaches myself with them). – Sebastián Vansteenkiste Jul 31 '14 at 19:28
  • Thank you for your time @Sebastian Vansteenkiste. If sprite is not shot by the defender, i.e. the sprite completes its flight, then it flys out of screen via the bottom cc.MoveTo.create(1, cc.p(ship_pos.x + 25, -25)). It then reappears out of screen at the top of the screen cc.MoveTo.create(1, cc.p(ship_pos.x + 25, 610)). It then flys back into position in the squadron. – Bruno Aug 02 '14 at 00:28

1 Answers1

0

I have solved this by (1) create a new sprite based on the enemy fighter that flys out of the squadron (2) hide the enemy fighter (3) show the new sprite (4) the new sprite acts as the enemy fighter (5) hide the sprite (6) display the enemy fighter

Thank you for your time @Sebastian Vansteenkiste. If sprite is not shot by the defender, i.e. the sprite completes its flight, then it flys out of screen via the bottom cc.MoveTo.create(1, cc.p(ship_pos.x + 25, -25)). It then reappears out of screen at the top of the screen cc.MoveTo.create(1, cc.p(ship_pos.x + 25, 610)). It then flys back into position in the squadron.

Bruno
  • 17
  • 4