oh, I thought u meant the wavey water affect console platformers tend to have.
If that is what you want, then your kinda screwed. I believe consoles did it in hardware, to achieve the same affect in java2d you would have to do it through per-pixel rendering, which would prevent you taking advantaged of hardware accelerated blitting.
It's pretty simple to get the water to wobble without messing about with things on the per-pixel level, and you *can* get hardware acceleration.
It's not a perfect solution but the effect is cool. All's I done was chop a loaded image up into 1 pixel length widths (so you're left with long thin image strips) then just wobble them in order, I suppose you could use a sine wave to control the wobble.
spose that'd work.... I was thinking of a more complex wavey effect ^_^
Though in a tile based platformer, from a performance perspective, that will increase the number of blits by a factor of TILE_WIDTH.
Unless you introduce an intermediary VolatileImage, and apply the wave affect after the frame has been rendered. That would only increase the number of blits by SCREEN_WIDTH+1.
>I was thinking of a more complex wavey effect ^_^
I could have guessed :)
As far as performance goes I think you could get away with just creating a small 64*64 block strip and applying the wobble on that, then tile that image, but you'd have to make sure the wave was even, else it would look awful. It's not ideal but I don't think it would be that much of a problem, and of course, this only reduces the wobble calculations which aren't very complicated anyway.
I've still got two horrible examples of this lying around on my comp, although these examples wobble a 320/240 image, and the fps didn't budge, and they weren't hardware accelerated. The things you do when bored :)
I was thinking more along the lines of just wobbling an image that you could place on your map that represents water, I didn't read luisoft post properly :) For example; draw the background then the water then the platforms, making sure that the platform draws over the bottom of the wobble/water image as this will also be wobbling :)
Wobbling the whole tile set would be a pain to say the least, but it would look a bit poo if it was only the background that was wobbling and the collision tiles where still. But you could experiment with making 64*64 wobbles and tiling them, but you are going to be drawing a lot of images.
I suppose you could just draw your level as normal and wobble a transparent image with white lines over the top of the scene but that would look a bit cheap, but if hardware translucent image where always supported this could work quite well.
lmao, just for some fun, I implemented it into the racing game im working on atm.
I now know why cars don't drive underwater ;)
The code is pretty simple actually, and the effect is..... interesting :D
1st off, create the displacement map for each column of the screen
The columns can be any width, mine are 1 pixel.
int [] disMap = new int[SCREEN_WIDTH];
for(int i = 0;i < SCREEN_WIDTH;i++)
{
disMap[i] = (int)(Math.sin((i*Math.PI*4)/SCREEN_WIDTH)*10);
}
int disStart = 0;//the offset into the displacement map, increment each game loop
Then create your VolatileImage to use as the intermediary buffer
VolatileImage waterBuffer = createVolatileImage(SCREEN_WIDTH,SCREEN_HEIGHT);
Now, modify your game code so instead of blitting directly to the BufferStrategys back buffer, blit to the waterBuffer instead.
//Graphics2D bg = (Graphics2D)bs.getDrawGraphics();
Graphics2D bg = waterBuffer.createGraphics();
Now, after all your render code, and before you call bufferStrategy.show(), add the code to blit the waterBuffer to the bufferStrategys back buffer. (applying the water affect)
Graphics g = bs.getDrawGraphics();
for(int i = 0;i < SCREEN_WIDTH;i++)
{
g.setClip(i,0,1,SCREEN_HEIGHT);
g.drawImage(waterBuffer,0,disMap[(i+disStart)%SCREEN_WIDTH],null);
}
disStart++;
bs.show();
Has no affect on fps at all either :)
Though im sure in a more taxing game it could cause problems (all that extra blitting is using alot of extra memory bandwidth on the graphics card)
And if it were running on a system that didn't implement VolatileImages in vram (think Mac :P), all the extra mem copies would absolutely kill the framerate.
hmm, I just rethought that code a little, and dthe isplacement map doesn't need to be as wide as the screen. You just need to precompute a sufficiently large range to get a nice sine wave, and then index into the array using the columns x offset [modding it into range].
but hey, that code works, and it was just an experiment ;)
Hehe, nice one Abuse, the way as I was doing it was *very* simple, rather than use a sine wave I was just using a bit character jumping code to control the wave :), ugh, hey it was a 2minute bodge :)
A 4k water shooter sounds interesting, if you can pile in some translucency effects behind it as well, you could probably melt some heads :D
Mwhuhewowwhaa, I'm can't spell evil laughter.
Just thought, you could make this effect more interesting...
At them moment the wobble effect is only happening in the y-axis, so it's only fair that you should wobble it on the x-axis as well, create another buffer that wobbles on the x and blit your y-wobble to that.
Wobble-tastic :)
A really good drunk effect without the preceding head throb sounds useful :)
I had no idea the createGraphics method was that fast, I've only ever used that for pre-calculated stuff, I somehow got the idea that's all it's good for :/ lots of possibilities there though :)
If only the image methods for get pixel colour and set pixel colour where that nippy :D