Tomcat Game DEMO

极客学院充值月度 VIP,学习 iOS 视频,感觉他们的知识体系图和实战路径图很不错,按照一个大纲去学习的。

今天按照视频指导:制作汤姆猫小游戏,完成以下 DEMO。

其中发现我写代码中遇到很多小问题,google 就有答案的。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//
// ViewController.m
// Tomcat Game DEMO
//
// Created by Will on 5/24/15.
// Copyright (c) 2015 gewill.org. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *tomImageView;

@end

@implementation ViewController



- (IBAction)touchHeadOnHead:(UIButton *)sender {
[self tomAnimateWith:@"knockout" imageCount:81];


}
- (IBAction)touchEat:(UIButton *)sender {
[self tomAnimateWith:@"eat" imageCount:40];
}
- (IBAction)touchPie:(UIButton *)sender {
[self tomAnimateWith:@"pie" imageCount:24];
}
- (IBAction)touchScratch:(UIButton *)sender {
[self tomAnimateWith:@"scratch" imageCount:56];
}
- (IBAction)TouchDrink:(UIButton *)sender {
[self tomAnimateWith:@"drink" imageCount:81];
}
- (IBAction)touchCymbal:(UIButton *)sender {
[self tomAnimateWith:@"symbal" imageCount:13];
}
- (IBAction)touchStomach:(UIButton *)sender {
[self tomAnimateWith:@"stomach" imageCount:34];

}
- (IBAction)touchFootLeft:(UIButton *)sender {
[self tomAnimateWith:@"footLeft" imageCount:30];
}
- (IBAction)touchFootRight:(UIButton *)sender {
[self tomAnimateWith:@"footRight" imageCount:30];
}
- (IBAction)touchAngry:(UIButton *)sender {
[self tomAnimateWith:@"angry" imageCount:26];
}

#pragma mark - 动画执行方法
- (void)tomAnimateWith:(NSString *)fileName imageCount:(NSInteger)imageCount{
// 0. 判断是否正在执行动画
if (self.tomImageView.isAnimating) {
return;
}

// 1. 创建图片数组
NSMutableArray *tomImages = [NSMutableArray array];

for (int i = 0; i < imageCount; i++) {
NSString *imageName = [NSString stringWithFormat:@"%@_%02d.jpg", fileName, i];
NSString *path =[[NSBundle mainBundle] pathForResource:imageName ofType:nil];
UIImage *image = [UIImage imageWithContentsOfFile:path];
[tomImages addObject:image ];
}

// 2. 设置动画过程
[self.tomImageView setAnimationImages:tomImages];
[self.tomImageView setAnimationDuration:self.tomImageView.animationImages.count * 0.1];
[self.tomImageView setAnimationRepeatCount:1];
[self.tomImageView startAnimating];

}



- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end