模态对话框的实现模板

类从CCLayerColor继承

@interface LQModalLayer : CCLayerColor {
    


}


@interface LQModalLayer () {
    // 模态对话框菜单
    CCMenu *m_pMenu;
    // 记录菜单点击
    bool m_bTouchedMenu;
}



// 初始化数据
-(id) init
{
    // always call "super" init
    // Apple recommends to re-assign "self" with the "super's" return value
    if( (self=[super initWithColor:ccc4(0, 0, 0, 125)]) ) {
        // ask director for the window size
        //CGSize size = [[CCDirector sharedDirector] winSize];
        
        CCMenuItemSprite *testItem1 =
        [CCMenuItemSprite itemWithNormalSprite: [CCSprite spriteWithSpriteFrameName: @"btn3.png"]
                                selectedSprite: [CCSprite spriteWithSpriteFrameName: @"btn3sel.png"]
                                        target: self
                                      selector: @selector(itemPressed:)];
        testItem1.position = ccp(320,200);
        m_pMenu = [CCMenu menuWithItems: testItem1,nil];
        m_pMenu.position = CGPointZero;
        m_pMenu.tag = 10;
        [self addChild:m_pMenu];
        
        [self setIsTouchEnabled:YES];
    }
    return self;
}

-(void) onEnter
{
    [[[CCDirector sharedDirector] touchDispatcher] addTargetedDelegate:self priority:kCCMenuHandlerPriority-1 swallowsTouches:YES];
    [super onEnter];
}

- (void)onExit
{
    [[[CCDirector sharedDirector] touchDispatcher] removeDelegate:self];
    [super onExit];
}

-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
//    CGPoint point = [touch locationInView: [touch view]];
//    point = [[CCDirector sharedDirector] convertToGL: point];
    m_bTouchedMenu = [m_pMenu ccTouchBegan:touch withEvent:event];

    return YES;
}

-(void) ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
    if (m_bTouchedMenu) {
        [m_pMenu ccTouchMoved:touch withEvent:event];
    }
    return;
}

-(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
    if (m_bTouchedMenu) {
        [m_pMenu ccTouchEnded:touch withEvent:event];
        m_bTouchedMenu = false;
    }
}

-(void) ccTouchCancelled:(UITouch *)touch withEvent:(UIEvent *)event
{
    if (m_bTouchedMenu) {
        [m_pMenu ccTouchCancelled:touch withEvent:event];
        m_bTouchedMenu = false;
    }
}

- (void) itemPressed: (CCNode *) item
{
    NSLog(@"itemPressed...%@",item);
    
    [self setVisible:false];
    [self.parent removeChild:self cleanup:true];
}

// 释放对象资源
- (void) dealloc
{
    // in case you have something to dealloc, do it in this method
    // in this particular example nothing needs to be released.
    // cocos2d will automatically release all the children (Label)
    
    // don't forget to call "super dealloc"
    [super dealloc];
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值