Search code examples
iphoneobjective-cioscocos2d-iphoneiphone-5

cocos2d CCScene background orientation


I'm trying to add a background image for my scene using the following code:

    CCSprite* background = [CCSprite spriteWithFile:@"background-hd.png"];
    background.tag = 1;
    background.anchorPoint = CGPointMake(0,0);
    [self addChild:background];

My apps orientation is landscape and the image's orientation is landscape as well, however I get the image orientated in portrait:

https://i.sstatic.net/ZIFnU.png


Solution

  • I think this is the solution with Layer which set the scene with orientation...

    +(CCScene *) scene
     {
    CCScene *scene = [CCScene node];
    StartLayer *layer = [StartLayer node];
    
    CCSprite *background = [CCSprite spriteWithFile:@"background-hd.png"];
    background.anchorPoint = ccp(0,0);
    
    [layer addChild:background z:-1];
    [scene addChild: layer];
    
    return scene;
     }
    

    See this link for More information Cocos2d-Scenes-and-Layers....

    Hope this helpful to you...