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 – manipulating display objects

Perform the following steps to manipulate the display objects we created earlier:

  1. Add a new method to Game.m below the init method we used to create the body parts:
    - (void)onLegTouch:(SPTouchEvent *)event
    {
      SPTouch *touch = [[event touchesWithTarget:self andPhase:SPTouchPhaseBegan] anyObject];
      if (touch) {
        SPQuad* target = (SPQuad *) event.target;
        
        float currentRotation = SP_R2D(target.rotation);
        currentRoration = currentRotation + 10;
        
        if (currentRotation >= 360.0)
        {
          currentRotation = currentRotation - 360.0;
        }
        target.rotation = SP_D2R(currentRotation);
      }
    }
  2. Next, we'll need to set the anchor (pivot) of our legs in the initializer, as shown in the following code:
    leftLeg.pivotX = 25; leftLeg.pivotY = 10; ...

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