Game Development Reference
In-Depth Information
HelloSpriteBuilderActivity.java simply creates a new class extending the CCActivity
class provided by Cocos2D. This goes in line with the HelloSpriteBuilderActivity
Objective-C class of the same name, whose interface is shown in Listing 13-2 .
Listing 13-2 . HelloSpriteBuilderActivity.h
#import "CCActivity.h"
BRIDGE_CLASS("org.cocos2d.HelloSpriteBuilder.HelloSpriteBuilderActivity")
@interface HelloSpriteBuilderActivity : CCActivity
@end
The special macro BRIDGE_CLASS refers to the aforementioned HelloSpriteBuilder-
Activity Java class, essentially connecting the two. There's also an analog for Java inter-
faces/Objective-C protocols named BRIDGE_INTERFACE. You only need to Bridge a
Java to Objective-C if you intend to use functionality not available in BridgeKit. Other-
wise, prefer to use the already exposed functionality of BridgeKit, since you can interface
with it purely using Objective-C code.
The HelloSpriteBuilderActivity implementation does only two things: launch the first
scene and respond to the Back key, telling the app to finish. The code is reprinted in List-
ing 13-3 .
Listing 13-3 . HelloSpriteBuilderActivity.m
#import "HelloSpriteBuilderActivity.h"
@implementation HelloSpriteBuilderActivity
-(CCScene*)startScene
{
return [CCBReader loadAsScene:@"MainScene"];
}
-(BOOL)onKeyUp:(int32_t)keyCode
keyEvent:(AndroidKeyEvent*)event
{
if (keyCode == AndroidKeyEventKeycodeBack)
{
[self finish];
}
return NO;
}
Search WWH ::




Custom Search