美文网首页
对于汤姆猫游戏构建的方法

对于汤姆猫游戏构建的方法

作者: 围篱亦海庄 | 来源:发表于2016-07-12 15:42 被阅读0次

       对于OS系统中汤姆猫游戏App的构造可以使用两种方法;其一、是按照步骤对代码一个一个的敲出来并使用,然而其过程耗费的时间过长并且程序的语句过多,错误发生时不宜修改;其二、构建以新的函数,将多个按钮的相同语句编写到该函数中,将其要改变得数据进行定义,在分别在个按钮中更改函数的参数和调用函数。

方法一:

#import "ViewController.h"

@interface ViewController ( )

@property (weak, nonatomic) IBOutlet UIImageView  *tomCatView;

@end

@implementation ViewController

/*

*/

- (void)viewDidLoad {

[super viewDidLoad];

//    序列帧都动画要播放的图片数组

//    imageView.animationImages

//    动画时长

//    imageView.animationDuration

//    动画重复次数

//    imageView.animationRepeatCount

//    开始动画

//    [imageView startAnimating]

//    结束动画

//    [imageView stopAnimating]

//    是否正在执行动画

//    [imageView isAnimating]

}

- (IBAction)eatBirdAction:(UIButton *)sender {

//    使用函数的方法对按钮图片的启用

[self tomCatAnimationWithName:@"eat" withCount:40];

/*

//  设置一个可变数组,负责存放播放的图片数组

NSMutableArray *images = [NSMutableArray array];

//  利用for循环确定图片名添加图片

for (NSInteger i = 0; i<40 ; i++) {

//    根据i来加载图片,然后添加到可变数组images里面

NSString *imageNamed = [NSString stringWithFormat:@"eat_%02ld.jpg",i];

//  根据格式化的图片名加载图片image

UIImage *image = [UIImage imageNamed:imageNamed];

//    将图片image添加到数组images中

[images addObject:image];

}

//设置一个动画数组

self.tomCatView.animationImages = images;

//设置动画时长

self.tomCatView.animationDuration = 40*0.075;

//    设置播放次数

self.tomCatView.animationRepeatCount = 1;

//    开始动画

[self.tomCatView startAnimating];

*/}

-(void)tomCatAnimationWithName:(NSString *)name withCount:(NSInteger)count

{    if([self.tomCatView isAnimating]){

return;}

//  设置一个可变数组,负责存放播放的图片数组

NSMutableArray *images = [NSMutableArray array];

//  利用for循环确定图片名添加图片

for (NSInteger i = 0; i< count; i++) {

//    根据i来加载图片,然后添加到可变数组images里面

NSString *imageNamed = [NSString stringWithFormat:@"%@_%02ld.jpg",name,i];

//  根据格式化的图片名加载图片image

UIImage *image = [UIImage imageNamed:imageNamed];

//    将图片image添加到数组images中

[images addObject:image];

}

//设置一个动画数组

self.tomCatView.animationImages = images;

//设置动画时长

self.tomCatView.animationDuration = count*0.075;

//    设置播放次数

self.tomCatView.animationRepeatCount = 1;

//    开始动画

[self.tomCatView startAnimating];

}

- (IBAction)fart:(UIButton *)sender {

//    使用函数的方法对按钮图片的启用

[self tomCatAnimationWithName:@"fart" withCount:28];

/*

// 设置一个可变数组,负责存放播放的图片数组

NSMutableArray *images = [NSMutableArray array];

//利用for循环确定图片名添加图片

for (NSInteger i = 0; i< 28 ; i++) {

//        根据i来加载图片,然后添加到可变数组images里面

NSString *imageNamed = [NSString stringWithFormat:@"fart_%02ld.jpg",i];

//  根据格式化的图片名加载图片image

UIImage *image = [UIImage imageNamed:imageNamed];

//    将图片image添加到数组images中

[images addObject:image];

}

//设置一个动画数组

self.tomCatView.animationImages = images;

//设置动画时长

self.tomCatView.animationDuration = 28*0.085;

//    设置播放次数

self.tomCatView.animationRepeatCount = 1;

//    开始动画

[self.tomCatView startAnimating];

*/

}

- (IBAction)cymbal:(UIButton *)sender {

//    使用函数的方法对按钮图片的启用

[self tomCatAnimationWithName:@"cymbal" withCount:13];

/*

// 设置一个可变数组,负责存放播放的图片数组

NSMutableArray *images = [NSMutableArray array];

//利用for循环确定图片名添加图片

for (NSInteger i = 0; i< 13; i++) {

//        根据i来加载图片,然后添加到可变数组images里面

NSString *imageNamed = [NSString stringWithFormat:@"cymbal_%02ld.jpg",i];

//  根据格式化的图片名加载图片image

UIImage *image = [UIImage imageNamed:imageNamed];

//    将图片image添加到数组images中

[images addObject:image];

}

//设置一个动画数组

self.tomCatView.animationImages = images;

//设置动画时长

self.tomCatView.animationDuration = 13*0.075;

//    设置播放次数

self.tomCatView.animationRepeatCount = 1;

//    开始动画

[self.tomCatView startAnimating];

*/

}

