Time for action – manipulating display objects
Perform the following steps to manipulate the display objects we created earlier:
Add a new method to
Game.m
below theinit
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); } }
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;
Update the leg positions using the following code:
SPQuad *leftLeg = [SPQuad quadWithWidth:50 height:150 color:0x0000ff]; [legs addChild:leftLeg...