1.将当前层下面的层全部禁止点击
//cocos2d-x代码 cocos2d::CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, kCCMenuTouchPriority, true);
//还需要加上 不然在debug模式下报错
bool PaymentLayer::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
return true; //返回YES表示吞噬touch事件,则其他代理都不收到该事件了。
}
//cocos2d代码 [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:kCCMenuTouchPriority swallowsTouches:YES];
//////////////或者直接建立一个 void registerWithTouchDispatcher()函数
PaymentLayer继承自cclayer 系统进PaymentLayer的时候会自动调用这个函数
void PaymentLayer::registerWithTouchDispatcher()
{
//禁止点击下层按钮
CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, kCCMenuTouchPriority, true);
CCLog("禁止点击下层按钮");
}
2.延迟调用方法 //cocos2d-x代码 //延迟0.4s调用 removeSelf()函数 针对有些回调函数延后执行 this->schedule(schedule_selector(PaymentLayer::removeSelf), 0.4f); void PaymentLayer::removeSelf() { //停止计时器 this->unschedule(schedule_selector(PaymentLayer::removeSelf)); }
//cocos2d代码 [self schedule:@selector(removeSelf) interval:0.4f]; - (void) removeSelf { //停止计时器 [self unschedule:@selector(removeSelf)]; }
3.获取公网的ip地址 NSError *error; NSURL *ipURL = [NSURL URLWithString:@"http://automation.whatismyip.com/n09230945.asp"]; NSString *ip = [NSString stringWithContentsOfURL:ipURL encoding:NSUTF8StringEncoding error:&error]; NSLog(@"-------ip = %@", ip);
4. //图片不加进缓存 ( 错误 imageWithContentsOfFile 要加取图片路径函数 ) imageListData是NSMutableArray
[imageListData addObject:[UIImageimageWithContentsOfFile:[MHFileToolgetResourcesFile:@"first.png"]]];
//[NSNull null]可以放进object的空指针
[imageListData addObject:[NSNullnull]];
|