Slice Effect – Fruit Ninja Effect [Actionscript 3.0]

No Comments

Halo teman-teman Flash Indonesia, saya akan berbagi tentang snippet code tentang slice effect.

Kali ini tidak ribet2, cukup copy paste-kan code berikut dan test movie :)

//import sesuai kebutuhan
import flash.display.*;
import flash.events.Event;
import flash.filters.DropShadowFilter;
import flash.filters.GlowFilter;
import flash.geom.*;
import flash.events.MouseEvent;

//definisikan untuk panjang garis yg diinginkan di sini gan
var N:int = 10;
//di dalam kode ini ada sebuah class yang bertipe Vector<> dan bukan bertipe Array
//namun maksudnya sama aja gan, cuman menggunakan vektor lebih enak 
var dotarr:Vector.<Point>  = new Vector.<Point> (N,true);
var canvas:Shape = new Shape();

for (var i:int = 0; i < N; i++) {
	dotarr[i] = new Point(mouseX,mouseY);
}
this.addChild(canvas);
//warna glow pertama #ffffff (tidak kelihatan karena sama dgn warna garis)
var glow0:GlowFilter = new GlowFilter(0xffffff,1,16,16,1,1,true,false);
//warna glow dari garis #3BCC16
var glow1:GlowFilter = new GlowFilter(0x3BCC16,1,6,6,1,1,false,false);
var dropShadow0:DropShadowFilter = new DropShadowFilter(0,90,0x39B310,1,24,24,5,3,false,false,false);
canvas.filters = [glow0,glow1,dropShadow0];

//memberikan event enter frame
this.addEventListener(Event.ENTER_FRAME, onEventEnterFrame);

//memberikan variabel apakah di klik atau tidak
var isClick:Boolean = false;

this.stage.addEventListener(MouseEvent.MOUSE_DOWN, function(e:MouseEvent){
	isClick = true;
	//pada permulaan awal klik, semua nilai dalam variabel dotarr berisi nilai yg sama
	for (var i:int = 0; i < N; i++) {
		dotarr[i] = new Point(mouseX,mouseY);
	}
});
this.stage.addEventListener(MouseEvent.MOUSE_UP, function(e:MouseEvent){
	//saat klik diangkat, mengubah nilai variabel isClick
	isClick = false;
});

function onEventEnterFrame(e:Event):void {
	if(isClick){
		//jika diklik (dan mouse digerakkan), posisi mouse akan dimasukkan ke dalam array dotarr
		dotarr[N - 1].x = mouseX;
		dotarr[N - 1].y = mouseY;
	}
	var _g:Graphics = canvas.graphics;
	_g.clear();
	var _prevPoint:Point = dotarr[0];
	for (var i:int = 1; i < N; ++i) {
		var _prev:Point = dotarr[i - 1];
		var _current:Point = dotarr[i];
		//mengubah warna garis di sini variabel i merupakan ketebalan (dimulai dari yg
		//paling tipis)
		_g.lineStyle(i, 0xffffff, 1, true, "none", "round", "round");
		var _point:Point = new Point(
		                    _prev.x + (_current.x - _prev.x) / 2,
		                    _prev.y + (_current.y - _prev.y) / 2);
		_g.moveTo(_prevPoint.x,_prevPoint.y);
		//ini nih yang bisa bikin melengkung
		_g.curveTo(_prev.x,_prev.y,_point.x,_point.y);

		_prevPoint = _point;
		_prev.x = _current.x;
		_prev.y = _current.y;
	}
}

Maka hasilnya seperti ini :

VN:F [1.9.8_1114]
Rating: 8.4/10 (85 votes cast)
VN:F [1.9.8_1114]
Rating: +19 (from 21 votes)
Slice Effect - Fruit Ninja Effect [Actionscript 3.0], 8.4 out of 10 based on 85 ratings

This is author biographical info, that can be used to tell more about you, your iterests, background and experience. You can change it on Admin > Users > Your Profile > Biographical Info page."

 

More from our blog

See all posts
No Comments
  1. Reply

    Your comment is awaiting moderation.

    Terimakasih tutorialnya bermanfaat banget, aku juga punya nih Tutorial Gratis

    VA:F [1.9.8_1114]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.8_1114]
    Rating: 0 (from 0 votes)
 

Leave a Comment

[+] kaskus emoticons nartzco