向javascript项添加文本

时间:2015-08-16 17:38:46

标签: javascript

有没有办法让我在Javascript中为sprite添加文本,这样每个人都可以给它自己的号码而不必编辑图片?

我正在使用一个简单的匹配游戏described here。目前要显示数字,必须更改图像资源。

<!DOCTYPE html>
<html>
   <head>
     <title>BakerIce</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script type ="text/javascript"
    src ="simpleGame.js"></script>
    <script type="text/javascript">

        var game;
        var iC;
        var iB;

        function cone() {
            TiC = new Sprite(game,"ICE-Cream-cone.png",150,150);
            TiC.setSpeed(0);
            TiC.setBoundAction(CONTINUE);
            TiC.setPosition(200,400);

            TiC.checkDrag = function(){
                if(TiC.isMouseDown()){
                    TiC.setX(document.mouseX);
                    TiC.setY(document.mouseY);
                }
            }; 
            return TiC; 
        }
        function box(){
            TiB = new Sprite(game,"Ice-Cream-Box.png",200,200);
            TiB.setSpeed(0);
            TiB.setBoundAction(CONTINUE);
            TiB.setPosition(400,250);
            TiB.addText = function(text){
                var Text = text;
            };
            return TiB;
        }
        function init() {
            console.log("Begin Init");
            game = new Scene();

            iC = new cone();
            iC.checkDrag();
            iB = new box();
            iB.addText(1/2);
            game.setBG("orange");
            game.start();
            console.log("End Init");
        }
        function update() {
            // console.log("Begin Update");

            game.clear();
            iB.update();
            iC.update();
            iC.checkDrag();

            // console.log("End Update");
        }

    </script>

</head>
<body onload = "init()">

</body>

0 个答案:

没有答案