6.2.2_图像绘制器
来源:互联网 发布:淘宝上刘老中医可靠吗 编辑:程序博客网 时间:2024/05/29 09:57
6.2.2_图像绘制器
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>图像绘制器</title> <style> body{ background: #ddd; } #canvas{ background: #fff; cursor: pointer; margin: 10px; -webkit-box-shadow: 3px 3px 6px rgba(0,0,0,0.5); -moz-box-shadow: 3px 3px 6px rgba(0,0,0,0.5); box-shadow: 3px 3px 6px rgba(0,0,0,0.5); } </style> </head> <body> <canvas id="canvas" width="600" height="300"></canvas> </body> <!-- 精灵对象 --> <script> var Sprite = function(name,painter,behaviors){ if(name !== undefined){ this.name = name; } if(painter !== undefined){ this.painter = painter; } this.top = 0; this.left = 0; this.width = 10; this.height = 10; this.velocityX = 0; this.velocityY = 0; this.visible = true; this.animating = false; this.behaviors = behaviors || []; } Sprite.prototype = { paint:function(context){ if(this.painter !== undefined && this.visible){ this.painter.paint(this,context); } }, update:function(context,time){ for(var i=0;i<this.behaviors.length;i++){ this.behaviors[i].execute(this,context,time); } } } </script> <!-- 图像绘制器 --> <script> var ImagePainter = function (imageUrl){ this.image = new Image(); this.image.src = imageUrl; } ImagePainter.prototype ={ paint:function(sprite,context){ //因为图像绘制器专门负责反复绘制精灵对象所用的图像,所以它并不负责图像的加载 if(this.image.complete){ context.drawImage(this.image,sprite.left,sprite.top,sprite.width,sprite.height); } } } </script> <script> var canvas = document.getElementById('canvas'); var context = canvas.getContext('2d'); var tree = new Sprite('tree', new ImagePainter('img/small_tree.png')); tree.left = 220; tree.top = 80; tree.width = 140; tree.height = 150; window.requestAnimationFrame(animate); function animate(){ context.clearRect(0,0,canvas.width,canvas.height); tree.paint(context); window.requestAnimationFrame(animate); console.log('动画持续中'); } </script></html>
阅读全文
0 0
- 6.2.2_图像绘制器
- Python学习05_图像的绘制
- 6.2.3_精灵表绘制器
- Matlab入门_06_同一图像绘制多图形_注释
- HTML5 绘制2D图像
- 6.2.1_描边与填充绘制器
- 6.2.1_描边与填充绘制器
- 6.2.1_描边与填充绘制器
- 绘制图像
- 图像绘制
- 图像绘制
- [SheRO]用D3D绘制2D图像
- [SheRO]用D3D绘制2D图像
- android 2D图像的绘制
- 在canvas上绘制视频图像2
- D3D绘制2D图像例子
- Canvas绘制2D图像API列表
- iOS图像处理(2)绘制文本
- 【AngularJS】过滤器——currency 过滤器
- redis:Unable to validate object ;Could not get a resource from the pool;(error) MISCONF Redis is con
- Ubuntu切换到root用户
- JavaScript笔记
- 326. Power of Three
- 6.2.2_图像绘制器
- Redis学习手册
- Linux上部署Jenkins流程
- 项目经验分享
- 小白Python学习第一弹
- spring boot 最佳实践(三)--使用java.time
- 线段树,实例,代码实现,区间最值,区间求和,顺序存储,链式存储
- iOS截屏包含状态栏
- Dom04-Dom对元素的增删改插