我使用canvasengine来编写我的HTML5游戏。我已经实现了一个平铺地图,到目前为止它是有效的,但是静态的。
现在我想让玩家有移动的能力。所以我想:“好的,我使用canvasengine skew命令”。这是可行的:
canvas.Scene.new ({
name: "tutorial",
materials: {
images: {
dg_edging232: "/maps/tilesets/dg_edging232.gif"
}
},
ready: function(stage) {
this.el = this.createElement();
var tiled = canvas.Tiled.new ();
tiled.load(this, this.el, "/maps/tutorial.json");
tiled.ready(function() {
var tile_w = this.getTileWidth(),
tile_h = this.getTileHeight(),
layer_object = this.getLayerObject();
stage.append(this.el);
});
},
render: function(stage) {
canvas.Input.keyDown(Input.Left);
canvas.Input.keyDown(Input.Right);
canvas.Input.keyDown(Input.Up);
canvas.Input.keyDown(Input.Down);
stage.refresh();
}
});现在,我想这样做:
canvas.Input.keyDown(Input.left,this.el.x--);但是我不能用上面的语法让它工作。
发布于 2013-05-07 00:16:15
从未使用过此库,但看起来您可能希望将渲染中的keyDown调用移动到ready,并在渲染时测试是否按下了键,并相应地移动精灵。
ready: function () {
// ... your ready code
// It's not clear from the docs, but it appears like you need to call
// keyDown for each input to register it, even if you're passing no callbacks.
// However, I'm guessing here. This may not be necessary.
canvas.Input.keyDown(Input.Left);
// ... and so on for each direction
},
render: function () {
// every frame test if the key is down, and update the sprite accordingly
if (canvas.Input.isPressed(Input.Left)) this.el.x--;
// ... and so on for each direction
stage.refresh();
}https://stackoverflow.com/questions/16398658
复制相似问题