O'Reilly logo

Sparrow iOS Game Framework Beginner's Guide by Johannes Stein

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – updating the movement

To update the movement of our ship, follow these steps:

  1. Inside the initializer, add a tween for the enemy ship. We want the enemy ship to move on its own. We should also rename the ship instance to enemyShip:
    SPImage *enemyShip = [SPImage imageWithTexture:[Assets texture:@"ship.png"]];
    enemyShip.x = 100;
    enemyShip.y = 100;
    
    SPTween *shipTween = [SPTween tweenWithTarget:enemyShip time:4.0f transition:SP_TRANSITION_EASE_IN_OUT];
    [shipTween animateProperty:@"y" targetValue:250];
    shipTween.repeatCount = 5;
    shipTween.reverse = YES;
    shipTween.delay = 2.0f;
    
    [Sparrow.juggler addObject:shipTween];
    
  2. Update the onBackgroundTouch method to resemble the following piece of code:
    SPTouch *touch = [[event touchesWithTarget:self] ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required