微信小游戏开发

注册:

1. 注册小程序
2. 填写小程序信息时选择,服务类目为:游戏

注意:小游戏类目选择后不可更换为普通小程序类目

基础用法:

1. 创建canvas:
wx.createCanvas()
//多个canvas调用
screenContext.drawImage(otherCanvas, 0, 0)
2. 绘制:
let ctx = canvas.getContext('2d')
ctx.fillStyle = 'red'
ctx.fillRect(0, 0, 100, 100)
//设置宽高:
canvas.width = 300
canvas.height = 300
3. 显示图片:
let image = wx.createImage()
image.onload = function () {
    console.log(image.width, image.height)
    context.drawImage(image, 0, 0)
}
image.src = 'logo.png'
4. 动画
setInterval()
setTimeout()
requestAnimationFrame()
clearInterval()
clearTimeout()
cancelAnimationFrame()
wx.setPreferredFramesPerSecond()
5. 触摸事件
wx.onTouchStart()
wx.onTouchMove()
wx.onTouchEnd()
wx.onTouchCancel()
//查看
wx.onTouchStart(function (e) {
    console.log(e.touches)
})
wx.onTouchCancel(function (e) {
    console.log(e.touches)
})
6. 全局对象
//封装到全局
//打印
console.log(GameGlobal.setTimeout === setTimeout);

猜你喜欢

转载自www.cnblogs.com/maoriaty/p/8981707.html