SpriteBuilder learning notes 1, spritebuilder

Source: Internet
Author: User

SpriteBuilder learning notes 1, spritebuilder

The CCControl tab is available only for user-interface nodes, which must be Buttons, Text Filed, and Slider nodes.

 

The Selector can be understood as the method name. When a button is pressed, a message is sent (it can be understood that the method is called)

Continuous: When selected, the method will always be called when the user keeps holding down the button.

 

 

There is a startScene method in AppDelegate. m:

 

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

 

Can change the loading scenario

The most common methods in CCBReader are loadAsScene and load. They can load specific CCB files and return CCScene and CCNode instances respectively.

 

 

 

 

Create a custom class for Scene

Create a custom class in SpriteBuilder, and then create a class or class variable with the same name in Xcode to connect the code. Order is not required.

Target can be specified. For selectors and ivars, the default values are Document root and Doc root var.

Document root refers to the root node of CCB file which contains the currently edited node. (the root node of the CCB file contains the node being edited ).

The root node is the topmost (top-level, top-level) node in the hierarchy ---- the one that's already there when you craete a CCB file. (This root node is the top-level node. When you create a CCB file, the existing node exists)

 

Note: When the Owner option is used as the target for selectors and ivars, it is only applicable to loading content in CCB at runtime in an existing Scenen. The original Article is as follows:

 

 

 

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.

You can specify a user-defined class (owner) as the receiver of selectors and ivars.

 

 

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

A common misunderstanding is that the Owner refers to the custom class of the selected node (the custom class of the selected node)

 

If you create a custom class for a Sprite-type CCB file, you must make the class inherit from CCSprite. If it is Particle CCBs, it must inherit from CCParticleSystem. Otherwise, it must inherit from the CCNode class, including Scene type !!

In the GameScene. m file:

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

When each node is created, it is sent by CCBReader.

 

Click the Button on GameScene to change the Scene Code as follows:

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: When CCBReader loadAsScene is used, "MainScene" can be used directly, but the. ccb extension cannot be added, because the extension name is ccbi rather than ccb internally.

Code Analysis:

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

The loadAsScene method returns a CCScene object, which is the root node of your CCB file and is the only child

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

The equivalent code of this line of code is as follows (using load: Method ):

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

To access the root node of MainScene, you also need to write:

CCNode * rootNode = scene. children. firstObject;

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.