#在蓝懿学习iOS的日子#Day10今天做了一个大的游戏,涵盖了这段时间学洗的知识,页面的切换字符串,还有可变数组和遍历等知识点。
1、显示搭建视图添加背景,创建一个选择hero视图,添加一个button点击进入下一个选择hero视图;
2、在hero视图搭建视图添加背景,创建一个英雄hero类,把不同的英雄j连接进同一个button,设置tag用以区分hero类;在点击button进入游戏页面,
3、在游戏页面添加移动的背景视图,
-(void)initBG{
//添加背景图片
self.bgIV1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
//第二张图片放在第一张的上面,y:-self.view.frame.size.height
self.bgIV2 = [[UIImageView alloc]initWithFrame:CGRectMake(0, -self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height)];
self.bgIV1.image = [UIImage imageNamed:@"img_bg_level_1.jpg"];
self.bgIV2.image = [UIImage imageNamed:@"img_bg_level_1.jpg"];
//插入子控件到某个位置,把背景图片放最下边
[self.view insertSubview:self.bgIV1 atIndex:0];
[self.view insertSubview:self.bgIV2 atIndex:0];
//给 背景的移动设置TImer
[NSTimer scheduledTimerWithTimeInterval:1.0/60 target:self selector:@selector(moveBG) userInfo:nil repeats:YES];
}
-(void)moveBG{
//设置图片往下移动y+1
self.bgIV1.center = CGPointMake(self.bgIV1.center.x, self.bgIV1.center.y+1);
self.bgIV2.center = CGPointMake(self.bgIV2.center.x, self.bgIV2.center.y+1);
//两张图片的衔接
if (self.bgIV1.center.y>=self.view.frame.size.height*1.5) {
self.bgIV1.center = CGPointMake(self.bgIV1.center.x, -self.view.frame.size.height/2);
}
if (self.bgIV2.center.y>=self.view.frame.size.height*1.5) {
self.bgIV2.center = CGPointMake(self.bgIV2.center.x, -self.view.frame.size.height/2);
}