我正在使用 Jaws 框架编写一个小游戏。我想使用 KineticJS 在我的画布上下文中绘制一些形状。是否可以直接在上下文上绘制形状而无需先创建舞台和图层?就像是
var circle = new Kinetic.Circle({...params...);
circle.draw(myContext);
我正在使用 Jaws 框架编写一个小游戏。我想使用 KineticJS 在我的画布上下文中绘制一些形状。是否可以直接在上下文上绘制形状而无需先创建舞台和图层?就像是
var circle = new Kinetic.Circle({...params...);
circle.draw(myContext);
I believe each KineticJS object has drawFunc as its property. If you can take that one out and apply to canvas directly, you won't need stage or layer,I guess.
Trying ...
Hmm .. no. drawFunc is using object dependent properties. i.e. this.getRadius().
However, you still can see how it is drawn by printing out the drawFunc
<script src="http://www.html5canvastutorials.com/libraries/kinetic-v4.3.0-beta2.js"></script>
<script>
var circle = new Kinetic.Circle({
x: 250,y: 250, radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4
});
console.log(circle.drawFunc);
</script>
Here is the output of that console.log command.
function (canvas) {
var context = canvas.getContext();
context.beginPath();
context.arc(0, 0, this.getRadius(), 0, Math.PI * 2, true);
context.closePath();
canvas.fillStroke(this);
}