·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> app软件开发 >> IOS开发 >> SpriteBuilder学习笔记一

SpriteBuilder学习笔记一

作者:佚名      IOS开发编辑:admin      更新时间:2022-07-23

只有user-interface nodes,必须Buttons,Text Filed,和Slider nodes才有CCControl选项卡

 

其中Selector可以理解为:方法的名字。当按钮被按下时,会传递一个消息(可以理解为方法被调用)

Continuous:当被选中时,方法会一直调用当用户不断的按住button。

 

 

在AppDelegate.m中有一个startScene方法:

 

- (CCScene*) startScene
{
    return [CCBReader loadAsScene:@"GameScene"];
}

 

可以改变载入场景

CCBReader中的方法最常用的是loadAsScene和load,分别可以载入特定的CCB文件,并且分别返回CCScene和CCNode实例。

 

 

 

 

为Scene创建一个自定义类

现在SPRiteBuilder中创建一个一个custom class,然后在Xcode中创建相同名字的类或者类的变量,才可以完成代码的的连接。顺序没有要求。

可以指定target,对于selectors和ivars,默认分别为Document root 和Doc root var.

Document root指的是 the root node of CCB file which contains the currently edited node.(CCB文件的根node,这个根node包含着正在编辑的node).

The root node is the topmost(顶层的,最高层的)node in the hierarchy ----the one that's already there when you craete a CCB file.(这个根node 是最顶层的node,当你建立一个CCB文件的时候,就已经存在的那个node)如图:

 

注意:对selectors和ivars使用Owner选项作为target的情况,仅仅适用于在已经存在的Scenen中,在运行时载入CCB中的内容.原文如下:

 

 

 

Using the Owner setting as the target for selectors and ivars is done only in cases where you load the contents of a CCB at runtime with an already existing scene.

你可以指定一个自定义类(owner)作为selectors和ivars的接收者。

 

 

One use for this is to map an overlaymenu CCB's button selectors to the scene's original custom class.

一个常见的误解是Owner指的是custom class of the selected node(被选择的node的自定义类)

 

如果你为Sprite类型的CCB文件创建自定义类,你必须让class继承自CCSprite,如果是Particle CCBs,必须继承自CCParticleSystem,除此之外,必须继承自CCNode类,包括Scene类型!!

在GameScene.m文件中:

@implementation GameScene
- (void)didLoadFromCCB {
    NSLog(@"GameScene created!");
}
@end

当每个node被创建时,由CCBReader发送。

 

点击GameScene上的Button,实现更换Scene的代码如下:

1 - (void)exitButtonPressed {
2     NSLog(@"get me outa here!");
3     CCScene *scene = [CCBReader loadAsScene:@"MainScene.ccbi"];
4     CCTransition *transition = [CCTransition transitionFadeWithDuration:1.5];
5     [[CCDirector sharedDirector] presentScene:scene withTransition:transition];
6 }

NOTE:使用CCBReader loadAsScene时,可以直接使用“MainScene”,但一定不能加上.ccb扩展名,因为在内部,后缀名为ccbi而不是ccb。

代码分析:

CCScene *scene = [CCBReader loadAsScene:@"MainScene.ccbi"];

loadAsScene方法返回一个CCScene对象,它是你的CCB文件的根node,作为唯一的child

原文:(It returns a CCScene object with your CCB file's root node as the only child)

这行代码的等价代码如下(使用load:方法):

CCNode *ccbRootNode = [CCBReader load:@"MainScene"];
CCScene *scene = [CCScene node];
[scene addChild:ccbRootNode];

为了访问MainScene的根node,还需要写:

CCNode *rootNode = scene.children.firstObject;

 

Create a Level Sub File Node

游戏支持很多level,因为每一个level都有相同的基本元素,所以每一level重复使用GameScene是合理的.

举例来说:HUD----headsup display 即不滚动的内容,比如暂停按钮,得分牌label等。

 

 

 

 

拖动一个Gradient Node 进入stage.

 

改变z轴顺序的方法:

在parent容器中的TimeLine中改变z轴顺序

NOTE:

可以在TimeLine中改变node的描述,但这和property中的名字可以不同,建议保持相同的名字以免出现冲突。

 

NOTE:

左侧第二项Tileless Editor View仅仅在CCB文件保存后或者项目发布后才会更新,使用时如果发现不同之处需要先保存或发布项目。

 

 

 

Adding the Player Sprite

执行后,文件夹变成粉红色

推荐使用PVR RGBA8888,并且选上Compress,这样内存加载的更快,也更省内存,并且没有任何负面影响。

 

NOTE:RGBA4444和RGB565把颜色位宽减到16bit,RGB565仅仅适用于没有透明通道的图片,比如:opaque background images.

PVRTC是”最后的招数“,它们使用有损压缩,就像JPG,但是这样可以很大程度上减少内存的使用和改进底层的表现。

在快速移动,短时间内存在或者很小图片的时候使用PVRTC。比如:子弹。