-(id) init { if( (self=[super init])) { // , CGSize size = [[CCDirector sharedDirector] winSize]; // backgroung CCSprite * background = [CCSprite spriteWithFile:@"clean bg.png"]; // background.position = ccp(size.width/2, size.height/2); // CCLayer , // z:-1 [self addChild:background z:-1]; } return self; }
[self addChild:background z:-1 tag:100];
this is done so that you can find a sprite on a tag in another method or class, this is done like this: CCSprite *spr = (CCSprite *)[self getChildByTag:100];
then do what you want with this sprite. // // CCMenuItemImage * image = [CCMenuItemImage itemFromNormalImage:@"new_game.png" selectedImage:@"new_game.png" target:self selector:@selector(perehod_v_igru)]; // ( , // ) image.position = ccp(0, 50); // font CCMenuItemFont * font = [CCMenuItemFont itemFromString:@"" target:self selector:@selector(options)]; font.position = ccp(0, -50); // // CCMenu * menu = [CCMenu menuWithItems:image, font, nil]; // menu.position = ccp(size.width /2 , size.height/2); // [self addChild:menu];
-(void)perehod_v_igru { // [[CCDirector sharedDirector] replaceScene:[CCTransitionPageTurn transitionWithDuration:1 scene:[Game node]]]; }
CCTransition
is responsible for the transition effect from one layer to another for a certain time. -(void)options { // [[CCDirector sharedDirector] pushScene:[Options node]]; }
pushScene
is used to temporarily overlay a layer. -(id) init { // RGB if ((self = [super initWithColor:ccc4(255, 0, 0, 155)])) { CGSize size = [[CCDirector sharedDirector] winSize]; CCMenuItemFont * font = [CCMenuItemFont itemFromString:@" " target:self selector:@selector(backItem)]; font.position = ccp(0, 0); CCMenu * menu = [CCMenu menuWithItems: font, nil]; menu.position = ccp(size.width /2 , size.height/2); [self addChild:menu]; } return self; } -(void)backItem{ // [[CCDirector sharedDirector] popScene]; }
-(id) init { if( (self=[super init])) { CGSize size = [[CCDirector sharedDirector] winSize]; // background CCSprite * background = [CCSprite spriteWithFile:@"clean bg.png"]; //anchorPoint , //background.anchorPoint = ccp(0.5f,0.5f); // anchorPoint = ccp(1, 1); // , (0, 0) background.anchorPoint = ccp(1, 1); background.position = ccp(size.width, size.height); [self addChild:background z:-1]; // 0,5 [self performSelector:@selector(sozdanie_CCSprite) withObject:self afterDelay:0.5]; } return self; }
-(void)sozdanie_CCSprite { // background CCSprite * tarakan = [CCSprite spriteWithFile:@"tarakan0.png"]; tarakan.position = ccp(512, 100); tarakan.anchorPoint = ccp(0,0); [self addChild:tarakan]; //Actions // id move = [CCMoveBy actionWithDuration:2 position:ccp(0, 500)]; // id accel = [CCEaseInOut actionWithAction:move rate:5]; // id rotate = [CCRotateBy actionWithDuration:2.0f angle:360]; // [tarakan runAction:[CCSequence actions:accel, rotate, nil]]; // [self performSelector:@selector(animation) withObject:self afterDelay:3.5]; }
-(void)animation { CGSize size = [[CCDirector sharedDirector] winSize]; // plist [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"tarakan.plist" textureFile:@"tarakan.png"]; //CCSpriteBatchNode cocos2d, // // CCSpriteBatchNode * bowSheet = [CCSpriteBatchNode batchNodeWithFile:@"tarakan.png"]; NSString *topbird = @"tarakan"; NSMutableArray *walkAnimFrames = [NSMutableArray array]; // for(int i = 1; i <= 4; ++i) { CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: topbird stringByAppendingString:[ NSString stringWithFormat:@"%d.png", i]]]; [walkAnimFrames addObject:frame]; } // CCAnimation *walkAnim = [CCAnimation animationWithFrames:walkAnimFrames delay:0.1f]; NSString *bowFrame = [topbird stringByAppendingString:@"1.png"]; // CCSprite * bow = [CCSprite spriteWithSpriteFrameName:bowFrame]; bow.position = ccp(size.width/2 , -100); [bowSheet addChild:bow]; //CCAnimate CCAnimation // CCAnimate CCAnimate * bowAnim = [[CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:YES] retain]; [self addChild:bowSheet]; // id walkAction = [CCRepeat actionWithAction:bowAnim times:5]; // id da = [CCMoveBy actionWithDuration:2 position:ccp(0, 600)]; // [bow runAction:[CCSpawn actions:da, walkAction, nil]]; }
tarakan.plist
file:tarakan.png
file:Source: https://habr.com/ru/post/126422/
All Articles