码迷,mamicode.com
首页 > 其他好文 > 详细

Lufylenged引擎学习——LGraphics

时间:2015-08-17 19:40:16      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

(一)在一个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为结束角


技术分享



版权声明:本文为博主原创文章,未经博主允许不得转载。

Lufylenged引擎学习——LGraphics

标签:

原文地址:http://blog.csdn.net/html5_/article/details/47728381

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!