- (IBAction)pie:(UIButton *)sender {

//    使用函数的方法对按钮图片的启用

[self tomCatAnimationWithName:@"pie" withCount:24];

/*

// 设置一个可变数组,负责存放播放的图片数组

NSMutableArray *images = [NSMutableArray array];

//利用for循环确定图片名添加图片

for (NSInteger i = 0; i< 24  ; i++) {

//        根据i来加载图片,然后添加到可变数组images里面

NSString *imageNamed = [NSString stringWithFormat:@"pie_%02ld.jpg",i];

//  根据格式化的图片名加载图片image

UIImage *image = [UIImage imageNamed:imageNamed];

//    将图片image添加到数组images中

[images addObject:image];

}

//设置一个动画数组

self.tomCatView.animationImages = images;

//设置动画时长

self.tomCatView.animationDuration = 24*0.075;

//    设置播放次数

self.tomCatView.animationRepeatCount = 1;

//    开始动画

[self.tomCatView startAnimating];

*/

}

- (IBAction)scratch:(UIButton *)sender {

//    使用函数的方法对按钮图片的启用

[self tomCatAnimationWithName:@"scratch" withCount:56];

/*

// 设置一个可变数组,负责存放播放的图片数组

NSMutableArray *images = [NSMutableArray array];

//利用for循环确定图片名添加图片

for (NSInteger i = 0; i< 56 ; i++) {

//        根据i来加载图片,然后添加到可变数组images里面

NSString *imageNamed = [NSString stringWithFormat:@"scratch_%02ld.jpg",i];

//  根据格式化的图片名加载图片image

UIImage *image = [UIImage imageNamed:imageNamed];

//    将图片image添加到数组images中

[images addObject:image];

}

//设置一个动画数组

self.tomCatView.animationImages = images;

//设置动画时长

self.tomCatView.animationDuration = 56*0.075;

//    设置播放次数

self.tomCatView.animationRepeatCount = 1;

//    开始动画

[self.tomCatView startAnimating];

*/

}

- (IBAction)drink:(UIButton *)sender {

//    使用函数的方法对按钮图片的启用

[self tomCatAnimationWithName:@"drink" withCount:81];

/*

//    设置一个可变数组,负责存放播放的图片数组

NSMutableArray *images = [NSMutableArray array];

//    利用for循环确定图片名添加图片

for (NSInteger i = 0; i< 81 ; i++) {

//    根据i来加载图片,然后添加到可变数组images里面

NSString *imageNamed = [NSString stringWithFormat:@"drink_%02ld.jpg",i];

//    根据格式化的图片名加载图片image

UIImage *image = [UIImage imageNamed:imageNamed];

//    将图片image添加到数组images中

[images addObject:image];

}

//    设置一个动画数组

self.tomCatView.animationImages = images;

//    设置动画时长

self.tomCatView.animationDuration = 81*0.075;

//    设置播放次数

self.tomCatView.animationRepeatCount = 1;

//    开始动画

[self.tomCatView startAnimating];

*/

}

- (IBAction)footleft:(UIButton *)sender {

//    使用函数的方法对按钮图片的启用

[self tomCatAnimationWithName:@"footLeft" withCount:30];

/*

//    设置一个可变数组,负责存放播放的图片数组

NSMutableArray *images = [NSMutableArray array];

//    利用for循环确定图片名添加图片

for (NSInteger i = 0; i< 30 ; i++) {

//    根据i来加载图片,然后添加到可变数组images里面

NSString *imageNamed = [NSString stringWithFormat:@"footLeft_%02ld.jpg",i];

//    根据格式化的图片名加载图片image

UIImage *image = [UIImage imageNamed:imageNamed];

//    将图片image添加到数组images中

[images addObject:image];

}

//    设置一个动画数组

self.tomCatView.animationImages = images;

//    设置动画时长

self.tomCatView.animationDuration = 30*0.075;

//    设置播放次数

self.tomCatView.animationRepeatCount = 1;

//    开始动画

[self.tomCatView startAnimating];

*/

}

