当前位置:编程学习 > wap >>

cocos2d-iphone之魔塔20层第十部分

今天我们要在我们的主场景中添加两个重要的精灵,就是楼层传送和怪物查看。
首先我们要在Game01.h中添加:
//风之罗盘图标
    CCSprite *floorFly;
   //洞悉权杖图标
    CCSprite *predict;
然后在Game01.m的初始化方法中添加这两个精灵
//飞行器图标
CCTexture2D *Texture = [[CCTextureCachesharedTextureCache]addImage:@"item.png"];
CCSpriteFrame *fly = [CCSpriteFrameframeWithTexture:Texturerect:CGRectMake(2*32,8*32,32,32)];
floorFly = [CCSpritespriteWithSpriteFrame:fly];
floorFly.scale =2.0;
floorFly.position =ccp(size.width -240, 110);
[selfaddChild:floorFly];
//洞悉权杖图标]
CCSpriteFrame *pre = [CCSpriteFrameframeWithTexture:Texturerect:CGRectMake(2*32,10*32,32,32)];
predict = [CCSpritespriteWithSpriteFrame:pre];
predict.scale =2.0;
predict.position =ccp(size.width -240, 40);
[selfaddChild:predict];
运行之后截图如下
屏幕快照 2013-02-27 下午2.35.30.png
 
下面我们首先来添加楼层传送这部分,我们需要先新建一个类FlyFloor,代码:
FlyFloor.h
#import<Foundation/Foundation.h>
#import"cocos2d.h"
 
@inte易做图ce FlyFloor :CCLayer 
{
    CCTMXTiledMap *mapBackground;
}
//是否清除窗体
@property (nonatomic,assign)bool removeView;
@end
 
FlyFloor.m
#import"FlyFloor.h"
 
@implementation FlyFloor
@synthesize removeView;
-(id)init
{
    if ((self = [superinit])) 
    {
        //背景
       mapBackground = [CCTMXTiledMaptiledMapWithTMXFile:@"shopbg.tmx"];
       mapBackground.position =ccp(45,85);
       mapBackground.scale =2.0;
        [selfaddChild:mapBackground];
       CCLabelTTF *floor = [CCLabelTTFlabelWithString:@"楼层"fontName:@"Verdana-Bold"fontSize:50];
        [selfaddChild:floor];
        floor.position =ccp(340,630);
        //菜单一
        CCMenuItemFont *floor1 = [CCMenuItemFontitemFromString:@"第一层" target:selfselector:@selector(goFloor:)];
        CCMenuItemFont *floor2 = [CCMenuItemFontitemFromString:@"第二层" target:selfselector:@selector(goFloor:)];
        CCMenuItemFont *floor3 = [CCMenuItemFontitemFromString:@"第三层" target:selfselector:@selector(goFloor:)];
        CCMenuItemFont *floor4 = [CCMenuItemFontitemFromString:@"第四层" target:selfselector:@selector(goFloor:)];
        CCMenuItemFont *floor5 = [CCMenuItemFontitemFromString:@"第五层" target:selfselector:@selector(goFloor:)];
        CCMenuItemFont *floor6 = [CCMenuItemFontitemFromString:@"第六层" target:selfselector:@selector(goFloor:)];
        CCMenuItemFont *floor7 = [CCMenuItemFontitemFromString:@"第七层" target:selfselector:@selector(goFloor:)];
        floor1.tag =1;
        floor2.tag =2;
        floor3.tag =3;
        floor4.tag =4;
        floor5.tag =5;
        floor6.tag =6;
        floor7.tag =7;
        floor1.position =ccp(0,180);
        floor2.position =ccp(0,120);
        floor3.position =ccp(0,60);
        floor4.position =ccp(0,0);
        floor5.position =ccp(0, -60);
        floor6.position =ccp(0, -120);
        floor7.position =ccp(0, -180);
        CCMenu *menu1 = [CCMenu menuWithItems:floor1,floor2,floor3,floor4,floor5,floor6,floor7, nil];
        [selfaddChild:menu1];
        
        menu1.position =ccp(160,360);
        //菜单二
        CCMenuItemFont *floor8 = [CCMenuItemFontitemFromString:@"第八层" target:selfselector:@selector(goFloor:)];
        CCMenuItemFont *floor9 = [CCMenuItemFontitemFromString:@"第九层" target:selfselector:@selector(goFloor:)];
        CCMenuItemFont *floor10 = [CCMenuItemFontitemFromString:@"第十层" target:selfselector:@selector(goFloor:)];
        CCMenuItemFont *floor11 = [CCMenuItemFontitemFromString:@"第十一层" target:self selector:@selector(goFloor:)];
        CCMenuItemFont *floor12 = [CCMenuItemFontitemFromString:@"第十二层" target:self selector:@selector(goFloor:)];
        CCMenuItemFont *floor13 = [CCMenuItemFontitemFromString:@"第十三层" target:self selector:@selector(goFloor:)];
        CCMenuItemFont *floor14 = [CCMenuItemFontitemFromString:@"第十四层" target:self selector:@selector(goFloor:)];
       //floor1.scale = 2.0;
        floor8.tag =8;
        floor9.tag =9;
        floor10.tag =10;
        floor11.tag =11;
        floor12.tag =12;
        floor13.tag =13;
        floor14.tag =14;
        floor8.position =ccp(0,180);
        floor9.position =ccp(0,120);
        floor10.position =ccp(0,60);
        floor11.position =ccp(0,0);
        floor12.position =ccp(0, -60);
        floor13.position =ccp(0, -120);
        floor14.position =ccp(0, -180);
        CCMenu *menu2 = [CCMenu menuWithItems:floor8,floor9,floor10,floor11,floor12,floor13,floor14, nil];
        [selfaddChild:menu2];
        menu2.position =ccp(340,360);
        //菜单三
        CCMenuItemFont *floor15 = [CCMenuItemFontitemFromString:@"第十五层" target:self selector:@selector(goFloor:)];
        CCMenuItemFont *floor16 = [CCMenuItemFontitemFromString:@"第十六层" target:self selector:@selector(goFloor:)];
        CCMenuItemFont *floor17 = [CCMenuItemFontitemFromString:@"第十七层" target:self selector:@selector(goFloor:)];
        CCMenuItemFont *floor18 = [CCMenuItemFontitemFromString:@"第十八层" target:self selector:@selector(goFloor:)];
        CCMenuItemFont *floor19 = [CCMenuItemFontite
补充:移动开发 , 其他 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,