微信小游戏之 wechat-adapter的使用(requestAnimationFrame)
2019-03-24 08:54
155 查看
[code]import "./weapp-adapter.js" var ctx = canvas.getContext("2d") var bg =new Image() bg.src ="./images/bg.jpg" bg.width =512 bg.height=512 var width = window.innerWidth //全局对象 var height = window.innerHeight bg.onload=function(){ ctx.drawImage(bg, 0, 0, bg.width, bg.height,0,0,width,height); }
画一张连续不停的画
[code]import "./weapp-adapter.js" var ctx = canvas.getContext("2d") var bg =new Image() bg.src ="./images/bg.jpg" bg.width =512 bg.height=512 var width = window.innerWidth //全局对象 var height = window.innerHeight var top = 0 move() function move(){ top++ requestAnimationFrame(function(){ ctx.clearRect(0,0,width,height) ctx.drawImage(bg, 0, 0, bg.width, bg.height,0,top,width,height); //一张向下走 ctx.drawImage(bg, 0, 0, bg.width, bg.height,0,-height+top,width,height); //一张在画室外面 if(top==height){ top =0 } move() }) }
3加入音乐
[code]var bgm = new Audio() bgm.volume =0.02 bgm.src ="./audio/bgm.mp3" bgm.play()
相关文章推荐
- 微信小游戏(四)从js的定时器到requestAnimationFrame
- window.requestAnimationFrame()的使用
- 使用requestAnimationFrame更好的实现javascript动画(转)
- 使用requestAnimationFrame更好的实现javascript动画(kimhou 译)
- HTML5 requestAnimationFrame的使用
- JavaScript 使用 requestAnimationFrame 代替 setInterval
- 使用requestAnimationFrame做动画效果二
- 使用requestAnimationFrame做动画效果一
- [翻译]使用requestAnimationFrame实现炫目的动画
- window.requestAnimationFrame与Tween.js配合使用实现动画缓动效果
- 使用requestAnimationFrame实现js动画性能好
- WebGL中使用window.requestAnimationFrame创建主循环
- 使用requestAnimationFrame实现js动画性能好
- 使用requestAnimationFrame实现平滑高效的javascript动画
- 从微信小程序重力感应API到requestAnimationFrame探索实现
- 系列博文-Three.js入门指南(张雯莉)-网格 setInterval方法 requestAnimationFrame方法 使用stat.js记录FPS
- 使用canvas画的圆形水球波纹带进度条的效果,里面使用的是requestAnimationFrame方法(),所以动画的执行只在区域可见的时候才会执行
- window.requestAnimationFrame()的使用
- requestAnimationFrame 的使用问题
- HTML5 Canvas 教程 2.4.2 使用 requestAnimationFrame 方法创建动画