纯代码实现小飞机游戏界面框架
//
// ViewController.m
// 01-playPlane
//
// Created by 王 on 16/4/9.
// Copyright © 2016年 王. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setupUi];
// Do any additional setup after loading the view, typically from a nib.
}
//设置界面
- (void)setupUi{
//设置背景
UIImageView *backgroundPicture = [[UIImageView alloc]init];
//把背景设置好了
backgroundPicture.image = [UIImage imageNamed:@"background"];
//调整背景大小
backgroundPicture.frame = self.view.frame;
//添加到跟视图
[self.view addSubview:backgroundPicture];
//添加飞机
UIButton *plane = [[UIButton alloc]init];
//默认和高亮状态下的两张图片
UIImage *normal = [UIImage imageNamed:@"hero1"];
UIImage *highLight = [UIImage imageNamed:@"hero2"];
[plane setImage:normal forState:UIControlStateNormal];
[plane setImage:highLight forState:UIControlStateHighlighted];
//飞机按钮大小
[plane sizeToFit];
//飞机按钮位置
plane.center=self.view.center;
//添加到跟视图
[self.view addSubview:plane];
//添加方向按钮
CGFloat offset = 100;
[self addDirButtonWithImageName:@"top" offsetPoint:CGPointMake(0, -offset)];
[self addDirButtonWithImageName:@"left" offsetPoint:CGPointMake(-offset,0)];
[self addDirButtonWithImageName:@"right" offsetPoint:CGPointMake(offset, 0)];
[self addDirButtonWithImageName:@"bottom" offsetPoint:CGPointMake(0, offset)];
}
- (void)addDirButtonWithImageName:(NSString *)imageName offsetPoint:(CGPoint)offsetPoint{
//确定四个按钮中心点的位置
CGPoint center = CGPointMake(self.view.center.x, self.view.center.y+200);
//按钮的尺寸
CGFloat mySize = 40;
//确定按钮的frame
CGRect rect = CGRectMake(center.x-mySize*0.5, center.y-mySize*0.5, mySize, mySize);
UIButton *dirButton = [[UIButton alloc]init];
//
NSString *nName = [imageName stringByAppendingString:@"_normal"];
NSString *hName = [imageName stringByAppendingString:@"_highlighted"];
//
UIImage *normal = [UIImage imageNamed:nName];
UIImage *highLighted = [UIImage imageNamed:hName];
//
[dirButton setImage:normal forState:UIControlStateNormal];
[dirButton setImage:highLighted forState:UIControlStateHighlighted];
//位置
dirButton.frame = CGRectOffset(rect, offsetPoint.x, offsetPoint.y);
[self.view addSubview:dirButton];
}
@end
转载于:https://www.cnblogs.com/bywjb/p/5376758.html
- [cocos2d-x][游戏开发]通过cocos2d-x实现简易飞机大战 03.游戏界面 背景层实现滚动
- [cocos2d-x][游戏开发]通过cocos2d-x实现简易飞机大战 06.游戏界面 主角飞机产生子弹
- [cocos2d-x][游戏开发]通过cocos2d-x实现简易飞机大战 07.游戏界面 敌机的产生与移动
- [cocos2d-x][游戏开发]通过cocos2d-x实现简易飞机大战 04.游戏界面 主角飞机的添加
- [cocos2d-x][游戏开发]通过cocos2d-x实现简易飞机大战 08.游戏界面 碰撞检测
- [cocos2d-x][游戏开发]通过cocos2d-x实现简易飞机大战 09.游戏界面 道具
- [cocos2d-x][游戏开发]通过cocos2d-x实现简易飞机大战 05.游戏界面 主角飞机的移动
- [cocos2d-x][游戏开发]通过cocos2d-x实现简易飞机大战 10.游戏界面 特效
- [cocos2d-x][游戏开发]通过cocos2d-x实现简易飞机大战02 主界面创建
- libgdx游戏引擎开发笔记(九)SuperJumper游戏例子的讲解(篇三)---- 主游戏界面显示框架
- 常见游戏Loading界面的实现
- 我的游戏框架基础构建篇(A* 寻路算法实现 )
- 我的Android进阶之旅------>Android疯狂连连看游戏的实现之加载界面图片和实现游戏Activity(四)
- linux下使用C语言实现2048简易字符界面游戏
- iOS微信QQ聊天界面的UI框架以及Socket简单实现群聊功能
- 利用CEGUI+Lua实现灵活的游戏UI框架(转)
- 基于OGRE所实现的高层游戏引擎框架(3)
- 分享非常漂亮的WPF界面框架源码及其实现原理
- 【源码分享】WPF漂亮界面框架实现原理分析及源码分享
- [源码和文档分享]基于VC++和OpenCV实现的全民飞机大战游戏