2009-03-20 31 views
9

Tôi đang làm việc trên một trò chơi iphone. Trong đó tôi phải tạo ra những gợn sóng nước. Tôi không biết làm thế nào để có được điều đó. Tôi nghe nói rằng có thể được thực hiện với OpenGL. Tôi rất mới với khái niệm này. Bất kỳ ai có thể hướng dẫn tôi không?Làm thế nào để thực hiện gợn sóng nước?

+0

Bạn có đạt được hiệu quả, sau khi tất cả? – Thanks

Trả lời

3

jk:

z=sin(x)+cos(y) 

Nghiêm trọng hơn, không những Composer thạch anh cơ bản làm gợn sóng cho bạn là một trong những lớp hiệu ứng? Hoặc là đã được công bố chỉ dành cho iPhone 3.0 SDK?

+0

Đó là một thói quen thực sự tốn kém. Nó hoàn toàn sẽ giết OpenGL trong một trò chơi. Tôi đoán anh ta muốn một hiệu ứng nước tốt, có nghĩa là thủ đoạn lập bản đồ kết cấu trường học cũ. – pestilence669

+0

Tha thứ; Tôi biết. Tôi đã nói đùa. – dlamblin

0

Tôi đã tìm thấy mã nguồn của hiệu ứng gợn nước để theo mã để thực hiện vào dự án của bạn và giải quyết vấn đề của bạn.

nhập khẩu "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

Các vấn đề liên quan