2009-03-20 6 views
9

나는 아이폰 게임을하고있다. 나는 물결을 일으켜야했다. 나는 그것을 어떻게 얻는 지 모른다. 나는 그것이 OpenGL로 할 수 있다고 들었다. 나는이 개념에 대해 아주 새로운 것입니다. 아무도 나를 안내 할 수 있습니까?물 잔물결을 구현하는 방법은 무엇입니까?

+0

당신은 결국 효과를 얻을나요? – Thanks

답변

3

JK :

더 심각
z=sin(x)+cos(y) 

, 쿼츠 컴포저 기본적으로 효과 레이어의 하나로서 당신을 위해 잔물결을하지 않는 이유는 무엇입니까? 아니면 iPhone 3.0 SDK에서만 발표 되었습니까?

+0

그건 정말 비싼 루틴입니다. 그것은 게임에서 OpenGL을 절대적으로 없애 버릴 것입니다. 나는 낡은 학교의 텍스처 맵핑 트릭을 의미하는 적당한 물 효과를 원한다고 생각합니다. – pestilence669

+0

사면; 알아. 농담 이었어. – dlamblin

0

물 리플 효과의 소스 코드를 발견하여 프로젝트에 구현하고 문제를 해결하는 코드를 따르십시오.

수입 "HelloWorldLayer.h"

// HelloWorldLayer implementation 
@implementation HelloWorldLayer 

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

    // 'layer' is an autorelease object. 
    HelloWorldLayer *layer = [HelloWorldLayer 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])) { 

     rippleImage = [ pgeRippleSprite ripplespriteWithFile:@"image_old.png" ]; 
     [ self addChild:rippleImage ]; 
     CCLabelTTF *label = [CCLabelTTF labelWithString:@"Hello Cocos2D Forum" fontName:@"Marker Felt" fontSize:16]; 
     label.position = ccp(80 , 300); 
     [self addChild: label]; 
     [ [ CCTouchDispatcher sharedDispatcher ] addTargetedDelegate:self priority:0 swallowsTouches:YES ]; 

     // schedule update 
     [ self schedule:@selector(update:) ];  

    } 
    return self; 
} 

float runtime = 0; 

-(BOOL)ccTouchBegan:(UITouch*)touch withEvent:(UIEvent*)event { 
    runtime = 0.1f; 
    [ self ccTouchMoved:touch withEvent:event ]; 
    return(YES); 
} 

-(void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event { 
    CGPoint pos; 

    if (runtime >= 0.1f) { 

     runtime -= 0.1f; 

     // get touch position and convert to screen coordinates 
     pos = [ touch locationInView: [ touch view ] ]; 
     pos = [ [ CCDirector sharedDirector ] convertToGL:pos ]; 

     // [ rippleImage addRipple:pos type:RIPPLE_TYPE_RUBBER strength:1.0f ];  
     [ rippleImage addRipple:pos type:RIPPLE_TYPE_WATER strength:2.0f ]; 


    } 
} 

-(void)update:(ccTime)dt { 

    runtime += dt; 

    [ rippleImage update:dt ]; 
} 

// 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 

Also you can download the source code from the Git

관련 문제