Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 19th, 2010 | Syntax: Objective C | Size: 5.84 KB | Hits: 387 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1.  <span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left">// // cocos2d Hello World example // http://www.cocos2d-iphone.org // // Import the interfaces #import "cocos2d.h" #import "HelloWorldScene.h" @implementation SpriteDemo -(id) init { if( (self=[super init])) { hbar1 = [[Sprite spriteWithFile:@"red_bar_52h.png"] retain]; hbar2 = [[Sprite spriteWithFile:@"yellow_bar_52h.png"] retain]; [self addChild: hbar1 z:2]; [self addChild: hbar2 z:1]; CGSize s = [[Director sharedDirector] winSize]; [hbar1 setPosition: ccp(240, 25)]; [hbar2 setPosition: ccp(240, 25)]; //myTimer = [NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(SpriteEaseSineInOut) userInfo:nil repeats:YES]; Label* label = [Label labelWithString:[self title] fontName:@"Arial" fontSize:32]; [self addChild: label]; [label setPosition: ccp(s.width/2, s.height-50)]; } return self; } -(void) dealloc { [hbar1 release]; [super dealloc]; } -(NSString*) title { return @"No title"; } @end @implementation SpriteEaseSineInOut -(void) onEnter { [super onEnter]; id move = [MoveBy actionWithDuration:1 position:ccp(0,200)]; //id move_back = [move reverse]; id move_ease = [EaseSineInOut actionWithAction:[[move copy] autorelease]]; id move_ease_back = [move_ease reverse]; id move2 = [MoveBy actionWithDuration:1 position:ccp(0,200)]; //id move_back = [move reverse]; id move_ease2 = [EaseSineInOut actionWithAction:[[move2 copy] autorelease]]; id move_ease_back2 = [move_ease2 reverse]; id seq1 = [Sequence actions: move_ease, move_ease_back, nil]; //id seq2 = [Sequence actions: move_ease2, move_ease_back2, nil]; id seq2 = [CCSequence actions: [CCDelayTime actionWithDuration:0.05f], [CCCallFuncN actionWithTarget: self selector:@selector(hbar2Repeat:)], nil]; [hbar1 runAction: [RepeatForever actionWithAction:seq1]]; //[hbar2 runAction: [DelayTime actionWithDuration:0.05f]]; //[hbar2 runAction: [RepeatForever actionWithAction:seq2]]; [hbar2 runAction: seq2]; } -(void)hbar2Repeat:(id)sender { id move2 = [MoveBy actionWithDuration:1 position:ccp(0,200)]; //id move_back = [move reverse]; id move_ease2 = [EaseSineInOut actionWithAction:[[move2 copy] autorelease]]; id move_ease_back2 = [move_ease2 reverse]; CCRepeatForever *repeat = [CCRepeatForever actionWithAction:[CCSequence actions: move_ease2, move_ease_back2, nil]]; [hbar2 runAction:repeat]; } -(NSString *) title { return @"Copper Bars!"; } @end /* -(void) example { id action = [CCSequence actions: [CCDelayTime actionWithDuration:1], [CCCallFuncN actionWithTarget:self selector:@selector(repeatForever:)], nil]; [sprite runAction:action]; } -(void) repeatForever:(id)sender { CCRepeatForever *repeat = [CCRepeatForever actionWithAction: [CCRotateBy actionWithDuration:2 angle:360]]; [sender runAction:repeat]; */</span> / / / / / / / / / 가져오기 인터페이스에서는 # import "cocos2d.h" "구현 HelloWorldScene.h"@ SpriteDemo # import를 http://www.cocos2d-iphone.org - (ID)을 초기화 Hello World를 예를 들어 / cocos2d (만약 ((자기 = [슈퍼 초기화])) (hbar1 = [[스프 라이트 spriteWithFile : @ "red_bar_52h.png"]] 유지; hbar2 = [[스프 라이트 spriteWithFile : @ "yellow_bar_52h.png"]] 유지; [자기 addChild : hbar1부터 Z : 2]; [자기 addChild : hbar2 z는 : 1]; CGSize =들 [[감독 sharedDirector] winSize; [hbar1 setPosition : (240, 25)]; [hbar2 setPosition : 공산당 (240, 25) 중공 ]; / / myTimer = [NSTimer scheduledTimerWithTimeInterval : .1 대상 : 자기 선택기 : 선택기 (SpriteEaseSineInOut) UserInfo : 무 반복 : 예 @]; 라벨 * 라벨 = [라벨 labelWithString : [셀프 타이틀] fontName : @ "돋움"FontSize : 32]; [자기 addChild : 레이블]; [라벨 setPosition : (s.width / 공산당 2 s.height - 50)];)를 반환 자기;) - (무효) dealloc ([hbar1 출시]; [슈퍼 dealloc] "제목 없음"@;) - (NSString *) 제목 (반환;) 구현 SpriteEaseSineInOut @ 최종 @ - (무효) OnEnter ([슈퍼 OnEnter]; id를 이동 = [MoveBy actionWithDuration : 1 위치 : 중국 공산당 (0200)]; / / id를 move_back = [이동 리버스]; 아이디 move_ease = [EaseSineInOut actionWithAction : [[이동 복사] autorelease]]; 아이디 move_ease_back = [move_ease 리버스]; 아이디 move2 = [MoveBy actionWithDuration : 1 위치 : 중국 공산당 (0200)]; / / id를 move_back = [이동 리버스]; 아이디 move_ease2 = [EaseSineInOut actionWithAction : [[move2 복사] autorelease]]; 아이디 move_ease_back2 = [move_ease2 리버스]; 아이디 seq1 = [시퀀스 작업 : move_ease, move_ease_back, 무]; / / 아이디 seq2 = [시퀀스 작업 : move_ease2, move_ease_back2,]; 아이디 seq2 = [CCSequence 작업 : [CCDelayTime actionWithDuration : 0.05f], [CCCallFuncN actionWithTarget : 자동 선별 : @ 선택기 (:)], 무] hbar2Repeat 대 0; [hbar1 runAction : [RepeatForever actionWithAction : seq1]]; / / [hbar2 runAction : [DelayTime actionWithDuration : 0.05f]]; / / [hbar2 runAction : [RepeatForever actionWithAction : seq2]]; [hbar2 runAction : seq2];) - (무효) hbar2Repeat : (ID)을 보낸 (id를 move2 = [MoveBy actionWithDuration : 1 위치 : = [EaseSineInOut actionWithAction : [[move2 복사] autorelease]]; 아이디 move_ease_back2 (0200)]; / / id를 move_back = [이동 리버스]; 아이디 move_ease2 중공 = [move_ease2 리버스]; CCRepeatForever * 반복 = [CCRepeatForever actionWithAction : [CCSequence 작업 : move_ease2, move_ease_back2, 무]]; [hbar2 runAction :] 반복;) - @ (NSString *) 제목 (복귀 "구리 바!";) @ 엔드 / * - (무효) 예제 (ID를 행동 = [CCSequence 작업 : [CCDelayTime actionWithDuration : 1], [CCCallFuncN actionWithTarget : 자동 선별 : @ 선택기 (repeatForever :)], 무]; [요정 runAction : 액션];) - (무효) repeatForever : (아이디) (CCRepeatForever * 반복 = [CCRepeatForever actionWithAction : [CCRotateBy actionWithDuration : 2 각도 : 360]]; [발신자 runAction :] 반복 보낸 사람; * /</span>