0

我正在尝试从 Chris Bowen 的 MSDN 博客中获得一个简单的 Pong 游戏:http: //blogs.msdn.com/b/cbowen/archive/2012/09/19/using-createjs-in-your-javascript-based- windows-商店-game.aspx

我在他的“设置舞台”部分,理论上我应该能够启动应用程序并在我的 Pong 游戏中使用球和桨,但是当我在 Visual Studio 2012 中运行代码时,我收到以下错误:

Exception is about to be caught by JavaScript library code at line 42, column 87 in ms-appx://521809a7-6594-45ba-a60e-bb529eac1299/js/createjs/easeljs-0.5.0.min.js
0x800a139e - JavaScript runtime error: TypeMismatchError
The program '[3756] WWAHost.exe' has exited with code 0 (0x0).

不幸的是,easeljs-0.5.0.min.js 文件已最小化,因此很难看,但我相信这是导致上述行和列出现问题的原因:

var d=this._ctx.createPattern(a,b||"");

下面是我的 default.js 文件:

(function () {
"use strict";

WinJS.Binding.optimizeBindingReferences = true;

var app = WinJS.Application;
var activation = Windows.ApplicationModel.Activation;

app.onactivated = function (args) {
    if (args.detail.kind === activation.ActivationKind.launch) {
        if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
            // TODO: This application has been newly launched. Initialize
            // your application here.
        } else {
            // TODO: This application has been reactivated from suspension.
            // Restore application state here.
        }
        args.setPromise(WinJS.UI.processAll().then(init()));
    }
};

var ball, paddle1, paddle2;
var stage;

function init() {
    stage = new createjs.Stage("gameCanvas");

    ball = new createjs.Shape();
    ball.graphics.beginFill("White");
    ball.graphics.drawCircle(0, 0, 10);
    ball.x = 400;
    ball.y = 300;

    paddle1 = new createjs.Shape();
    paddle1.graphics.beginBitmapFill("White");
    paddle1.graphics.drawRect(0, 0, 20, 100);
    paddle1.x = 20;
    paddle1.y = 300;

    paddle2 = new createjs.Shape();
    paddle2.graphics.beginBitmapFill("White");
    paddle2.graphics.drawRect(0, 0, 20, 100);
    paddle2.x = 760;
    paddle2.y = paddle1.y;

    stage.addChild(ball, paddle1, paddle2);
    stage.update();
}

app.oncheckpoint = function (args) {
    // TODO: This application is about to be suspended. Save any state
    // that needs to persist across suspensions here. You might use the
    // WinJS.Application.sessionState object, which is automatically
    // saved and restored across suspension. If you need to complete an
    // asynchronous operation before your application is suspended, call
    // args.setPromise().
};

app.start();
})();

我的简单 default.html 文件:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Pong</title>

<!-- WinJS references -->
<link href="//Microsoft.WinJS.1.0/css/ui-dark.css" rel="stylesheet" />
<script src="//Microsoft.WinJS.1.0/js/base.js"></script>
<script src="//Microsoft.WinJS.1.0/js/ui.js"></script>

<!-- Pong references -->
<link href="/css/default.css" rel="stylesheet" />
<script src="/js/default.js"></script>
<script src="js/createjs/easeljs-0.5.0.min.js"></script>
</head>
<body>
<canvas id="gameCanvas" width="800" height="600"></canvas>
</body>
</html>
4

1 回答 1

1

您将桨代码更改为beginBitmapFillvs beginFill,但仍在将颜色名称传递给调用,这导致类型不匹配,

根据文档

Graphics beginBitmapFill ( image , repetition )  
   Begins a pattern fill using the specified image. This ends the current subpath. 

Parameters:
   image <object>        The Image, Canvas, or Video object to use as the pattern. 
   repetition <String>   Optional. Indicates whether to repeat the image in the fill area. 
                         One of "repeat", "repeat-x", "repeat-y", or "no-repeat". 
                         Defaults to "repeat". 

Returns:  
   Graphics The Graphics instance the method is called on (useful for chaining calls.)
于 2013-01-06T04:17:06.500 回答