我使用canvasengine对我的HTML5游戏进行编程。我已经实现了一个平铺的 map ,目前可以使用,但是是静态的。
现在,我希望玩家能够移动。因此我想:“好吧,我使用canvasengine歪斜命令”。这有效:
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--);
但是我无法使其与上述语法一起使用。
最佳答案
从未使用过此库,但似乎您可能希望将render中的keyDown
调用移动到ready
,并在渲染时测试是否按下了键并相应地移动了sprite。
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();
}
关于javascript - 如何在canvasengine中倾斜平铺的 map ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16398658/