(No. 00004) implementing the brick-hitting game for iOS (6): rebound Rod
Another element of the brick-hitting game is the rebound rod. In this class, we will implement the rebound rod class.
Create a bounce stick header file
Create a Stick class in Xcode and add the following content to the header file:
#import CCSprite.h@interface Stick : CCSprite+(instancetype)stickNormal;-(void)moveStickTo:(CGPoint)location;@end
The items that make the rebound rod longer or shorter later, so here we first add a method to create a normal rebound rod, and finally add a method to move the rebound rod.
Implementation of rebound Rods
The implementation of the bounce stick class is very simple. We implement the above two methods according to the definition of the header file:
+ (Instancetype) stickNormal {Stick * stick = (Stick *) [CCBReader load: @ Elements/Stick]; stick. name = @ stick; return stick;}-(void) moveStickTo :( CGPoint) location {CGPoint orgPos = self. position; location. y = orgPos. y; // restrict the movement of the bounce rod to the screen if (location. x <0) {location. x = 0;} else if (location. x> _ viewSize. width) {location. x = _ viewSize. width;} self. position = location ;}
Because the physical object type of the bounce rod is a mixture (neither dynamic nor static), we can manually move it as needed.