zoukankan      html  css  js  c++  java
  • createjs 利用createjs 写拼图功能

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
    </head>
    <body>
        <canvas id="canvas" width="400" height="400" style="background-color:#ccc;"></canvas>
        <script src="../js/createjs/easeljs-NEXT.combined.js"></script>
        <script>
            var canvas = document.getElementById("canvas");
            var stage = new createjs.Stage(canvas);//创建舞台(画布)
            var shape2 = new createjs.Shape();
            ///
            shape2.graphics.beginFill("pink").beginStroke("#fff").setStrokeStyle(4).moveTo(0, 0).lineTo(canvas.width, 0).lineTo(canvas.width, canvas.height * .4).lineTo(0, canvas.height * .6).closePath();
            stage.addChild(shape2);
            stage.update();
            var img = new Image();
            img.onload = function () {
                var bmp = new createjs.Bitmap(this);
                stage.addChild(bmp);
                bmp.mask = shape2;
                stage.update();
                bmp.addEventListener("mousedown", function (e) {
                    var disX = e.stageX - bmp.x;
                    var disY = e.stageY - bmp.y;
                    document.onmousemove = function (e) {
                        bmp.x = e.clientX - disX;
                        bmp.y = e.clientY - disY;
                        stage.update();
                    };
                    document.onmouseup = function (e) {
                        document.onmousemove = null;
                        document.onmouseup = null;
                    };
                }, false);
            }
            img.src = "../img/10.jpg";
            ///
            var shape3 = new createjs.Shape();
            shape3.graphics.beginFill("yellow").beginStroke("#fff").setStrokeStyle(4).moveTo(0, canvas.height * .6).lineTo(canvas.width, canvas.height * .4).lineTo(canvas.width,canvas.height).lineTo(0,canvas.height).closePath();
            stage.addChild(shape3);
            stage.update();
            var img2 = new Image();
            img2.onload = function () {
                var bmp = new createjs.Bitmap(this);
                stage.addChild(bmp);
                bmp.mask = shape3;
                stage.update();
                bmp.addEventListener("mousedown", function (e) {
                    var disX = e.stageX - bmp.x;
                    var disY = e.stageY - bmp.y;
                    document.onmousemove = function (e) {
                        bmp.x = e.clientX - disX;
                        bmp.y = e.clientY - disY;
                        stage.update();
                    };
                    document.onmouseup = function (e) {
                        document.onmousemove = null;
                        document.onmouseup = null;
                    };
                }, false);
            };
            img2.src = "../img/20.jpg";
    
            //createjs.Ticker.addEventListener('tick', function (e) {
            //    img.x += 10;
            //    stage.update();
            //});
        </script>
    </body>
    </html>
  • 相关阅读:
    ES6 Promise 用法转载
    移动端滚动性能优化
    Python之禅
    Day01~15
    Python
    第一章 Java起源
    IMP-00009: 导出文件异常结束 imp
    浏览器访问网页的详细内部过程
    数据库连接池
    连接数据库 六大步骤
  • 原文地址:https://www.cnblogs.com/LLJ748211490/p/createjs.html
Copyright © 2011-2022 走看看