mirror of
https://github.com/Leo501/CocosCreatorTutorial.git
synced 2026-06-23 19:37:32 +08:00
QRCode
This commit is contained in:
6
PQCode/assets/Script/3thPart.meta
Normal file
6
PQCode/assets/Script/3thPart.meta
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"ver": "1.0.1",
|
||||
"uuid": "4865e11a-13e3-4831-b0d5-a17970fcc41a",
|
||||
"isGroup": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
1237
PQCode/assets/Script/3thPart/qrcode.js
Normal file
1237
PQCode/assets/Script/3thPart/qrcode.js
Normal file
File diff suppressed because it is too large
Load Diff
9
PQCode/assets/Script/3thPart/qrcode.js.meta
Normal file
9
PQCode/assets/Script/3thPart/qrcode.js.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "53447054-ffc4-49ea-a72e-0d0659865944",
|
||||
"isPlugin": true,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
44
PQCode/assets/Script/QRcodeUi.js
Normal file
44
PQCode/assets/Script/QRcodeUi.js
Normal file
@@ -0,0 +1,44 @@
|
||||
cc.Class({
|
||||
extends: cc.Component,
|
||||
properties: {
|
||||
|
||||
},
|
||||
// use this for initialization
|
||||
onLoad() {
|
||||
this.init('http://forum.cocos.com/t/topic/44304/9');
|
||||
},
|
||||
|
||||
init(url){
|
||||
var ctx = this.node.addComponent(cc.Graphics);
|
||||
if (typeof (url) !== 'string') {
|
||||
console.log('url is not string',url);
|
||||
return;
|
||||
}
|
||||
this.QRCreate(ctx, url);
|
||||
},
|
||||
|
||||
QRCreate(ctx, url) {
|
||||
var qrcode = new QRCode(-1, QRErrorCorrectLevel.H);
|
||||
qrcode.addData(url);
|
||||
qrcode.make();
|
||||
|
||||
ctx.fillColor = cc.Color.BLACK;
|
||||
//块宽高
|
||||
var tileW = this.node.width / qrcode.getModuleCount();
|
||||
var tileH = this.node.height / qrcode.getModuleCount();
|
||||
|
||||
// draw in the Graphics
|
||||
for (var row = 0; row < qrcode.getModuleCount(); row++) {
|
||||
for (var col = 0; col < qrcode.getModuleCount(); col++) {
|
||||
if (qrcode.isDark(row, col)) {
|
||||
// ctx.fillColor = cc.Color.BLACK;
|
||||
var w = (Math.ceil((col + 1) * tileW) - Math.floor(col * tileW));
|
||||
var h = (Math.ceil((row + 1) * tileW) - Math.floor(row * tileW));
|
||||
ctx.rect(Math.round(col * tileW), Math.round(row * tileH), w, h);
|
||||
ctx.fill();
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
});
|
||||
9
PQCode/assets/Script/QRcodeUi.js.meta
Normal file
9
PQCode/assets/Script/QRcodeUi.js.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "1f7a3ac7-08ff-44aa-b73d-012b68e649a4",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
Reference in New Issue
Block a user