Book Image

Sparrow iOS Game Framework Beginner's Guide

By : Johannes Stein
Book Image

Sparrow iOS Game Framework Beginner's Guide

By: Johannes Stein

Overview of this book

Table of Contents (20 chapters)
Sparrow iOS Game Framework Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Afterword
Index

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;
            
    rightLeg.pivotX = 25;
    rightLeg.pivotY = 10;
  3. Update the leg positions using the following code:

    SPQuad *leftLeg = [SPQuad quadWithWidth:50 height:150 color:0x0000ff];
    [legs addChild:leftLeg...