10
A
回答
12
就像Tz说的那样,你必须在自己身上建立所有的持久性。但这决不意味着难以做到。我已经写了一对夫妇短片tutorials,如果你要完成这项任务,这将使你开始。
5
我认为这是画布后面没有对象模型,所以你不能访问“子对象”就像一个“文本对象”改变。 你可以做的是用不同的颜色重写文本,覆盖画布的“像素”。 如果要移动文本,首先必须清除画布或使用背景/透明颜色重新绘制文本以摆脱先前位置中的文本。然后,您可以在新位置绘制文字。
4
希望允许广告某人的项目。
看看http://ocanvas.org/你可以在那里获得灵感。 像画布库那样的对象。允许你处理事件,制作动画等。
3
我从来没有尝试过,但我认为这将是实现它的方式。
var canvas = document.getElementById("canvas"); //get the canvas dom object
var ctx = canvas.getContext("2d"); //get the context
var c = { //create an object to draw
x:0, //x value
y:0, //y value
r:5; //radius
}
var redraw = function(){ // this function redraws the c object every frame (FPS)
ctx.clearRect(0, 0, canvas.width, canvas.height); // clear the canvas
ctx.beginPath(); //start the path
ctx.arc(c.x, c.y, c.r, 0, Math.PI*2); //draw the circle
ctx.closePath(); //close the circle path
ctx.fill(); //fill the circle
requestAnimationFrame(redraw);//schedule this function to be run on the next frame
}
function move(){ // this function modifies the object
var decimal = Math.random() // this returns a float between 0.0 and 1.0
c.x = decimal * canvas.width; // mulitple the random decimal by the canvas width and height to get a random pixel in the canvas;
c.y = decimal * canvas.height;
}
redraw(); //start the animation
setInterval(move, 1000); // run the move function every second (1000 milliseconds)
这是它的小提琴。 http://jsfiddle.net/r4JPG/2/
如果要缓存和翻译,请相应地更改move
方法。
3
这将移动一个小圆圈在画布
<html>
<head>
</head>
<body>
<canvas id="canvas" style="background:rgba(34,45,23,0.4)"></canvas>
<script>
var can = document.getElementById('canvas');
can.height = 1000; can.width = 1300;
var ctx = can.getContext('2d');
var x = 10, y = 100;
ctx.fillStyle = "black";
ctx.fillRect(700, 100, 100, 100);
function draw() {
ctx.beginPath();
ctx.arc(x, y, 20, 0, 2 * Math.PI);
ctx.fillStyle = 'rgba(250,0,0,0.4)';
ctx.fill();
x += 2;
ctx.fillStyle = "rgba(34,45,23,0.4)";
ctx.fillRect(0, 0, can.width, can.height);
requestAnimationFrame(draw);
//ctx.clearRect(0,0,can.width,can.height);
}
draw();
</script>
</body>
</html>
查看示例here!
+1
这是上面的JSFiddle,以防其他人想要它:http://jsfiddle.net/4fWt5/ – 2014-03-27 14:56:11
0
<html>
<head>
<title>Canvas Exam</title>
</head>
<body>
<canvas id="my_canvas" height="500" width="500" style="border:1px solid black">
</canvas>
<script>
var dom=document.getElementById("my_canvas");
var ctx=dom.getContext("2d");
var x1=setInterval(handler,1);
var x=50;
var y=50;
r=40;
function handler()
{
ctx.clearRect(0,0,500,500);
r1=(Math.PI/180)*0;
r2=(Math.PI/180)*360;
ctx.beginPath();
//x=x*Math.random();
x=x+2;
r=r+10*Math.random();
ctx.arc(x,y,r,r1,r2);
ctx.closePath();
ctx.fillStyle="blue";
ctx.fill();
ctx.stroke();
if(x>400)
{
x=50;
y=y+10;
}
r=40;
}
</script>
</body>
</html>
相关问题
- 1. HTML5画布距离和移动对象
- 2. 在画布上移动对象
- 3. 在html5画布上移动圈圈
- 4. html5画布 - 按路径动画对象
- 5. 用户输入在HTML5画布中移动对象
- 6. HTML5画布对象事件
- 7. 在画布中移动对象
- 8. 在html5 webgl画布动画中组织对象three.js
- 9. 动画GIF在HTML5画布
- 10. 在JavaScript中使对象在画布上移动
- 11. SkiaSharp - 如何在画布上移动对象
- 12. 需要帮助在画布上移动两个对象
- 13. 同时在Tkinter画布上移动多个对象
- 14. html5画布旋转移动弹跳球
- 15. 限制HTML5画布内的移动?
- 16. HTML5画布图像移动闪烁
- 17. html5画布旋转和移动问题
- 18. 如何使用文本输入在HTML5画布中移动对象?
- 19. 在html5画布上自定义滚动
- 20. 如何在html5画布上绘制移动的重复图案
- 21. HTML5 Canvas-在画布上移动一颗星
- 22. HTML5画布:使对象仅在画布的特定区域中可拖动。
- 23. Bootstrap偏移和HTML5画布
- 24. HTML5画布元素作为对象
- 25. html5 - 拖动画布
- 26. html5画布滚动
- 27. Html5,JavaScript,画布动画?
- 28. HTML5画布动画问题
- 29. 在两个对象之间的HTML5画布上绘制箭头
- 30. HTML5画布 - 在画布上拖动文本问题
@基山是不是你应该给+1的唯一原因?你有没有给过一个不太好的答案+1?哈。 AIGF – DutGRIFF 2015-05-17 13:54:06
Canvas是否没有在其上绘制“对象”的内部矢量状态?它仅仅是一个像素的“斑点”? – 2015-12-04 13:46:46
这是正确的。这只是一个位图,不知道如何绘制任何东西,除非您自己录制它。 – 2015-12-04 18:21:16