1

Cocos2d でゲームを開発しています。その中で、x 軸で絶えず動いているシーンの背景。私はcocos2dが初めてなので、どうすればそれができるかを理解したいです。

前もって感謝します

4

1 に答える 1

1

私のコードを見てください -ここにソースがあります。で「移動」テクニックを見つけますHelloWorldLayer.m。360 度のパノラマ写真を撮影し、フルスクリーンで右から左に連続的に移動させました。

YourClass.h ファイルで:

#import "cocos2d.h"
@interface YourClass : CCLayer

+(CCScene *) scene;

@end

YourClass.m ファイルで:

#import "YourClass.h"

@implementation YourClass

CCSprite *panorama;
CCSprite *appendix;
//_____________________________________________________________________________________
+(CCScene *) scene
{
    // 'scene' is an autorelease object.
    CCScene *scene = [CCScene node];

    // 'layer' is an autorelease object.
    YourClass *layer = [YourClass node];

    // add layer as a child to scene
    [scene addChild: layer];

    // return the scene
    return scene;
}
//_____________________________________________________________________________________
// on "init" you need to initialize your instance
-(id) init
{
    // always call "super" init
    // Apple recommends to re-assign "self" with the "super" return value
    if( (self=[super init])) {

        panorama = [CCSprite spriteWithFile: @"panorama.png"];
        panorama.position = ccp( 1709/2 , 320/2 );
        [self addChild:panorama];

        appendix = [CCSprite spriteWithFile: @"appendix.png"];
        appendix.position = ccp( 1709+480/2-1, 320/2 );
        [self addChild:appendix];

        // schedule a repeating callback on every frame
        [self schedule:@selector(nextFrame:)];

    }
    return self;
}
//_____________________________________________________________________________________
- (void) nextFrame:(ccTime)dt {

    panorama.position = ccp(panorama.position.x - 100 * dt, panorama.position.y);
    appendix.position = ccp(appendix.position.x - 100 * dt, appendix.position.y);
    if (panorama.position.x < -1709/2) {
        panorama.position = ccp( 1709/2 , panorama.position.y );
        appendix.position = ccp( 1709+480/2-1, appendix.position.y );
    }

}
// on "dealloc" you need to release all your retained objects
- (void) dealloc
{
    // in case you have something to dealloc, do it in this method
    // in this particular example nothing needs to be released.
    // cocos2d will automatically release all the children (Label)

    // don't forget to call "super dealloc"
    [super dealloc];
}
//_____________________________________________________________________________________
@end

このコードを少し試してみると、必要なものが得られます。

于 2012-07-26T13:50:45.667 に答える