Tom Cat Game Core Code IOS/OBJECTIVE-C

Source: Internet
Author: User

#import "ViewController.h"

@interface Viewcontroller ()

@property (Weak, nonatomic) Iboutlet Uiimageview *tomimageview;

@end

@implementation Viewcontroller

Knock on Tom's cat's head. Premise: A series of animations have been imported.

(ibaction) btnknockoutonclicked: (UIButton *) sender{

[Self tomimatewith:@ "KnockOut" imagecount:81];

}

Tom plays birds. Premise: The animation about the bird has been imported.

(ibaction) Eatonclick: (UIButton *) sender{

[self.tomimatewith:@ "Eat" iamgecout:40];

}

Animation Execution method

(void) Tonanimatewith: (NSString *) fileName Iamgecount:(Nsinteger) imagecout{

0. If you create picture data

if (self.tomImageView.isAnimating) {

Return

}

1. First create an array of images

Nsmutablearray *tomimages = [Nsmutablearray Arry];

for (int i=0;i<imagecout;i++) {

NSString *imagename = [NSString stringwithformat:@ "%1.jpg", FileName, I];

NSString *path = [[NSBundle mainbundle] Pathforresource:imagename Oftype:nil];

UIImage *image = [UIImage Imagewithcontentsoffile:path];

[Tomimages Addobject:image];

}

2 Setting up the animation process

2.1 Adding an animated array of images

[Self.tomimageview Setanimationimages:tomimages];

2.2 Setting the time for animation execution

[Self.tomimagesview setanimationduration:self.tomimageview.animationimages.cout*0.1];

2.3 Set the number of times the animation executes

[Self.tomimagesview setanimationrepeatcout:1];

2.4 Set Animation to start

[Self.tomimagesview startanimating];

3. Empty the array after animation technology

[Self perfomselector: @selector (setanimationimages) Withobject:nil afterDelay:self.tomImagesView.animationDuration ] ;

}

Tom Cat Game Core Code IOS/OBJECTIVE-C

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.