- (IBAction)footright:(UIButton *)sender {

//    使用函数的方法对按钮图片的启用

[self tomCatAnimationWithName:@"footRight" withCount:30];

/*

//    设置一个可变数组,负责存放播放的图片数组

NSMutableArray *images = [NSMutableArray array];

//    利用for循环确定图片名添加图片

for (NSInteger i = 0; i< 30 ; i++) {

//    根据i来加载图片,然后添加到可变数组images里面

NSString *imageNamed = [NSString stringWithFormat:@"footRight_%02ld.jpg",i];

//    根据格式化的图片名加载图片image

UIImage *image = [UIImage imageNamed:imageNamed];

//    将图片image添加到数组images中

[images addObject:image];

}

//    设置一个动画数组

self.tomCatView.animationImages = images;

//    设置动画时长

self.tomCatView.animationDuration = 30*0.075;

//    设置播放次数

self.tomCatView.animationRepeatCount = 1;

//    开始动画

[self.tomCatView startAnimating];

*/

}

- (IBAction)stomach:(UIButton *)sender {

//    使用函数的方法对按钮图片的启用

[self tomCatAnimationWithName:@"stomach" withCount:34];

/*

//    设置一个可变数组,负责存放播放的图片数组

NSMutableArray *images = [NSMutableArray array];

//    利用for循环确定图片名添加图片

for (NSInteger i = 0; i< 34 ; i++) {

//    根据i来加载图片,然后添加到可变数组images里面

NSString *imageNamed = [NSString stringWithFormat:@"stomach_%02ld.jpg",i];

//    根据格式化的图片名加载图片image

UIImage *image = [UIImage imageNamed:imageNamed];

//    将图片image添加到数组images中

[images addObject:image];

}

//    设置一个动画数组

self.tomCatView.animationImages = images;

//    设置动画时长

self.tomCatView.animationDuration = 34*0.075;

//    设置播放次数

self.tomCatView.animationRepeatCount = 1;

//    开始动画

[self.tomCatView startAnimating];

*/

}

- (IBAction)knockcut:(UIButton *)sender {

//    使用函数的方法对按钮图片的启用

[self tomCatAnimationWithName:@"knockout" withCount:81];

/*

//    设置一个可变数组,负责存放播放的图片数组

NSMutableArray *images = [NSMutableArray array];

//    利用for循环确定图片名添加图片

for (NSInteger i = 0; i< 81 ; i++) {

//    根据i来加载图片,然后添加到可变数组images里面

NSString *imageNamed = [NSString stringWithFormat:@"knockout_%02ld.jpg",i];

//    根据格式化的图片名加载图片image

UIImage *image = [UIImage imageNamed:imageNamed];

//    将图片image添加到数组images中

[images addObject:image];

}

//    设置一个动画数组

self.tomCatView.animationImages = images;

//    设置动画时长

self.tomCatView.animationDuration = 81*0.075;

//    设置播放次数

self.tomCatView.animationRepeatCount = 1;

//    开始动画

[self.tomCatView startAnimating];

*/

}

