amexudo
May 19th, 2009, 10:25 AM
Hello folks,
i have found a beautiful water effect made in as3. The effect is available to download on the website below.
I am trying to change the fill of the water (that is blue or any color that you pick).
The original code fills the water like this:
public function renderWater():void {
shape.graphics.clear();
shape.graphics.beginFill(0x006699);
shape.graphics.lineStyle(0, 0x000000, 0);
shape.graphics.moveTo(0, 0);
var t:Number = getTimer();
for (var i=0;i<dots.length;++i) {
var dot:Dot = dots[i];
shape.graphics.lineTo(dot.x, dot.y);
}
shape.graphics.lineTo(dots[dots.length-1].x, 300);
shape.graphics.lineTo(0, 300);
shape.graphics.endFill();
}But i have changed it and it looks like this (water.jpg is the texture i am willing to fill the water with):
public function renderWater():void {
var request:URLRequest = new URLRequest("water.jpg");
loader = new Loader(); //this variable was declared as a class variable
loader.load(request);
loader.addEventListener(Event.COMPLETE, onWaterRender);
}
public function onWaterRender(e:Event):void
{
var myBitmap:BitmapData = new BitmapData(loader.width, loader.height, false);
myBitmap.draw(loader, new Matrix());
var matrix:Matrix = new Matrix();
shape.graphics.clear();
//shape.graphics.beginFill(0x006699);
shape.graphics.beginBitmapFill(myBitmap, matrix, true);
shape.graphics.lineStyle(0, 0x000000, 0);
shape.graphics.moveTo(0, 0);
var t:Number = getTimer();
for (var i=0;i<dots.length;++i) {
var dot:Dot = dots[i];
shape.graphics.lineTo(dot.x, dot.y);
}
shape.graphics.lineTo(dots[dots.length-1].x, 300);
shape.graphics.lineTo(0, 300);
shape.graphics.endFill();
}
I tried to follow the instructions on the beginBitmapFill help, but i am receiving the water with no fill.
Can anyone help me?
http://jobemakar.blogspot.com/2007/05/using-wave-physics-to-render-water.html
i have found a beautiful water effect made in as3. The effect is available to download on the website below.
I am trying to change the fill of the water (that is blue or any color that you pick).
The original code fills the water like this:
public function renderWater():void {
shape.graphics.clear();
shape.graphics.beginFill(0x006699);
shape.graphics.lineStyle(0, 0x000000, 0);
shape.graphics.moveTo(0, 0);
var t:Number = getTimer();
for (var i=0;i<dots.length;++i) {
var dot:Dot = dots[i];
shape.graphics.lineTo(dot.x, dot.y);
}
shape.graphics.lineTo(dots[dots.length-1].x, 300);
shape.graphics.lineTo(0, 300);
shape.graphics.endFill();
}But i have changed it and it looks like this (water.jpg is the texture i am willing to fill the water with):
public function renderWater():void {
var request:URLRequest = new URLRequest("water.jpg");
loader = new Loader(); //this variable was declared as a class variable
loader.load(request);
loader.addEventListener(Event.COMPLETE, onWaterRender);
}
public function onWaterRender(e:Event):void
{
var myBitmap:BitmapData = new BitmapData(loader.width, loader.height, false);
myBitmap.draw(loader, new Matrix());
var matrix:Matrix = new Matrix();
shape.graphics.clear();
//shape.graphics.beginFill(0x006699);
shape.graphics.beginBitmapFill(myBitmap, matrix, true);
shape.graphics.lineStyle(0, 0x000000, 0);
shape.graphics.moveTo(0, 0);
var t:Number = getTimer();
for (var i=0;i<dots.length;++i) {
var dot:Dot = dots[i];
shape.graphics.lineTo(dot.x, dot.y);
}
shape.graphics.lineTo(dots[dots.length-1].x, 300);
shape.graphics.lineTo(0, 300);
shape.graphics.endFill();
}
I tried to follow the instructions on the beginBitmapFill help, but i am receiving the water with no fill.
Can anyone help me?
http://jobemakar.blogspot.com/2007/05/using-wave-physics-to-render-water.html