Lufylenged引擎學習——LGraphics

一喵嗚發表於2015-08-17


(一)在一個LSprite上畫一張圖,new另一個Sprite進行圖片的mask效果 ,效果如下:

<!DOCTYPE HTML>
<html>
<head>
	<meta charset="utf-8" />
	<script type="text/javascript" src="../lufylegend-1.7.6.min.js"></script> 
</head>
<body>
<div id="mylegend">loading...</div>
<script type="text/javascript">
var loader;  
init(50,"mylegend",500,350,main);

function main(){  
    loader = new LLoader();  
    loader.addEventListener(LEvent.COMPLETE,loadBitmapdata);  
    loader.load("face.jpg","bitmapData");  
}  
function loadBitmapdata(event){  
    var bitmapdata = new LBitmapData(loader.content);
    var bitmap = new LBitmap(bitmapdata);  
 	//加入層LSprite
    var layer = new LSprite();
    addChild(layer);
    layer.x = 50;
    layer.y = 50;
    layer.rotate = 60;
    layer.addChild(bitmap);

    var layer2 = new LSprite();
    addChild(layer2);
    layer2.graphics.drawRect(1,"#FCF",[50,0,140,140]);
    layer.mask = layer2;
} 
</script>
</body>
</html>

(二)drawRect的兩個屬性效果對比

<!DOCTYPE HTML>
<html>
<head>
	<meta charset="utf-8" />
	<script type="text/javascript" src="../lufylegend-1.7.6.min.js"></script> 
</head>
<body>
<div id="mylegend">loading...</div>
<script type="text/javascript">
init(50,"mylegend",500,350,main);
function main(){  
   var layer = new LSprite();
   addChild(layer);
   layer.graphics.drawRect(1,'#000000',[50,50,100,100]);
   layer.graphics.drawRect(1,'#000000',[170,50,100,100],true,'#cccccc');
}  
</script>	
</body>
</html>


效果如下:



(三)線條的繪製

init(50,"mylegend",500,350,main);
function main(){  
	var graphics = new LGraphics();
	addChild(graphics);
	graphics.add(function(coodx,coody){
		LGlobal.canvas.strokeStyle = "#000000";
		LGlobal.canvas.moveTo(20,20);
		LGlobal.canvas.lineTo(200,200);
		LGlobal.canvas.stroke();
	});
} 


(四)畫圓、三角形、四邊形 用點陣圖影像填充繪圖區。

			LInit(50, "legend", 800, 480, main);
			function main () {
				var loader = new LLoader();
				loader.addEventListener(LEvent.COMPLETE, loadBitmapdata); 
				loader.load("face.jpg", "bitmapData");
			}
			function loadBitmapdata (event) {
				var bitmapdata = new LBitmapData(event.target);  
				var backLayer;
				backLayer = new LSprite();
				addChild(backLayer);
				backLayer.graphics.beginBitmapFill(bitmapdata);
				backLayer.graphics.drawArc(1,"#000000",[150,50,50,0,Math.PI*2]);
				backLayer = new LSprite();
				addChild(backLayer);
				backLayer.graphics.beginBitmapFill(bitmapdata);
				backLayer.graphics.drawRect(1,"#000000",[10,100,70,100]);
				backLayer = new LSprite();
				addChild(backLayer);
				backLayer.graphics.beginBitmapFill(bitmapdata);
				backLayer.graphics.drawVertices(1,"#000000",[[120,100],[100,200],[200,150]]);
			}
			

drawVertices  分別繪製的是三個∠ 點的座標值,

而drawRect  畫出左上角的座標值 然後分別賦值寬 高值

 backLayer.graphics.drawArc(1,"#000000",[150,100,50,0,Math.PI*2]);  

150,100為圓點座標、50為半徑、0,為起始角、Math.PI*2為結束角






相關文章