9

iphoneのゲームをやっています。その中で、水の波紋を作らなければなりませんでした。私はそれを取得する方法がわかりません。openGLでできると聞きました。私はこの概念に非常に慣れていません。誰でも私を案内できますか?

4

3 に答える 3

14

ここに私が見つけたいくつかのリソースがあります:

言語にとらわれない 2D ウォーター リップル アルゴリズム(出典: virgin.net ) (出典: virgin.net )
代替テキスト
代替テキスト

水の波紋を伴う OpenGL プロジェクト (出典) (出典: sulaco.co.za )
代替テキスト

また、GameDev の FAQも参照してください。「水のレンダリング」セクションまでスクロールします。

于 2009-03-20T05:47:19.580 に答える
2

JK:

z=sin(x)+cos(y)

もっと深刻なことに、Quartz Composer は基本的に、エフェクト レイヤーの 1 つとして波紋を作成しますか? それとも、iPhone 3.0 SDK だけで発表されたのですか?

于 2009-03-20T05:47:48.627 に答える
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

また、Git からソース コードをダウンロードすることもできます。

于 2012-10-23T06:10:44.067 に答える