- 浏览: 236448 次
- 性别:
- 来自: 天津
文章分类
最新评论
-
yulanlian:
...
实现在删除数据后,自增列的值连续 -
RonQi:
楼主写的很好,支持原创!
Google Protocol Buffers
一款游戏一般肯定不止有一个scene(啥?你就做了一个?回去洗洗睡吧),从一个scene到另一个scene的过程就是本篇讨论的中心。假设当前在FirstScene,然后执行如下代码:
[[CCDirector sharedDirector] replaceScene:[OtherScene scene]];
将会引发一系列的方法被调用,如下:
1. scene: OtherScene的
2. init: OtherScene的
3. onEnter: OtherScene的
4. Transition 发生.
5. onExit: FirstScene的
6. onEnterTransitionDidFinish: OtherScene的
7. dealloc: FirstScene的
当一个scene被搬上“台面”,它会收到onEnter,原来的scene会收到onExit,最后交替完成在台面上的scene收到onEnterTransitionDidFinish。从中我们可以看出,只有当登台的scene完全加载完成,下场的scene才会被释放。两个scene在某一帧是同时处在内存里的,内存自然会表示压力很大。
两个资源密集型的scene在切换时,不仅对内存有很大压力,加载时间有时也会长到让用户果断按下home键。书中给出了一个巧妙的解决方案:通过引入一个轻量的中间scene,使源scene先切换到中间scene,再切换到目标scene。这样不仅避免了源scene和目标scene的重叠,还可以在中间scene显示loading等字样。中间scene的名字叫LoadingScene,代码如下:
//LoadingScene.h
typedef enum
{
TargetSceneFirstScene,
TargetSceneOtherScene,
} TargetScenes; //定义几个target scene,还是使用enum来提高可读性
@interface LoadingScene : CCScene { //直接继承CCScene,这里完全不需要CCLayer
TargetScenes targetScene_;
}
+(id) sceneWithTargetScene:(TargetScenes)targetScene;
-(id) initWithTargetScene:(TargetScenes)targetScene;
//LoadingScene.m
+(id) sceneWithTargetScene:(TargetScenes)targetScene
{
return [[[self alloc] initWithTargetScene:targetScene] autorelease];
}
-(id) initWithTargetScene:(TargetScenes)targetScene
{
if (self = [super init]) {
targetScene_ = targetScene;
//这里可以放个CCLabel来显示loading什么的,不是重点,不写了。
[self scheduleUpdate]; //最关键的一句!等待一帧,让源scene的内存都释放掉,下一帧进入update
}
return self;
}
-(void) update:(ccTime)delta
{
[self unscheduleAllSelectors]; //取消schedule,update不会再被调用了
switch (targetScene_)
{
case TargetSceneFirstScene:
[[CCDirector sharedDirector] replaceScene:[FirstScene scene]]; break;
case TargetSceneOtherScene:
[[CCDirector sharedDirector] replaceScene:[OtherScene scene]]; break;
default:
//error
break;
}
}
有了LoadingScene作为中介,scene的切换就可以这样写了:
[[CCDirector sharedDirector] replaceScene:[LoadingScene sceneWithTargetScene:TargetSceneOtherScene]];
written by Magic
转载请注明原地址: http://blog.sina.com.cn/s/blog_77013e2b0100qosh.html
发表评论
-
ios 国际化相关
2011-10-08 18:49 1413添加国际化 1. 代码中使用字符串的地方 使用 NS ... -
iPhone开发笔记
2011-09-26 21:52 1063退回输入键盘: - (BOOL) textFie ... -
ios开发基础知识 - 1
2011-09-26 21:51 1087输出 command+shift+r NSLog(@& ... -
ios---超链接的UILabel教程
2011-09-26 21:50 1491超链接的UILabel教程 -
ios开发基础问题总结
2011-09-26 21:49 1246订阅 1,如何进入应用后首 ... -
UILabel用法
2011-09-26 20:45 1779/设置换行 UILabel*label; / ... -
IPhone之UIScrollView [转载]
2011-09-22 15:55 859原文地址:IPhone之UIScrollView作者:飞 ... -
手势识别
2011-09-03 17:19 860注册: UISwipeGestureReco ... -
“碰撞”探测
2011-08-21 14:28 807首先要向大家说明的是,所谓“碰撞”探测没有大家想想 ... -
coco2d地图显示相关类
2011-08-21 07:55 1550摘自:知易教程 Cocos2d-iPhone 实现地图 ... -
Cocos2D 的事件处理机制
2011-08-21 07:21 1561摘自:知易教程 系统当前场景对象包含多个层 ... -
cocos2d游戏开发,常用工具集合
2011-08-20 19:40 797位图字体工具Bitmap Font ToolsBMFon ... -
iPhone OS 的 Touche 事件
2011-08-20 19:34 1304知易教程 基础知识 在开始介绍 iPhone OS ... -
iPad, iPhone, and Aspect Ratio
2011-08-05 11:58 918好,现在处理iphone上 ... -
Retina Display and Cocos2D
2011-08-05 11:57 1295最新版本的cocos2d完全 ... -
网络编程总结
2011-08-04 15:41 796一:确认网络环境3G/WIFI 1. 添加源文件和fra ... -
Cocos2D界面切换方式
2011-08-04 15:37 1601CCTransitionFade, //渐隐 ... -
Protocol协议的用法
2011-08-04 15:30 1218一、说明 两个类进行通讯,用协议就比较方便。 (书 ... -
IOS开源项目和官方例子汇总
2011-08-04 14:22 1811开源项目: 扫描wifi信息:http://code. ... -
cocos2d场景和UIViewController视图的切换
2011-08-04 14:20 1581cocos2d中从场景切换到UIViewController视 ...
相关推荐
javafx-multi-scene javafx-multi-scene演示了在构建JavaFX应用程序时如何使用一个阶段和多个场景。 图形非常简单,因为演示的重点是如何从一个移动到另一个。 介绍 javafx-multi-scene在Main中使用静态Map,将...
Learning to associate - HybridBoosted multi-target tracker for crowded scene
This is 3D reconstruction algorithm
多标记图像数据Multi-instance multi-label learni ng with application to scene classificat ion-miml-image-data 。。。。。。。。。。。
different images of the same scene can be combined into a single fused image [1]. The fused image can provide more comprehensive information about the scene which is more useful for human and machine ...
这篇论文提出了一种使用多任务学习生成通用、稳健的文本表示的方法,非常值得学习,欢迎下载!
Multi-focus image fusion in wireless visual sensor networks (WVSN) is a process of fusing two or more images to obtain a new one which contains a more accurate description of the scene than any of the...
驾驶场景中的多对象跟踪。 该存储库中的代码基于。 跟踪器的C ++。 用于评估代码的Python。 示范影片 。 概述 ...这项工作以(Osep,2017)所做的工作为基础。 原始代码可以在这里找到。 这个想法是使跟踪器适应于现代...
Parallel multi-stage features fusion of deep convolutional neural networks for aerial scene classification
"flappy bird" Python code with pygame framework. Multi-scene structure.
基于小规模深度卷积神经网络的场景识别,刘宇轩,董远, 场景分类是随着大规模图像分类问题被基本解决之后被提出的更加细分的分类问题。本文首先介绍了目前常用的场景分类评测数据集��
Context Contrasted Feature and Gated Multi-scale Aggregation for Scene Segmentation.pdf Context Encoding for Semantic Segmentation.pdf Convolutional Neural Networks with Alternately Updated Clique ....
基于原型的内存网络的标签和代码用法在requirements.txt安装依赖项下载并解压缩images.zip ... @article{hua2021prototype, title={Aerial Scene Understanding in The Wild: Multi-Scene Recognition via Prototype-ba
多任务学习 此仓库旨在在PyTorch中实施几种多任务学习模型和培训策略。 该代码库是对以下工作的补充: , ,Wouter Van Gansbeke,Marc Proesmans,Dengxin Dai和Luc Van Gool。 , 和Luc Van Gool。...
A modified method of image denoising based on multi-scale mathematical morphology is proposed to be used in the earthquake ruin scene. A new morphological arithmetic operator is desiged according to ...
A light field three-dimensional (3D) display with multi-projectors and a concave screen is proposed. The system sets the viewing area at the center of the concave screen, making viewers enter the ...
Inspired by the fact that edge is an important cue to distinguish texts from background, we propose a novel scene text detection method via edge cue and multiple features, which has two main parts, i....
It is the first relatively large scale scene text dataset that features three different text orientations: horizontal, multi- oriented, and curve-oriented. In addition, we also study several other ...
IncepText: A New Inception-Text Module with Deformable PSROI Pooling for Multi-Oriented Scene Text Detection