我有很多問題試圖在動力學層上創建一個圓。基本上我試圖創建一個繪畫應用程序,但我想我需要一次解決這個問題。所以我只是想能夠從字面上拖放一個圓圈。我有一些東西,但我知道它絕對充滿了錯誤。請,我真的很需要一些指導,我很久沒有使用KineticJs或JavaScript了,所以我很想知道這是如何工作的。謝謝你,有一個美好的一天!使用Kinectjs製作圈子
<!DOCTYPE html>
<html>
<head>
<meta chartset="utf-8">
<title>Creating a Cirlce</title>
<style type="text/css">
body {
margin: 0px;
padding: 0px;
}
</style>
</head>
<body>
<script type="text/javascript" src="kinetic-v4.5.4.min.js"></script>
<div id="container"></div>
<script type="text/javascript">
window.onload = function() {
var stage = new Kinectic.Stage({
container: "container",
width: 400,
height: 400
});
var layer = new Kinetic.Layer();
background = new Kinetic.Rect({
x: 0,
y: 0,
width: stage.getWidth(),
height: stage.getHeight(),
fill: "white"
});
var Circle = new Kinetic.Circle({
x: 0,
y: 0,
radius: 0,
fill: "red",
stroke: "black",
strokeWidth: 4
});
layer.add(background);
layer.add(Circle);
stage.add(layer);
var moving = false;
stage.on("mousedown", function(){
if (moving) {
moving = false;
layer.draw();
}
else {
var pos = stage.getMousePosition();
moving = true;
Circle.x = pos.x;
Circle.y = pos.y
Circle.radius = 0;
layer.drawScene();
}
});
stage.on("mousemove", function(){
if (moving) {
var pos = stage.getMousePosition();
var x = pos.x;
var y = pos.y;
Circle.x = pos.x;
Cirlce.y = pos.y;
Cirlce.radius = 0.5 * Math.sqrt(Math.pow(x,2)+Math.pow(y,2));
Cirlce.fill = "red";
Circle.stroke = "black";
Cirlce.strokeWidth = 1;
}
});
stage.on("mouseup", function() {
moving = false;
})
}
</script>
</body>
小提琴在Chrome Win8中似乎不適合我。 –
@CoryGross謝謝,我忘了以前的KineticJS和Chrome有填充導致失敗的問題。我把最新的KineticJS放在小提琴上,它現在應該工作。感謝您的領導! – markE
沒問題,不錯的演示! –