// Import the interfaces #import "HelloWorldLayerr.h" #import "CCTouchDispatcher.h" #import "CCAnimation.h" #import "SimpleAudioEngine.h" #import "LanguageOfGame.h" #import "LanguageOfGameUA.h" #import "LanguageOfGameRu.h" CCScene* scene; CCMenu* startMenu; // HelloWorldLayer implementation @implementation HelloWorldLayerr +(CCScene *) scene { // 'scene' is an autorelease object. scene = [CCScene node]; // 'layer' is an autorelease object. HelloWorldLayerr *layer = [HelloWorldLayerr 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 { if( (self=[super init])) { CGSize size = [[CCDirector sharedDirector] winSize]; // 16- [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGB565]; CCSprite* startPicture = [CCSprite spriteWithFile:@"startMenu.png"]; startPicture.scale = 0.5; startPicture.position = ccp(size.width/2, size.height/2); [self addChild: startPicture z:1]; CCLabelTTF *languageLabel = [CCLabelTTF labelWithString:@"Choose your language" fontName:@"AppleGothic" fontSize:30]; languageLabel.anchorPoint = CGPointMake(0, 0.5f); languageLabel.color = ccYELLOW; languageLabel.position = ccp(size.width*0.05, size.height*9/10); [self addChild:languageLabel z:2]; CCMenuItemFont* button1 = [CCMenuItemFont itemFromString:@"ENG" target:self selector:@selector(selector1:)]; button1.color = ccYELLOW; CCMenuItemFont* button2 = [CCMenuItemFont itemFromString:@"UA" target:self selector:@selector(selector2:)]; button2.color = ccYELLOW; CCMenuItemFont* button3 = [CCMenuItemFont itemFromString:@"RU" target:self selector:@selector(selector3:)]; button3.color = ccYELLOW; startMenu = [CCMenu menuWithItems:button1, button2,button3, nil]; button1.position = ccp(size.width/4, size.height*8/10); button2.position = ccp(size.width/4, size.height*6.5/10); button3.position = ccp(size.width/4, size.height*5/10); startMenu.position = CGPointZero; [self addChild:startMenu z:10]; } return self; } -(void)selector1:(id)sender{ CCTransitionRadialCCW *transition = [CCTransitionZoomFlipX transitionWithDuration:1.1 scene:[LanguageOfGame scene]]; [[CCDirector sharedDirector] replaceScene:transition]; } -(void)selector2:(id)sender{ CCTransitionRadialCCW *transition = [CCTransitionZoomFlipX transitionWithDuration:0.8 scene:[LanguageOfGameUA scene]]; [[CCDirector sharedDirector] replaceScene:transition]; } -(void)selector3:(id)sender{ CCTransitionRadialCCW *transition = [CCTransitionZoomFlipX transitionWithDuration:0.8 scene:[LanguageOfGameRu scene]]; [[CCDirector sharedDirector] replaceScene:transition]; } //on "dealloc" you need to release all your retained objects - (void) dealloc { [scene release]; [startMenu release]; [super dealloc]; } @end
CCMotionStreak* streak; // -(void) ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event{ NSLog(@"TouchesMoved"); CGPoint touchLocation = [self convertTouchToNodeSpace:touch]; CGPoint oldTouchLocation = [touch previousLocationInView:touch.view]; oldTouchLocation = [[CCDirector sharedDirector] convertToGL:oldTouchLocation]; oldTouchLocation = [self convertToNodeSpace:oldTouchLocation]; CGPoint changedPosition = ccpSub(touchLocation, oldTouchLocation); // [self moveMotionStreakToTouch:touch]; } -(void)moveMotionStreakToTouch:(UITouch*)touch{ CCMotionStreak* streak = [self getMotionStreak]; streak.position = [self locationFromTouch:touch]; } -(CGPoint)locationFromTouch:(UITouch*)touch{ CGPoint touchLocation = [touch locationInView:[touch view]]; return [[CCDirector sharedDirector] convertToGL:touchLocation]; } // -(CCMotionStreak*)getMotionStreak{ streak = [CCMotionStreak streakWithFade:0.99f minSeg:8 image:@"ghost01.png" width:22 length:48 color:ccc4(255, 255, 255, 180)]; [self addChild:streak z:5 tag:1]; CCNode* node = [self getChildByTag:1]; NSAssert([node isKindOfClass:[CCMotionStreak class]], @"not a CCMotionStreak"); return (CCMotionStreak*)node; } /* , CCMotionStreak */ -(void) ccTouchEnded:(NSSet *)touch withEvent:(UIEvent *)event{ NSLog(@"TouchesEnded"); selectedSprite = nil; streak = nil; }
// -(void) nextFrame:(ccTime)dt{ bottle.positionInPixels = ccp(bottle.positionInPixels.x - 1, + bottle.positionInPixels.y); if (bottle.positionInPixels.x <= 49) { bottle.positionInPixels = ccp(bottle.positionInPixels.x + 1, + bottle.positionInPixels.y); } } -(void)moveTouchedObject:(CGPoint)changedPosition { if (selectedSprite == bottle) { [self nextFrame:5]; } }
// CCSprite *crashBottle2 = [CCSprite spriteWithFile:@"crashBottle01.png"]; crashBottle2.scale = 0.5; [crashBottle2 setPosition:ccp(xOfBottle, yOfBottle)]; [self addChild:crashBottle2]; CCAnimation *cbot = [CCAnimation animation]; [cbot addFrameWithFilename:@"crashBottle00.png"]; [cbot addFrameWithFilename:@"crashBottle01.png"]; [cbot addFrameWithFilename:@"crashBottle02.png"]; [cbot addFrameWithFilename:@"crashBottle03.png"]; [cbot addFrameWithFilename:@"crashBottle04.png"]; [cbot addFrameWithFilename:@"crashBottle05.png"]; [cbot addFrameWithFilename:@"crashBottle06.png"]; [cbot addFrameWithFilename:@"crashBottle07.png"]; [cbot addFrameWithFilename:@"crashBottle08.png"]; [cbot addFrameWithFilename:@"crashBottle09.png"]; [cbot addFrameWithFilename:@"crashBottle10.png"]; [cbot addFrameWithFilename:@"crashBottle11.png"]; id animationAction = [CCAnimate actionWithDuration:0.2f animation:cbot restoreOriginalFrame:NO]; [crashBottle2 runAction:animationAction];
CCSprite *manFrame1; CCAnimate *manCodding; CCRepeatForever* repeat; // -(void)manAnimation{ // - - CCSpriteBatchNode *manBatchNode; [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"man300N.plist"]; manBatchNode = [CCSpriteBatchNode batchNodeWithFile:@"man300N.png"]; [self addChild:manBatchNode]; CCSpriteBatchNode *manBatchNode2; [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"man359N.plist"]; manBatchNode2 = [CCSpriteBatchNode batchNodeWithFile:@"man359N.png"]; [self addChild:manBatchNode2]; manFrame1 = [CCSprite spriteWithSpriteFrameName:@"UntitledAnimation_0.png"]; manFrame1.position = ccp(size.width*0.4187,size.height*0.4281); [self addChild:manFrame1 z:30]; // NSString* fullFileName = @"man1Anim.plist"; NSString* rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString* plistPath = [rootPath stringByAppendingPathComponent:fullFileName]; if (![[NSFileManager defaultManager] fileExistsAtPath:plistPath]) { plistPath = [[NSBundle mainBundle] pathForResource:@"man1Anim" ofType:@"plist"]; } NSDictionary* animSettings = [NSDictionary dictionaryWithContentsOfFile:plistPath]; if (animSettings == nil){ NSLog(@"error reading plist"); } NSDictionary* animSettings2 = [animSettings objectForKey:@"man1Anim"]; float animationDelay = [[animSettings2 objectForKey:@"delay"] floatValue]; CCAnimation * animToReturn = [CCAnimation animation]; [animToReturn setDelay:animationDelay]; NSString* animationFramePrefix = [animSettings2 objectForKey:@"namePrefix"]; NSString* animationFrames = [animSettings2 objectForKey:@"animationFrames"]; NSArray* animFrameNumbers = [animationFrames componentsSeparatedByString:@","]; for (NSString* frameNumber in animFrameNumbers) { NSString* frameName = [NSString stringWithFormat:@"%@%@.png", animationFramePrefix, frameNumber]; [animToReturn addFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:frameName]]; } manCodding = [CCAnimate actionWithAnimation:animToReturn]; repeat = [CCRepeatForever actionWithAction:manCodding]; [manFrame1 runAction:repeat]; }
-(id) init { if( (self=[super init])) { size = [[CCDirector sharedDirector] winSize]; if (size.width > 500) { CCSprite* walls = [CCSprite spriteWithFile:@"walls.png"]; walls.position = ccp(size.width/2, size.height/2); walls.scale = 0.5; [self addChild:walls z:-10]; size.width = [CCDirector sharedDirector].winSize.width - 87; } … }
Source: https://habr.com/ru/post/266595/
All Articles