- 浏览: 236450 次
- 性别:
- 来自: 天津
文章分类
最新评论
-
yulanlian:
...
实现在删除数据后,自增列的值连续 -
RonQi:
楼主写的很好,支持原创!
Google Protocol Buffers
前篇创建了一个没有任何内容的GameScene,本篇就来为它加上两个layer,再说说管理多layer的小技巧。假设这两个layer已经写好了,分别叫作GroundLayer和UserInterfaceLayer。
我们先给两个layer定义个tag,方便以后获取它们:
//GameScene.h
typedef enum
{
LayerTagGroundLayer,
LayerTagUserInterfaceLayer,
} GameSceneTags;
然后就在GameScene里添加这两个layer:
//GameScene.m
-(id) init
{
if ((self = [super init]))
{
gameSceneInstance = self; //先不管它,后面用上
GroundLayer* groundLayer = [GroundLayer node];
[self addChild:groundLayer z:1 tag:LayerTagGroundLayer];
UserInterfaceLayer* uiLayer = [UserInterfaceLayer node];
[self addChild:uiLayer z:2 tag:LayerTagUserInterfaceLayer];
}
return self;
}
z和tag的作用估计大家一看就懂,这段的意思也很明白。两个layer加好了,问题也随之而来:1.多个layer内部如果想和scene通信怎么办? 2.多个layer之间想通信怎么办?
首先解决问题1:
//GameScene.m
static GameScene* gameSceneInstance;
+(GameScene*) sharedScene {
return gameSceneInstance;
}
利用一个简陋的单件(singleton)模式,现在所有layer都能拿到GameScene了,方法为[GameScene sharedScene]; 问题1解决,但注意的是必须确保GameScene同时只有一个实例对象。
问题2,给GameScene加上几个getter方法:
-(GroundLayer*) groundLayer
{
return [self getChildByTag:LayerTagGroundLayer]; //tag派上用场了
}
-(UserInterfaceLayer*) uiLayer
{
return [self getChildByTag:LayerTagUserInterfaceLayer];
}
这样,在任何地方可以通过[[GameScene sharedScene] groundLayer];就拿到了GroundLayer对象。
当然,想代码漂亮点,加两个property就更好了。
written by Magic
转载请注明原地址: http://blog.sina.com.cn/s/blog_77013e2b0100ql5r.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 797一:确认网络环境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视 ...
相关推荐
本次实验是基于词袋模型的图像分类技术,利用提取的局部区域的分布对图像进行识别。在图像分类中,词袋模型算法需要通过监督或非监督的学习来获得视觉词典。基于词袋模型的图像分类算法一般分为四步,首先对图像进行...
多标记图像数据Multi-instance multi-label learni ng with application to scene classificat ion-miml-image-data 。。。。。。。。。。。
Learning to associate - HybridBoosted multi-target tracker for crowded scene
This is 3D reconstruction algorithm
Convolutionalneural networks with intra-layer recurrent connections for scene labeling
javafx scene builder 2.0-windows.msi.7z
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 ...
javafx-multi-scene javafx-multi-scene演示了在构建JavaFX应用程序时如何使用一个阶段和多个场景。 图形非常简单,因为演示的重点是如何从一个移动到另一个。 介绍 javafx-multi-scene在Main中使用静态Map,将...
Algorithm-Scene-text-recognition.zip,基于极值区域(er)的场景文本检测与识别,算法是为计算机程序高效、彻底地完成任务而创建的一组详细的准则。
javafx界面开发工具,方便大家下载 javafx_scenebuilder-2_0-windows
这篇论文提出了一种使用多任务学习生成通用、稳健的文本表示的方法,非常值得学习,欢迎下载!
Scene-Recognition-with-Bag-of-Words(基于词袋模型的场景识别) 1 实验目的 使用了两种特征提取算法(Tiny images feature和Bag of sift)及两种分类算法(k-Nearest Neighbor和SVM)进行场景识别。 Tiny + ...
Semantic Scene Completion via Integrating Instances and Scene In-the-Loop
Springer Tracts in Advanced Robotics Volume 135. Indoor Scene Recognition by 3-D Object Search.
javafx可视化工具 搬运至官方最新版
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...
javafx_scenebuilder
ABCNet - Real-time Scene Text Spotting with Adaptive Bezier-curve Network.mp4
JavaFx SceneBuilder2.0 看好多人官网下载不了我放这里面