如果我将 e1 属性 y 更改为 1 或其他一些正值,则此代码有效,但如果 y 为 0 或负数,则会失败。没有错误,但形状没有出现。如果我绘制其他类型的形状,则会出现同样的问题。无论如何,0、90和271等旋转值与y:0一起工作。x值没有这样的问题。这是为什么?它是与 Crafty.js 相关的错误吗?
<script>
Crafty.init(480,680, document.getElementById('test'));
Crafty.c("myComponent", {
init: function () {
this.requires("2D, Canvas");
this.bind("Draw", this._draw_me);
this.ready = true;
},
_draw_me: function (e) {
var ctx = e.ctx;
ctx.beginPath();
ctx.moveTo(e.pos._x, e.pos._y);
ctx.lineTo(e.pos._x + e.pos._w, e.pos._y);
ctx.lineTo(e.pos._x + e.pos._w/2, e.pos._y + e.pos._h);
ctx.lineTo(e.pos._x, e.pos._y);
ctx.fillStyle = "blue";
ctx.fill();
}
});
var e1 = Crafty.e("myComponent")
.attr({x: 100, y: 0, w: 60, h: 60, rotation:180})
.origin("center");
</script>