WeChat Mini Game Development

register:

1. Register the applet
 2. Select when filling in the applet information, the service category is: games

Note: After the mini game category is selected, it cannot be changed to the ordinary mini program category

Basic usage:

1. Create a canvas:
wx.createCanvas()
// Multiple canvases call 
screenContext.drawImage(otherCanvas, 0 , 0 )
 2. Drawing:
let ctx = canvas.getContext('2d')
ctx.fillStyle = ' red ' 
ctx.fillRect( 0 , 0 , 100 , 100 )
 // Set width and height: 
canvas.width = 300 
canvas.height = 300 
3 . Display image:
let image = wx.createImage()
image.onload = function () {
    console.log(image.width, image.height)
    context.drawImage(image, 0, 0)
}
image.src = ' logo.png ' 
4. Animation
setInterval()
setTimeout()
requestAnimationFrame()
clearInterval()
clearTimeout()
cancelAnimationFrame()
wx.setPreferredFramesPerSecond()
5. Touch events
wx.onTouchStart()
wx.onTouchMove()
wx.onTouchEnd()
wx.onTouchCancel()
// View 
wx.onTouchStart(function (e) {
    console.log(e.touches)
})
wx.onTouchCancel(function (e) {
    console.log(e.touches)
})
6. Global object
 // encapsulate to global
 // print 
console.log(GameGlobal.setTimeout === setTimeout);

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325194617&siteId=291194637
Recommended