(No. 00004) implementing the brick-hitting game for iOS (6): rebound Rod

Source: Internet
Author: User

(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.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.