- (IBAction)Angry:(UIButton *)sender {

//    使用函数的方法对按钮图片的启用

[self tomCatAnimationWithName:@"Angry" withCount:26];

/*

//    设置一个可变数组,负责存放播放的图片数组

NSMutableArray *images = [NSMutableArray array];

//    利用for循环确定图片名添加图片

for (NSInteger i = 0; i< 26 ; i++) {

//    根据i来加载图片,然后添加到可变数组images里面

NSString *imageNamed = [NSString stringWithFormat:@"Angry_%02ld.jpg",i];

//    根据格式化的图片名加载图片image

UIImage *image = [UIImage imageNamed:imageNamed];

//    将图片image添加到数组images中

[images addObject:image];

}

//    设置一个动画数组

self.tomCatView.animationImages = images;

//    设置动画时长

self.tomCatView.animationDuration = 26*0.075;

//    设置播放次数

self.tomCatView.animationRepeatCount = 1;

//    开始动画

[self.tomCatView startAnimating];

*/

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

@end

方法二:

#import "ViewController.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *tomCatView;

@end

@implementation ViewController

/*

*/

- (void)viewDidLoad {

[super viewDidLoad];

//    序列帧都动画要播放的图片数组

//    imageView.animationImages

//    动画时长

//    imageView.animationDuration

//    动画重复次数

//    imageView.animationRepeatCount

//    开始动画

//    [imageView startAnimating]

//    结束动画

//    [imageView stopAnimating]

//    是否正在执行动画

//    [imageView isAnimating]

}

- (IBAction)eatBirdAction:(UIButton *)sender {

//    使用函数的方法对按钮图片的启用

[self tomCatAnimationWithName:@"eat" withCount:40];

}

-(void)tomCatAnimationWithName:(NSString *)name withCount:(NSInteger)count

{    if([self.tomCatView isAnimating]){

return;}

//  设置一个可变数组,负责存放播放的图片数组

NSMutableArray *images = [NSMutableArray array];

//  利用for循环确定图片名添加图片

for (NSInteger i = 0; i< count; i++) {

//    根据i来加载图片,然后添加到可变数组images里面

NSString *imageNamed = [NSString stringWithFormat:@"%@_%02ld.jpg",name,i];

//  根据格式化的图片名加载图片image

UIImage *image = [UIImage imageNamed:imageNamed];

//    将图片image添加到数组images中

[images addObject:image];

}

//设置一个动画数组

self.tomCatView.animationImages = images;

//设置动画时长

self.tomCatView.animationDuration = count*0.075;

//    设置播放次数

self.tomCatView.animationRepeatCount = 1;

//    开始动画

[self.tomCatView startAnimating];

}

- (IBAction)fart:(UIButton *)sender {

//    使用函数的方法对按钮图片的启用

[self tomCatAnimationWithName:@"fart" withCount:28];

}

- (IBAction)cymbal:(UIButton *)sender {

//    使用函数的方法对按钮图片的启用

[self tomCatAnimationWithName:@"cymbal" withCount:13];

}

- (IBAction)pie:(UIButton *)sender {

//    使用函数的方法对按钮图片的启用

[self tomCatAnimationWithName:@"pie" withCount:24];

}

- (IBAction)scratch:(UIButton *)sender {

//    使用函数的方法对按钮图片的启用

[self tomCatAnimationWithName:@"scratch" withCount:56];

}

- (IBAction)drink:(UIButton *)sender {

//    使用函数的方法对按钮图片的启用

[self tomCatAnimationWithName:@"drink" withCount:81];

}

- (IBAction)footleft:(UIButton *)sender {

//    使用函数的方法对按钮图片的启用

[self tomCatAnimationWithName:@"footLeft" withCount:30];

}

- (IBAction)footright:(UIButton *)sender {

//    使用函数的方法对按钮图片的启用

[self tomCatAnimationWithName:@"footRight" withCount:30];

}

- (IBAction)stomach:(UIButton *)sender {

//    使用函数的方法对按钮图片的启用

[self tomCatAnimationWithName:@"stomach" withCount:34];

}

- (IBAction)knockcut:(UIButton *)sender {

//    使用函数的方法对按钮图片的启用

[self tomCatAnimationWithName:@"knockout" withCount:81];

}

- (IBAction)Angry:(UIButton *)sender {

//    使用函数的方法对按钮图片的启用

[self tomCatAnimationWithName:@"Angry" withCount:26];

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

@end

相关文章

  • 对于汤姆猫游戏构建的方法

    对于OS系统中汤姆猫游戏App的构造可以使用两种方法;其一、是按照步骤对代码一个一个的敲出来并使用,然而其过...

  • 《猫和老鼠》游戏为什么越来越不好玩

    1. “汤姆怎么这么厉害?血太多了,根本打不死嘛。” 老公又在抱怨《猫和老鼠》游戏里的汤姆猫。的确,汤姆猫血很厚,...

  • IOS-汤姆猫实例

    ++2016/7/12++by side @OC-汤姆猫实例 相信大家或多或少都玩过汤姆猫这个有趣的小游戏 ===...

  • 汤姆猫小游戏

    // Copyright©2016年lanou. All rights reserved. #import"Vie...

  • Day20

    今天遇到难题了,目前无解。 前几天应灰灰要求给他下载了《汤姆猫跑酷》的游戏,现在又换成了《汤姆猫英雄跑酷》,着迷到...

  • Day25 | 想抱怨时去找汤姆猫

    儿子最近迷恋上会说话的汤姆猫,还学会了主动抱着平板找我们给他打开游戏界面,咿咿呀呀的和汤姆猫玩的不亦乐乎。受他启发...

  • 20181201 汤姆猫跑酷

    汤姆猫跑酷是一款游戏,在游戏里面,你可以选择一种猫或者狗,在游戏的场景里进行跑酷。 我现在有三只猫和一条狗,三只猫...

  • Day17

    我在包馄饨的时候,灰灰因为屏幕时间已用完,而《汤姆猫跑酷》这个游戏还没玩够而在我旁边不停地大喊:我要玩《汤姆猫跑酷...

  • 美国人的恶趣味:花350元在地牢里和老鼠一起喝咖啡 实在是猜不

    ​ 汤姆都可以,凭什么杰瑞不行?——吱星人 对于爱猫却又没猫的的人来说 整天云吸猫已经满足不了他们对于猫的渴望了 ...

  • 123跑酷飞天贺新年《汤姆猫跑酷》新春版今日上线

    跑酷跨新年,喵将军助你一飞冲天!由“会说话的汤姆猫”原班团队开发,多酷游戏代理发行的休闲跑酷手游《汤姆猫跑酷》安卓...

网友评论

      本文标题:对于汤姆猫游戏构建的方法

      本文链接:https://www.haomeiwen.com/subject/dbfsjttx.html