Javascript 未捕获类型错误:无法调用方法';添加';未定义的类型(动态js)

Javascript 未捕获类型错误:无法调用方法';添加';未定义的类型(动态js),javascript,jquery,html5-canvas,kineticjs,Javascript,Jquery,Html5 Canvas,Kineticjs,我正在尝试制作一个游戏,其中使用kineticjs制作多个圆形对象 以下是html: <!DOCTYPE html> <html> <head> <title>TODO supply a title</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width"&g

我正在尝试制作一个游戏,其中使用kineticjs制作多个圆形对象

以下是html:

<!DOCTYPE html>
<html>
    <head>
        <title>TODO supply a title</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width">
        <link rel="stylesheet" href="../css/style.css"/>
    </head>
    <body>
        <!--<canvas id="canvasRegn" width="600" height="450" style="margin:100px;"></canvas>-->
        <div id="container" style="width: auto; height: auto; background:#000; margin:auto; float:left;"></div>
        <script src="../js/jquery.min.js"></script>
        <script src="../js/kinetic-v5.0.0.min.js"></script>
        <script type="text/javascript" src="../js/rain2.js"></script>
    </body>
</html>
我的最终目标是在游戏中制造敌人:

这是小提琴:

在创建图层对象之前,您正在调用
CreateEquire
,因此在调用
CreateEquire
时,变量
layer
值未定义

var stage = new Kinetic.Stage({
    container: 'container',
    width: window.innerWidth,
    height: window.innerHeight,
    listening: true
});
var layer = new Kinetic.Layer({
    listening: true
});

//need to call it after the layer is created
createEnemy();
演示:


您可能还想了解一下

错误似乎已被删除,thnx。但是红色敌人的物体没有移动。。。知道为什么吗?编辑:无需担心。。。我明白了:)Thanx:)@NevinMadhukarK
setInterval()
被注释掉了是的,我刚刚做到了。。thnx:)
html {
    color:#000;
    background:#222222;
}
a {
    cursor:pointer;
    list-style: none;
}
html, body {
    width: 100%;
    height: 100%;
    margin: 0px;
    padding: 0px;
    overflow: hidden;
}
html, body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, code, form, fieldset, legend, input, textarea, p, blockquote, th, td {
    margin:0;
    padding:0;
}
#container {
    background:#000;
    margin:auto;
    cursor:none;
    float:left;
    width:auto;
    height: auto;
}
var stage = new Kinetic.Stage({
    container: 'container',
    width: window.innerWidth,
    height: window.innerHeight,
    listening: true
});
var layer = new Kinetic.Layer({
    listening: true
});

//need to call it after the layer is created
createEnemy();