(07-06-2014, 12:08 PM)Koh Wrote: Love the swimming animation! Question...I've always wanted to ask this from the programmers; what are you doing to get that water effect? Is it a shader, or a bunch of water objects cycling through the correct ripple tiles?
I actually am not 100% sure myself, since it's not my engine. lemme pull the code out of the water maker, though. you might be able to get something from that
(create event)
nodewidth = waterwidth/16
nodes = floor(waterwidth/nodewidth)+1;
spring = 2;
fricdiv = 1.5;
for (i=0; i<nodes; i+=1;) {
yy[i] = y;
ysp[i] = 0;
frc[i] = ysp[i]/(room_speed/fricdiv);
}
swim = instance_create(x,y+4,obj_swim)
swim.image_xscale = waterwidth/16
swim.image_yscale = waterheight/16
(step event)
var drop;
for (i = 0; i < nodes; i += 1) {
if ((i-1 > -1) && (i+1 < nodes)) {
ysp[i] += ((((yy[i-1]-yy[i])+(yy[i+1]-yy[i]))+(ysp[i-1]+ysp[i+1])))/(room_speed*spring);
ysp[i] += (y-yy[i])/(room_speed*spring);
frc[i] = (ysp[i])/(room_speed/fricdiv);
ysp[i] -= frc[i];
drop = collision_circle(x+(i*nodewidth), yy[i], nodewidth/2, obj_physics, 0, 1);
if (drop) {
if (abs(drop.vspeed) > 0.5){
ysp[i] = divide(drop.vspeed/4, max(1, point_distance(drop.x, 0, x+(i*nodewidth), 0)/16));
}
}
//actually move the node
yy[i] += ysp[i];
}
}
(draw event)
draw_set_blend_mode(bm_add) {
draw_set_color(make_color_rgb(0,128,255));
draw_set_alpha(0.5);
draw_primitive_begin(pr_trianglestrip);
for (i = 0; i < nodes; i += 1)
{
draw_vertex(x+(i*nodewidth), yy[i]);
draw_vertex(x+(i*nodewidth), y+waterheight);
}
draw_primitive_end();
draw_set_alpha(1);
draw_set_color(c_white);
//draw the water's surface
var pth, wid, stp, stp_i, xt, xt_i, sgn, a, a_i, x1, y1, x2, y2, i, px, py, nx, ny, vert_count;
wid = 4; //half the width of water surface
px = x;
py = yy[0];
vert_count = 0;
draw_set_color(c_teal)
draw_primitive_begin_texture(pr_trianglestrip, sprite_get_texture(spr_watertop, 0));
for (i = 0; i < nodes; i += 1)
{
nx = x+(i*nodewidth);
ny = yy[i];
dir = point_direction(px, py, nx, ny);
dx = lengthdir_x(wid, dir+90);
dy = lengthdir_y(wid, dir+90);
xt = (i-1)/nodes;
draw_vertex_texture(px+dx, py+dy, xt, 0);
draw_vertex_texture(px-dx, py-dy, xt, 1);
px = nx;
py = ny;
}
draw_vertex_texture(px+dx, py+dy, xt, 0);
draw_vertex_texture(px-dx, py-dy, xt, 1);
draw_primitive_end();
}
draw_set_blend_mode(bm_normal)