//
// HelloWorldScene.m
// test3
//
// Created by justin burlace on 1/1/14.
// Copyright burlace 2014. All rights reserved.
//
// -----------------------------------------------------------------------
#import "HelloWorldScene.h"
#import "IntroScene.h"
// -----------------------------------------------------------------------
#pragma mark - HelloWorldScene
// -----------------------------------------------------------------------
@implementation HelloWorldScene
{
CCLabelTTF *_helloLabel;
float _runtime;
}
// -----------------------------------------------------------------------
#pragma mark - Create & Destroy
// -----------------------------------------------------------------------
+ (HelloWorldScene *)scene
{
return [[self alloc] init];
}
// -----------------------------------------------------------------------
- (id)init
{
CCSprite *spaceCargoShip = [CCSprite
spriteWithFile:@"SpaceCargoShip.png"];
[spaceCargoShip setPosition:ccp(size.width/2, size.height/2)];
[self addChild:spaceCargoShip];
// Apple recommend assigning self with supers return value
self = [super init];
// Crash if basic initialization for some reason failed
NSAssert(self, @"Unable to create class HelloWorldScene");
// Here is where custom code for the scene starts
_runtime = 0;
// create a lebal on the centre of the sceen
_helloLabel = [CCLabelTTF labelWithString:@"Hello World (v3)" fontName:@"Arial" fontSize:48];
_helloLabel.positionType = CCPositionTypeNormalized;
_helloLabel.position = ccp(0.5f, 0.8f);
[self addChild:_helloLabel];
// create a back button
CCButton *backButton = [CCButton buttonWithTitle:@"[ Back ]"];
backButton.positionType = CCPositionTypeNormalized;
backButton.position = ccp(0.1f, 0.9f);
[backButton setTarget:self selector:@selector(onBackClicked:)];
[self addChild:backButton];
// done
return self;
}
// -----------------------------------------------------------------------
- (void)dealloc
{
// clean up code goes here
}
// -----------------------------------------------------------------------
#pragma mark - Enter & Exit
// -----------------------------------------------------------------------
- (void)onEnter
{
// always call super onEnter first
[super onEnter];
// In pre-v3, touch enable and scheduleUpdate was called here
// In v3, touch is enabled by setting userInterActionEnabled for the individual nodes
// Pr frame update is automatically enabled, if update is overridden
}
// -----------------------------------------------------------------------
- (void)onExit
{
// always call super onExit last
[super onExit];
}
// -----------------------------------------------------------------------
#pragma mark - update
// -----------------------------------------------------------------------
- (void)update:(CCTime)delta
{
// manually move hello label up and down
_runtime += delta * 5.0f;
_helloLabel.position = ccp(0.5f, 0.8f + (sinf(_runtime) * 0.1f));
}
// -----------------------------------------------------------------------
#pragma mark - Button Callbacks
// -----------------------------------------------------------------------
- (void)onBackClicked:(id)sender
{
// back to intro scene with transition
[[CCDirector sharedDirector] replaceScene:[IntroScene scene]
withTransition:[CCTransition transitionPushWithDirection:CCTransitionDirectionRight duration:1.0f]];
}
// -----------------------------------------------------------------------
@end
所以我到目前为止得到了2个问题。 1.无法找到spriteWithFile方法。它在另一个文件中声明。不确定我是否必须链接或不是什么? 2.大小未定义......这只会令人困惑
我意识到这可能是一个简单的解决方法,但我刚刚开始,任何事情都可以提供帮助。