Javascript 我的乒乓球游戏不适用于Windows 8、Visual Studio 2012和easeljs
我试图从Chris Bowen的MSDN博客中获得一个简单的乒乓球游戏: 我在他的“设置舞台”部分,理论上我应该能够启动应用程序,并在我的乒乓球游戏中使用球和桨,但当我在Visual Studio 2012中运行代码时,我得到以下错误:Javascript 我的乒乓球游戏不适用于Windows 8、Visual Studio 2012和easeljs,javascript,windows-8,easeljs,Javascript,Windows 8,Easeljs,我试图从Chris Bowen的MSDN博客中获得一个简单的乒乓球游戏: 我在他的“设置舞台”部分,理论上我应该能够启动应用程序,并在我的乒乓球游戏中使用球和桨,但当我在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
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||"");
下面是我的默认.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>
庞
您将拨片代码更改为beginBitmapFill
而不是beginFill
,但仍在调用中传递颜色名称,这导致类型不匹配
,
Graphics beginBitmapFill(图像,重复)
使用指定的图像开始填充图案。这将结束当前子路径。
参数:
图像要用作图案的图像、画布或视频对象。
重复是可选的。指示是否在填充区域中重复图像。
“重复”、“重复x”、“重复y”或“不重复”中的一个。
默认为“重复”。
返回:
图形调用该方法的图形实例(用于链接调用)
啊!感谢您详细阅读我的代码。我在Visual Studio中选择了错误的自动完成:(这解决了问题。动态类型语言的乐趣:(
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.)