I'm working on an iphone game. In that i had to produce water ripples. I dont know how to get that. I heard thatit can be done with openGL. I am very new to this concept. Can any one guide me?
Asked
Active
Viewed 1.3k times
9
-
Did you achieve the effect, after all? – Thanks Jul 25 '09 at 09:25
3 Answers
14
Here are some resources I found:
Language Agnostic 2d Water Ripple Algorithm
(source: virgin.net)
(source: virgin.net)
OpenGL Project with Water Ripples (Source)
(source: sulaco.co.za)
You also might want to swing by GameDev's FAQ. Scroll down to the "Water Rendering" section.

Glorfindel
- 21,988
- 13
- 81
- 109

mmcdole
- 91,488
- 60
- 186
- 222
2
jk:
z=sin(x)+cos(y)
More seriously, doesn't the Quartz Composer basically do ripples for you as one of the effects layers? Or was that announced only for the iPhone 3.0 SDK?

dlamblin
- 43,965
- 20
- 101
- 140
-
That's a really expensive routine. It would absolutely kill OpenGL in a game. I'm guessing he wants a decent water effect, which means old-school texture mapping tricks. – pestilence669 Jan 19 '10 at 00:58
-
0
I found the source code of the water ripple effect so following code to implement into your project and solove your problem also.
import "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

Community
- 1
- 1

Nimit Parekh
- 16,776
- 8
- 50
- 72