IOS learning 04 Tom development, ios04

Source: Internet
Author: User

IOS learning 04 Tom development, ios04

IOS development, a simple Tom development, is as follows:

1.1 I used to think this little game was good and fun. Now I learned about IOS and found that this program is really simple. In fact, this is not complete yet, and there is no sound. I will try it again later.

1.2 create a project, Import images, and save the PNG Image in the project images. xcassets. Here, only six key images are saved. You can directly pull the image file, for example:

 

1.3 I believe most people have played this game. In fact, this is an animation, and the animation is played together by multiple images. It finally looks like an animation.

1.4 if you understand the animation principle, you can easily import the animation group images corresponding to the buttons. These images are not saved in images. xcassets,

We now save all the Files in the project Supporting Files. Just pull in the image culture like above, for example:

This Animations folder contains the images used for animation. The folder contains many subfolders,

Here, each subfolder has an animation to be operated by a button event on the interface, for example:

There are 81 images in the Angry folder in 1.5. Playing the images in this folder together is an animation of Tom falling to the ground. The same applies to other folders.

2.1 After the project is created and the image is loaded, design the interface. Put a UIimage on the interface to fill up the screen, set the image attribute, and find an image starting with Tom in the project.

Then, we put 11 buttons on the interface for 11 animation events, put a transparent Button on the head, and a transparent Button under the belly, and two transparent buttons on both sides, A transparent Button is placed on the tail, and each of the six visible animation buttons sets the corresponding image attribute. The transparent Button is invisible here, as shown in the interface.

3.1 There are no multiple settings on the interface. After the interface design is complete, create 11 click events corresponding to 11 buttons on the page, and then create a UIimage attribute, as shown below.

# Import "ViewController. h "@ interface ViewController () // nod event-(IBAction) Kuockout; // click the stomach event-(IBAction) stomach; // click the left-foot event-(IBAction) footLeft; // click the right-foot event-(IBAction) footRight; // click the tail event-(IBAction) angry; // click the labala event-(IBAction) cambal; // milk drinking event-(IBAction) drink; // point bird event-(IBAction) eat; // fart event-(IBAction) fart; // (IBAction) pie; // capture sub-events-(IBAction) csrotch; // interface image attributes @ property (weak, nonatomic) IBOutlet UIImageView * tom; @ endView Code

3.2 connect the corresponding events to the buttons corresponding to the interface. After these operations are completed, we have to think about how to write the animation Event code?

3.3 As we mentioned above, each animation is made up of a group of images that can be played together, the first is to find the image group corresponding to each event.

3.4 then, put the image group in the UIimage of the screen and let him play the video. OK. Of course, if you have a good idea, you can implement the code, here we can encapsulate a method for playing an animation. The method is as follows. Here we will explain the implementation code and each line of code, so we will not talk about it here.

1 // load the animation method. There are two parameters. The first one will input the image file name, and the second one will input the number of animated images 2-(void) animationWithImgName :( NSString *) imgName imgCount :( int) imgCount 3 {4 // determine whether the animation has been played completely. If not, the next animation will not be played. 5 if (self. tom. isAnimating) return; 6 7 // define a dynamic array to save the loaded Animated Image 8 NSMutableArray * animationImages = [NSMutableArray array]; 9 10 // loop the number of animation images to be played, and then add all the images to the dynamic array. 11 for (int I = 0; I 3.5 this method is used to input two parameters. The first parameter is the image file name, and the second parameter is the number of animated images, in this way, we can encapsulate the implementation of all the animation events on the interface into a method, which is simple for button events, as shown below.

1-(IBAction) Kuockout {2 3 [self animationWithImgName: @ "knockout" imgCount: 81]; 4} 5 6-(IBAction) stomach {7 [self animationWithImgName: @ "stomach" imgCount: 34]; 8} 9 10-(IBAction) footLeft {11 12 [self animationWithImgName: @ "footLeft" imgCount: 30]; 13 14} 15-(IBAction) footRight {16 [self animationWithImgName: @ "footRight" imgCount: 30]; 17} 18 19-(IBAction) angry {20 [self animationWithImgName: @ "angry" imgCount: 26]; 21 22} 23 24-(IBAction) cambal {25 26 [self animationWithImgName: @ "cymbal" imgCount: 13]; 27} 28 29-(IBAction) drink {30 31 [self animationWithImgName: @ "drink" imgCount: 81]; 32} 33 34-(IBAction) eat {35 36 [self animationWithImgName: @ "eat" imgCount: 40]; 37} 38 39-(IBAction) fart {40 41 [self animationWithImgName: @ "fart" imgCount: 28]; 42} 43 44-(IBAction) pie {45 46 [self animationWithImgName: @ "pie" imgCount: 24]; 47} 48 49-(IBAction) csrotch {50 51 [self animationWithImgName: @ "scratch" imgCount: 56]; 52}View Code

 

4.0 after the writing, we run the program and developed our Tom cat, for example:

Finally, upload your own code. Although the program is not very good, share the Internet spirit! : Http://pan.baidu.com/s/1i3L7INr

 

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.