UNPKG

ycc.js

Version:

Mini and powerful canvas engine for creating App or Game.

98 lines (87 loc) 2.11 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>多边形Polygon测试示例</title> <link rel="stylesheet" href="../style.css"> <meta name=viewport content="width=device-width,initial-scale=1,user-scalable=0,viewport-fit=cover"> </head> <body> <div class="tip"> <h3>示例说明:</h3> <div> 1、这个示例展示系统的多边形UI。<br> 2、蓝色多边形经过了旋转,其旋转中心通过anchorX、anchorY。<br> 3、UI的x、y值可以理解为UI的偏移量,虚线标注了UI旋转、平移之前的位置。<br> </div> <br><br> </div> <div id="canvas"></div> </body> </html> <script src="http://localhost:9000/livereload.js"></script> <script src="../common.js"></script> <script src="../../build/ycc.js"></script> <script> var canvas = document.createElement("canvas"); canvas.width = 300; canvas.height = 400; document.getElementById("canvas").appendChild(canvas); var ycc = new Ycc(); ycc.bindCanvas(canvas); // 新建图层 var layer = ycc.layerManager.newLayer({enableEventManager:true}); var pa = new Ycc.UI.Polygon({ name:"parent", fill:true, fillStyle:'blue', isDrawIndex:true, isShowRotateBeforeUI:true, coordinates:[ {x:10,y:10}, {x:80,y:0}, {x:100,y:100}, {x:0,y:50}, {x:10,y:10}, ], anchorX:10, anchorY:10, rotation:45, ontap:function (e) { console.log(e); } }); layer.addUI(pa); var son = new Ycc.UI.Polygon({ name:"son", fill:true, fillStyle:'red', isDrawIndex:true, isShowRotateBeforeUI:true, coordinates:[ {x:100,y:100}, {x:200,y:100}, {x:200,y:180}, {x:100,y:180}, {x:100,y:100}, ], anchorX:200, anchorY:180, ontap:function (e) { console.log(e); } }); pa.addChild(son); ycc.layerManager.reRenderAllLayerToStage(); layer.onmousemove=function (e) { /*console.log(e); pa.fillStyle="blue"; son.fillStyle="red"; if(pa.containDot(e)) pa.fillStyle="yellow"; if(son.containDot(e)) son.fillStyle="yellow"; ycc.layerManager.reRenderAllLayerToStage();*/ }; layer.ontap = function (e) { console.log('layer -> ',e); }; </script>