search
HomeWeChat AppletMini Program DevelopmentImplementation of scratch card in WeChat mini program

Implementation of scratch card in WeChat mini program

How to achieve the effect of scratch card?

The idea is:

1. First determine the position and size of the winning picture or text

2. Start drawing the canvas, and match the position and size to the previous winning copy. The location remains consistent.

3. Cover the canvas with a gray mask to create the effect of the scratch card before it is scratched

The specific code is as follows

let left=0;
this.data.awardCanvas.moveTo(left,0)
this.data.awardCanvas.lineTo(left+400,0);
this.data.awardCanvas.lineTo(left+400,150);
this.data.awardCanvas.lineTo(left,150);
this.data.awardCanvas.stroke()
this.data.awardCanvas.setFillStyle('#ddd')
this.data.awardCanvas.fill()
this.data.awardCanvas.draw()

4. Start To make a scratch card action, define two triggered actions, bindtouchstart and bindtouchmove, on canvas

bindtouchstart is the first position where the finger starts to fall, and bindtouchmove is the position where the finger moves

One of the important canvas attributes is clearRect, which clears the content on the canvas

clearRect (clears the X coordinate of the position, clears the Y coordinate of the position, clears the width, clears the height)

The specific code is as follows :

this.data.awardCanvas.clearRect(x,y,15,15);
this.data.awardCanvas.draw(true)

The specific code is athttps://github.com/zhaodengping/scratch-mini

Go and try it, maybe You can win the first prize~~

Recommended tutorial: "WeChat Mini Program"

The above is the detailed content of Implementation of scratch card in WeChat mini program. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:juejin. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft