0

我是电话间隙和画架的新手。我正在尝试在我的 android 表上运行我的重力球应用程序。当我尝试在平板电脑上通过 eclipse 运行应用程序时,LogCat 出现错误:

05-27 15:48:57.180:E/Web 控制台(22640):未捕获的 ReferenceError:createjs 未在文件中定义:///android_asset/www/index.html:144

我在下面附上我的代码。有人可以帮我为什么这不起作用吗?感谢你

头:

<script type="text/javascript" src="../src/easeljs/ui/Touch.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.min.js"></script>
<script type="text/javascript" charset="utf-8" src="cordova-2.7.0.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" charset="utf-8">


    // The watch id references the current `watchAcceleration`
    var watchID = null;
    var accX,accY,accZ;
    // Wait for Cordova to load
    //
    function onLoad() {
        document.addEventListener("deviceready", onDeviceReady, false);
    }

    // Cordova is ready
    //
    function onDeviceReady() {

        startWatch();

        // Register the event listener

    }
    //get locale time zone for the device
    function checkLocale() {
        navigator.globalization.getLocaleName(
                function (locale) {alert('locale: ' + locale.value + '\n');},
                function () {alert('Error getting locale\n');}
        );
    }

    // onSuccess: Get a snapshot of the current acceleration
    //
    function onSuccess(acceleration) {

        //var element = document.getElementById('deviceAcceleration');

        accX = acceleration.x;
        accY = acceleration.y;
        accZ = acceleration.z;

    }  

    // Start watching the acceleration
    //
    function startWatch() {

        // Update acceleration every 10th of a seconds
        var options = { frequency: 100 };

        watchID = navigator.accelerometer.watchAcceleration(onSuccess, onError, options);
    }

    // Stop watching the acceleration
    //
    function stopWatch() {
        if (watchID) {
            navigator.accelerometer.clearWatch(watchID);
            watchID = null;
        }
    }


    // onError: Failed to get the acceleration
    //
    function onError() {
        alert('onError!');
    }

以下是正文中的脚本:

var canvas;
var FPS = 40;

//Create a stage by getting a reference to the canvas
var stage;

//var bricks =[]
var balls = [];
//var paddle;

//initiates the applet
function init() {

    var ballImg = new Image();
    ballImg.src = "ball.gif";

    //var brickImg = new Image();
    //brickImg.src = "";

    var paddleImg = new Image();
    paddleImg.src = "";

    canvas = document.getElementById('canvas');
    //get the window dimensions
    canvas.width = window.innerWidth;
    canvas.height = window.innerHeight;

    stage = new createjs.Stage(canvas);

    createjs.Touch.enable(stage);

    var ball = new createjs.Bitmap(ballImg);
    ball.height = 120;
    ball.width = 120;
    //center of the object
    ball.radius = ball.height/2;
    ball.x = accX;
    ball.y = accY;
    ball.z = accZ;
    ball.velx = ball.vely =  ball.velz = 0;
    ball.acc = 0;
    balls.push(ball);
    stage.addChild(ball);

    createjs.Ticker.addEventListener("tick",repaint);
    createjs.Ticker.setFPS(FPS);

}


function moveBall(ball){
    //var velocity = Math.sqrt((accX*accX) +(accY*accY));
    //var xAccMag = Math.abs(accX);
    //var yAccMag = Math.abs(accY);

    //if the ball is on the edges of the canvas
    if(ball.x + ball.radius >= canvas.width){
        ball.velx *= -0.85;
        ball.vely *= 0.95;
        ball.x = canvas.width - ball.radius;
    }else if(ball.x - ball.radius <= 0){
        ball.velx *= -0.85;
        ball.vely *= 0.95;
        ball.x =  ball.radius;
    }else if(ball.y + ball.radius >=canvas.height){
        ball.velx *= 0.9;
        ball.vely *= -0.85;
        ball.y = canvas.height - ball.radius;
    }else if(ball.y - ball.radius <=0){
        ball.velx *= 0.9;
        ball.vely *= -0.85;
        ball.y= ball.radius;
    }

    ball.velx + (accX*(-1));
    ball.vely + accY;
}

function repaint(){
    moveBall(balls[0]);
    var rotation = ball.velx * FPS/1000;
    var ball = balls[0];
    ball.y += ball.vely * FPS/1000;
    ball.x += ball.velx * FPS/1000;

    ball.rotation += rotation;
    //clamp rotation
    ball.rotation = ball.rotation%360;
    stage.update();
}

$(document).ready( function () {
    init();
});

4

0 回答 0