// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

// import { getSprNode } from "./util";
import { getSprNode, playAudioByUrl, showBtnAnima, getScaleRateBy2Node, localPosTolocalPos, randomSortByArr, loadDragonBones, playAudio, showTrebleFirework, getSprNodeByUrl, setSprNodeMaxLen, delayCall, asyncDelay, RandomInt, exchangeNodePos, onHomeworkFinish, callNetworkApi, loopLog, playBtnAnim} from "../script/hw_lettersort_util";

cc.Class({
	extends: cc.Component,

	properties: {
		baseWidth: {
			default: 1920,
			type: cc.Integer
		},
		baseHeight: {
			default: 1080,
			type: cc.Integer
		}
	},

	onLoad() {
		cc.debug.setDisplayStats(false);
		this.initSceneData();
		this.initSize();
	},

	initSceneData() {
		this._imageResList = [];
		this._audioResList = [];
		this._animaResList = [];
	},


	_designSize: null,
	_frameSize: null,
	_mapScaleMin: null,
	_mapScaleMax: null,
	_cocosScale: null,
	canvas: null,
	initSize() {

		this.canvas = cc.find('Canvas');

	

		// 注意cc.winSize只有在适配后(修改fitHeight/fitWidth后)才能获取到正确的值,因此使用cc.getFrameSize()来获取初始的屏幕大小
		let screen_size = cc.view.getFrameSize().width / cc.view.getFrameSize().height
		let design_size = cc.Canvas.instance.designResolution.width / cc.Canvas.instance.designResolution.height


		let f = screen_size >= design_size
		cc.Canvas.instance.fitHeight = f
		cc.Canvas.instance.fitWidth = !f

		const frameSize = cc.view.getFrameSize();
		this._frameSize = frameSize;

		this._designSize = cc.view.getDesignResolutionSize();

		let sx = cc.winSize.width / frameSize.width;
		let sy = cc.winSize.height / frameSize.height;
		this._cocosScale = Math.min(sx, sy);

		sx = frameSize.width / this._designSize.width;
		sy = frameSize.height / this._designSize.height;
		this._mapScaleMin = Math.min(sx, sy) * this._cocosScale;
		this._mapScaleMax = Math.max(sx, sy) * this._cocosScale;



		// cc.log('cc.Canvas: ', cc.Canvas);
	},

	start() {

		console.log(' in start 1 ');

		const middleLayer = cc.find('middleLayer');
		if (middleLayer) {
			const middleLayerComponent = middleLayer.getComponent('middleLayer');
			this.data = middleLayerComponent.getTempData('hw_dictation_data');

			console.log(' this.data: ', this.data);

		} else {

			this.data = this.getDefaultData();
			console.log(' this.data: ', this.data);

		}

		this.preloadItem()
		return;



		let getData = this.getData.bind(this);
		if (window && window.courseware) {
			getData = window.courseware.getData;

			console.log(' in start 2 ');

		}
		getData((data) => {
			console.log('data:', data);
			this.data = data || this.getDefaultData();
			this.preloadItem()
		})






		// const nextBtn = cc.find('middleLayer/BtnRight');
		// if (nextBtn) {
		// 	nextBtn.active = false;
		// }

	},

	getWordData() {
		const data = cc.sys.localStorage.getItem("hw_dictation") || {};
		return data;
	},

	_imageResList: null,
	_audioResList: null,
	_animaResList: null,
	preloadItem() {
		this.addPreloadImage();
		this.addPreloadAudio();
		this.addPreloadAnima();
		this.preload();
	},


	getData(func) {
		if (window && window.courseware) {
			window.courseware.getData(func, 'dfzx_cocos_dqq');
			return;
		}
		
		const middleLayer = cc.find('middleLayer');
		if (middleLayer) {
			const middleLayerComponent = middleLayer.getComponent('middleLayer');
			middleLayerComponent.getData(func);
			return;
		}
		
		func(this.getDefaultData());
	},

	getDefaultData() {

		return {
			"code":200,
			"msg":"success",
			"rows":[
					{
							"id":4,
							"pid":3,
							"text_en":"apple",
							"text_cn":"苹果",
							"audio_url":"https://staging-teach.cdn.ireadabc.com/45c2f33063ae0f167a64f2b262163e44.mp3",
							"audio_cn_url":"https://staging-teach.cdn.ireadabc.com/f7469d6e9e25ed5c6e4a3cb00a1e7ac4.mp3",
							"image_url":"[\"https://staging-teach.cdn.ireadabc.com/13e1752693f2892f5a5e7475a7e0c0ca.png\"]",
							"phonetic":"[hə'ləu]",
							"description":null,
							"mlk":null,
							"data":null,
							"seq":1,
							"has_child":0,
							"depth":4,
							"created_date":"2023-02-01T10:07:13.000Z",
							"updated_date":"2023-02-10T03:31:34.000Z",
							"del":0
					},
					{
							"id":4,
							"pid":3,
							"text_en":"box",
							"text_cn":"盒子",
							"audio_url":"https://staging-teach.cdn.ireadabc.com/063cd0637f937aaaa71b183f73bbb885.mp3",
							"audio_cn_url":"https://staging-teach.cdn.ireadabc.com/1a9ba8880b648a533245003da3ffc229.mp3",
							"image_url":"[\"https://staging-teach.cdn.ireadabc.com/d581120c4ae4fd87c41f960552d9a920.png\"]",
							"phonetic":"[hə'ləu]",
							"description":null,
							"mlk":null,
							"data":null,
							"seq":1,
							"has_child":0,
							"depth":4,
							"created_date":"2023-02-01T10:07:13.000Z",
							"updated_date":"2023-02-10T03:31:34.000Z",
							"del":0
					},
					{
							"id":4,
							"pid":3,
							"text_en":"mirror",
							"text_cn":"镜子",
							"audio_url":"https://staging-teach.cdn.ireadabc.com/d0c2fcd982889b0b326c2e1c1899102b.mp3",
							"audio_cn_url":"https://staging-teach.cdn.ireadabc.com/070c928e62b86654927f1d4c6e27bf46.mp3",
							"image_url":"[\"https://staging-teach.cdn.ireadabc.com/554f3bb2de99c70c7b6a1ac9eb18be69.png\"]",
							"phonetic":"[hə'ləu]",
							"description":null,
							"mlk":null,
							"data":null,
							"seq":1,
							"has_child":0,
							"depth":4,
							"created_date":"2023-02-01T10:07:13.000Z",
							"updated_date":"2023-02-10T03:31:34.000Z",
							"del":0
					},
					{
							"id":4,
							"pid":3,
							"text_en":"goodbye",
							"text_cn":"再见",
							"audio_url":"https://staging-teach.cdn.ireadabc.com/a949d762ae1416846377b36804bdb345.mp3",
							"audio_cn_url":"https://staging-teach.cdn.ireadabc.com/beeb4e25bf8b745d848c673b966e61cd.mp3",
							"image_url":"[\"https://staging-teach.cdn.ireadabc.com/3d8b17121aff99485bc23091dd96786b.png\"]",
							"phonetic":"[hə'ləu]",
							"description":null,
							"mlk":null,
							"data":null,
							"seq":1,
							"has_child":0,
							"depth":4,
							"created_date":"2023-02-01T10:07:13.000Z",
							"updated_date":"2023-02-10T03:31:34.000Z",
							"del":0
					},
					{
							"id":5,
							"pid":3,
							"text_en":"hat",
							"text_cn":"帽子",
							"audio_url":"https://staging-teach.cdn.ireadabc.com/7645af77f7e967114fdf40f5914c0ebb.mp3",
							"audio_cn_url":"https://staging-teach.cdn.ireadabc.com/78636cebef7d3d8935d1b13a56769a49.mp3",
							"image_url":"[\"https://staging-teach.cdn.ireadabc.com/a1419d93c7317e222bd271c507ff2966.png\"]",
							"phonetic":"[eɪ]",
							"description":null,
							"mlk":null,
							"data":null,
							"seq":2,
							"has_child":0,
							"depth":4,
							"created_date":"2023-02-01T10:07:13.000Z",
							"updated_date":"2023-02-10T03:31:34.000Z",
							"del":0
					},
					{
							"id":6,
							"pid":3,
							"text_en":"grass",
							"text_cn":"草",
							"audio_url":"https://staging-teach.cdn.ireadabc.com/c340f84a48ba9dc3cd3ea8f068647959.mp3",
							"audio_cn_url":"https://staging-teach.cdn.ireadabc.com/76f2a4f513eb1f471f70895f110be7c9.mp3",
							"image_url":"[\"https://staging-teach.cdn.ireadabc.com/eeb9981f15c9888b8cbe2e02b804c598.png\"]",
							"phonetic":"[u:]",
							"description":null,
							"mlk":null,
							"data":null,
							"seq":3,
							"has_child":0,
							"depth":4,
							"created_date":"2023-02-01T10:07:13.000Z",
							"updated_date":"2023-02-10T03:31:34.000Z",
							"del":0
					},
					{
							"id":7,
							"pid":3,
							"text_en":"cat",
							"text_cn":"猫",
							"audio_url":"https://staging-teach.cdn.ireadabc.com/08c41e5955662c6b305207e48edd69ff.mp3",
							"audio_cn_url":"https://staging-teach.cdn.ireadabc.com/245dbdbba2903b505b856acf65831108.mp3",
							"image_url":"[\"https://staging-teach.cdn.ireadabc.com/20df5f7c2755cb25a43cebe54a096415.png\"]",
							"phonetic":"[ai]",
							"description":null,
							"mlk":null,
							"data":null,
							"seq":4,
							"has_child":0,
							"depth":4,
							"created_date":"2023-02-01T10:07:13.000Z",
							"updated_date":"2023-02-10T03:31:34.000Z",
							"del":0
					},
					{
							"id":8,
							"pid":3,
							"text_en":"bed",
							"text_cn":"床",
							"audio_url":"https://staging-teach.cdn.ireadabc.com/24e1754910436af1e96607517b3b1f8e.mp3",
							"audio_cn_url":"https://staging-teach.cdn.ireadabc.com/d7bf6b5c3cfc1deec121aeafb1378959.mp3",
							"image_url":"[\"https://staging-teach.cdn.ireadabc.com/9b2871fc2d28a46c67cb64660a071a99.png\"]",
							"phonetic":"[em]",
							"description":null,
							"mlk":null,
							"data":null,
							"seq":5,
							"has_child":0,
							"depth":4,
							"created_date":"2023-02-01T10:07:13.000Z",
							"updated_date":"2023-02-10T03:31:34.000Z",
							"del":0
					},
					{
							"id":9,
							"pid":3,
							"text_en":"shoes",
							"text_cn":"鞋",
							"audio_url":"https://staging-teach.cdn.ireadabc.com/bf6b82e836fdabef23a148323f317044.mp3",
							"audio_cn_url":"https://staging-teach.cdn.ireadabc.com/f5fd21ac039ad795b82b8212550a94cb.mp3",
							"image_url":"[\"https://staging-teach.cdn.ireadabc.com/4937b8aa08bc7e6c88191fc2b93bfa3c.png\"]",
							"phonetic":"[aɪm]",
							"description":null,
							"mlk":null,
							"data":null,
							"seq":6,
							"has_child":0,
							"depth":4,
							"created_date":"2023-02-01T10:07:13.000Z",
							"updated_date":"2023-02-10T03:31:34.000Z",
							"del":0
					},
					{
							"id":10,
							"pid":3,
							"text_en":"tree",
							"text_cn":"树",
							"audio_url":"https://staging-teach.cdn.ireadabc.com/593567ac4a152d8df5f9cf561de8c89e.mp3",
							"audio_cn_url":"https://staging-teach.cdn.ireadabc.com/054e9e37fb39cba2cf775bf91ae7fa67.mp3",
							"image_url":"[\"https://staging-teach.cdn.ireadabc.com/8e6073338dd46624949025ba7c24b5cb.png\"]",
							"phonetic":"[aim]",
							"description":null,
							"mlk":null,
							"data":null,
							"seq":7,
							"has_child":0,
							"depth":4,
							"created_date":"2023-02-01T10:07:13.000Z",
							"updated_date":"2023-02-10T03:31:34.000Z",
							"del":0
					},
					{
							"id":11,
							"pid":3,
							"text_en":"jump",
							"text_cn":"跳",
							"audio_url":"https://staging-teach.cdn.ireadabc.com/2d7811e2821c8a3653362eaf3f0fad88.mp3",
							"audio_cn_url":"https://staging-teach.cdn.ireadabc.com/11a73f92b86f93053ba5951930263cd0.mp3",
							"image_url":"[\"https://staging-teach.cdn.ireadabc.com/fe1f6465fe513c1de2bb45f37b16c561.png\"]",
							"phonetic":"[ˌɡʊd'baɪ]",
							"description":null,
							"mlk":null,
							"data":null,
							"seq":8,
							"has_child":0,
							"depth":4,
							"created_date":"2023-02-01T10:07:13.000Z",
							"updated_date":"2023-02-14T01:01:17.000Z",
							"del":0
					},
					{
							"id":12,
							"pid":3,
							"text_en":"see",
							"text_cn":"看",
							"audio_url":"https://staging-teach.cdn.ireadabc.com/77dfdb213af9a61ccdc0b2ff10c11f69.mp3",
							"audio_cn_url":"https://staging-teach.cdn.ireadabc.com/1cab61c6744a1e4ec5b7f390fef9bd98.mp3",
							"image_url":"[\"https://staging-teach.cdn.ireadabc.com/63bae62a77d00636eb14aced784ca8a6.png\"]",
							"phonetic":"",
							"description":null,
							"mlk":null,
							"data":null,
							"seq":9,
							"has_child":0,
							"depth":4,
							"created_date":"2023-02-01T10:07:13.000Z",
							"updated_date":"2023-02-14T01:48:04.000Z",
							"del":0
					},
					{
							"id":13,
							"pid":3,
							"text_en":"hello",
							"text_cn":"你好",
							"audio_url":"https://staging-teach.cdn.ireadabc.com/d1d21805a9dad93088d94d0cf73fd91a.mp3",
							"audio_cn_url":"https://staging-teach.cdn.ireadabc.com/06dd39eb36459a544db5f98407000dc0.mp3",
							"image_url":"[\"https://staging-teach.cdn.ireadabc.com/a074f252f7febcf37b487d0926506fdf.png\"]",
							"phonetic":"[nəu]",
							"description":null,
							"mlk":null,
							"data":null,
							"seq":10,
							"has_child":0,
							"depth":4,
							"created_date":"2023-02-01T10:07:13.000Z",
							"updated_date":"2023-02-14T01:48:04.000Z",
							"del":0
					},
					{
							"id":14,
							"pid":3,
							"text_en":"ball",
							"text_cn":"球",
							"audio_url":"https://staging-teach.cdn.ireadabc.com/63f7701964c7892f376048501bab636e.mp3",
							"audio_cn_url":"https://staging-teach.cdn.ireadabc.com/6ccabea4267a1c40c8f62b4b0fc0be64.mp3",
							"image_url":"[\"https://staging-teach.cdn.ireadabc.com/144963684fb3228d1288a553e08c2e5b.png\",\"http://teach.cdn.ireadabc.com/c277886eed7dd79f8ebabef2ca01248a.jpg\"]",
							"phonetic":"[jes]",
							"description":null,
							"mlk":null,
							"data":null,
							"seq":11,
							"has_child":0,
							"depth":4,
							"created_date":"2023-02-01T10:07:13.000Z",
							"updated_date":"2023-02-14T01:48:04.000Z",
							"del":0
					},
					{
							"id":15,
							"pid":3,
							"text_en":"up",
							"text_cn":"向上",
							"audio_url":"https://staging-teach.cdn.ireadabc.com/ccb0156dfca34ad8fd70ad7a00ec03fb.mp3",
							"audio_cn_url":"https://staging-teach.cdn.ireadabc.com/3fc7e368f116264119810c89ed3599a1.mp3",
							"image_url":"[\"https://staging-teach.cdn.ireadabc.com/6d3d40f0e14f5365bc4936fd9a60b10b.png\"]",
							"phonetic":"['sɒri]",
							"description":null,
							"mlk":null,
							"data":null,
							"seq":12,
							"has_child":0,
							"depth":4,
							"created_date":"2023-02-01T10:07:13.000Z",
							"updated_date":"2023-02-10T03:31:34.000Z",
							"del":0
					},
					{
							"id":16,
							"pid":3,
							"text_en":"down",
							"text_cn":"向下",
							"audio_url":"https://staging-teach.cdn.ireadabc.com/84160f100d7b5607ddeadf068cdc0010.mp3",
							"audio_cn_url":"https://staging-teach.cdn.ireadabc.com/a75ad96abb21b7b9130405cbd9b4bd08.mp3",
							"image_url":"[\"https://staging-teach.cdn.ireadabc.com/02da7fe46ced513de4c4a02f0f79f274.png\"]",
							"phonetic":"[faɪn]",
							"description":null,
							"mlk":null,
							"data":null,
							"seq":13,
							"has_child":0,
							"depth":4,
							"created_date":"2023-02-01T10:07:13.000Z",
							"updated_date":"2023-02-14T01:48:58.000Z",
							"del":0
					}
					
			]
	}

		return  {
			"code": 200,
			"msg": "success",
			"rows": [
				{
					"id": 1301,
					"pid": 1300,
					"text_en": "can",
					"text_cn": "can",
					"audio_url": "http://teach.cdn.ireadabc.com/7146fd98f16ea1fc580c508e238164f3.mp3",
					"audio_cn_url": "http://teach.cdn.ireadabc.com/950acc37df35c3f8b82b2823c74fa2b6.mp3",
					"image_url": "[\"http://teach.cdn.ireadabc.com/7cf22e530a6ab18e4a3a54478a386124.jpg\",\"http://teach.cdn.ireadabc.com/bb2531bb3e92856d54dbdd810ff5f224.jpeg\",\"http://teach.cdn.ireadabc.com/5815237ea67ed5694adc4ca70e4d10ce.webp\"]",
					"phonetic": null,
					"description": null,
					"data": null,
					"seq": 1,
					"has_child": 0,
					"depth": 4,
					"created_date": "2023-02-02T02:44:13.000Z",
					"updated_date": "2023-02-07T23:33:49.000Z",
					"del": 0
				},
				{
					"id": 1302,
					"pid": 1300,
					"text_en": "ram",
					"text_cn": "ram",
					"audio_url": "http://teach.cdn.ireadabc.com/717fb741707975c2383d5a04868b405e.mp3",
					"audio_cn_url": "http://teach.cdn.ireadabc.com/7b266fb7469ceeacf62f7fbd01c0a7d3.mp3",
					"image_url": "[\"http://teach.cdn.ireadabc.com/9614af1ba1511225178b47b537b0ea2c.jpg\",\"http://teach.cdn.ireadabc.com/e40619d96bf24b0316df6044a8a2a2a2.jpg\"]",
					"phonetic": null,
					"description": null,
					"data": null,
					"seq": 2,
					"has_child": 0,
					"depth": 4,
					"created_date": "2023-02-02T02:44:13.000Z",
					"updated_date": "2023-02-07T23:33:49.000Z",
					"del": 0
				},
				{
					"id": 1303,
					"pid": 1300,
					"text_en": "fan",
					"text_cn": "fan",
					"audio_url": "http://teach.cdn.ireadabc.com/e314bbdec7df6e6d92e1bfdb64edbeb2.mp3",
					"audio_cn_url": "http://teach.cdn.ireadabc.com/83c16cbf439fe163326fc98bd9b3b308.mp3",
					"image_url": "[\"http://teach.cdn.ireadabc.com/edd4a15e80ed86cce167cb517bcf9ea9.jpg\",\"http://teach.cdn.ireadabc.com/e1f9dd0f1114c393240b05d3a6a8b95f.jpg\"]",
					"phonetic": null,
					"description": null,
					"data": null,
					"seq": 3,
					"has_child": 0,
					"depth": 4,
					"created_date": "2023-02-02T02:44:13.000Z",
					"updated_date": "2023-02-07T23:33:49.000Z",
					"del": 0
				},
				{
					"id": 1304,
					"pid": 1300,
					"text_en": "dam",
					"text_cn": "dam",
					"audio_url": "http://teach.cdn.ireadabc.com/0a25cf3096147ab3278368666375a073.mp3",
					"audio_cn_url": "http://teach.cdn.ireadabc.com/308a5e478d1de06f8b7087a529073940.mp3",
					"image_url": "[\"http://teach.cdn.ireadabc.com/5c7f1c9ef3ecff0fdd2c5a2a29960a25.jpg\"]",
					"phonetic": null,
					"description": null,
					"data": null,
					"seq": 4,
					"has_child": 0,
					"depth": 4,
					"created_date": "2023-02-02T02:44:13.000Z",
					"updated_date": "2023-02-07T23:33:49.000Z",
					"del": 0
				},
				{
					"id": 1305,
					"pid": 1300,
					"text_en": "pan",
					"text_cn": "pan",
					"audio_url": "http://teach.cdn.ireadabc.com/e24396e9abca23932e0740ac652cb892.mp3",
					"audio_cn_url": "http://teach.cdn.ireadabc.com/1a4d97462b4e155cb7ff4210bd6cf37b.mp3",
					"image_url": "[\"http://teach.cdn.ireadabc.com/913dca39a7ac4598a740f274f33ce3bf.webp\",\"http://teach.cdn.ireadabc.com/64580530e9d9df587914b257c692bca5.webp\",\"http://teach.cdn.ireadabc.com/cc22164f6436f431ef0de782d25488db.webp\"]",
					"phonetic": null,
					"description": null,
					"data": null,
					"seq": 5,
					"has_child": 0,
					"depth": 4,
					"created_date": "2023-02-02T02:44:13.000Z",
					"updated_date": "2023-02-07T23:33:49.000Z",
					"del": 0
				},
				{
					"id": 1306,
					"pid": 1300,
					"text_en": "jam",
					"text_cn": "jam",
					"audio_url": "http://teach.cdn.ireadabc.com/344070143e6a32e3795ecf48140ef804.mp3",
					"audio_cn_url": "http://teach.cdn.ireadabc.com/8324f125f5ef342a6b06bdc84e11fd13.mp3",
					"image_url": "[\"http://teach.cdn.ireadabc.com/2d47ee18a14fc1f3b41b834b390a60c7.jpg\"]",
					"phonetic": null,
					"description": null,
					"data": null,
					"seq": 6,
					"has_child": 0,
					"depth": 4,
					"created_date": "2023-02-02T02:44:13.000Z",
					"updated_date": "2023-02-07T23:33:49.000Z",
					"del": 0
				},
				{
					"id": 1307,
					"pid": 1300,
					"text_en": "man",
					"text_cn": "man",
					"audio_url": "http://teach.cdn.ireadabc.com/4f01d61ccfee16f7bead3521205d7a33.mp3",
					"audio_cn_url": "http://teach.cdn.ireadabc.com/abde4e66a080f67d00f8e6426a1e7823.mp3",
					"image_url": null,
					"phonetic": null,
					"description": null,
					"data": null,
					"seq": 7,
					"has_child": 0,
					"depth": 4,
					"created_date": "2023-02-02T02:44:13.000Z",
					"updated_date": "2023-02-07T23:33:49.000Z",
					"del": 0
				}
			]
		}

		return  {
			"code": 200,
			"msg": "success",
			"rows": [
				{
					"id": 1301,
					"pid": 1300,
					"text_en": "book",
					"text_cn": "书，书本",
					"audio_url": "http://teach.cdn.ireadabc.com/7146fd98f16ea1fc580c508e238164f3.mp3",
					"audio_cn_url": "http://teach.cdn.ireadabc.com/950acc37df35c3f8b82b2823c74fa2b6.mp3",
					"image_url": "[\"http://teach.cdn.ireadabc.com/7cf22e530a6ab18e4a3a54478a386124.jpg\",\"http://teach.cdn.ireadabc.com/bb2531bb3e92856d54dbdd810ff5f224.jpeg\",\"http://teach.cdn.ireadabc.com/5815237ea67ed5694adc4ca70e4d10ce.webp\"]",
					"phonetic": null,
					"description": null,
					"data": null,
					"seq": 1,
					"has_child": 0,
					"depth": 4,
					"created_date": "2023-02-02T02:44:13.000Z",
					"updated_date": "2023-02-07T23:33:49.000Z",
					"del": 0
				},
				{
					"id": 1302,
					"pid": 1300,
					"text_en": "ruler",
					"text_cn": "尺子",
					"audio_url": "http://teach.cdn.ireadabc.com/717fb741707975c2383d5a04868b405e.mp3",
					"audio_cn_url": "http://teach.cdn.ireadabc.com/7b266fb7469ceeacf62f7fbd01c0a7d3.mp3",
					"image_url": "[\"http://teach.cdn.ireadabc.com/9614af1ba1511225178b47b537b0ea2c.jpg\",\"http://teach.cdn.ireadabc.com/e40619d96bf24b0316df6044a8a2a2a2.jpg\"]",
					"phonetic": null,
					"description": null,
					"data": null,
					"seq": 2,
					"has_child": 0,
					"depth": 4,
					"created_date": "2023-02-02T02:44:13.000Z",
					"updated_date": "2023-02-07T23:33:49.000Z",
					"del": 0
				},
				{
					"id": 1303,
					"pid": 1300,
					"text_en": "pencil",
					"text_cn": "铅笔",
					"audio_url": "http://teach.cdn.ireadabc.com/e314bbdec7df6e6d92e1bfdb64edbeb2.mp3",
					"audio_cn_url": "http://teach.cdn.ireadabc.com/83c16cbf439fe163326fc98bd9b3b308.mp3",
					"image_url": "[\"http://teach.cdn.ireadabc.com/edd4a15e80ed86cce167cb517bcf9ea9.jpg\",\"http://teach.cdn.ireadabc.com/e1f9dd0f1114c393240b05d3a6a8b95f.jpg\"]",
					"phonetic": null,
					"description": null,
					"data": null,
					"seq": 3,
					"has_child": 0,
					"depth": 4,
					"created_date": "2023-02-02T02:44:13.000Z",
					"updated_date": "2023-02-07T23:33:49.000Z",
					"del": 0
				},
				{
					"id": 1304,
					"pid": 1300,
					"text_en": "schoolbag",
					"text_cn": "书包",
					"audio_url": "http://teach.cdn.ireadabc.com/0a25cf3096147ab3278368666375a073.mp3",
					"audio_cn_url": "http://teach.cdn.ireadabc.com/308a5e478d1de06f8b7087a529073940.mp3",
					"image_url": "[\"http://teach.cdn.ireadabc.com/5c7f1c9ef3ecff0fdd2c5a2a29960a25.jpg\"]",
					"phonetic": null,
					"description": null,
					"data": null,
					"seq": 4,
					"has_child": 0,
					"depth": 4,
					"created_date": "2023-02-02T02:44:13.000Z",
					"updated_date": "2023-02-07T23:33:49.000Z",
					"del": 0
				},
				{
					"id": 1305,
					"pid": 1300,
					"text_en": "teacher",
					"text_cn": "教师",
					"audio_url": "http://teach.cdn.ireadabc.com/e24396e9abca23932e0740ac652cb892.mp3",
					"audio_cn_url": "http://teach.cdn.ireadabc.com/1a4d97462b4e155cb7ff4210bd6cf37b.mp3",
					"image_url": "[\"http://teach.cdn.ireadabc.com/913dca39a7ac4598a740f274f33ce3bf.webp\",\"http://teach.cdn.ireadabc.com/64580530e9d9df587914b257c692bca5.webp\",\"http://teach.cdn.ireadabc.com/cc22164f6436f431ef0de782d25488db.webp\"]",
					"phonetic": null,
					"description": null,
					"data": null,
					"seq": 5,
					"has_child": 0,
					"depth": 4,
					"created_date": "2023-02-02T02:44:13.000Z",
					"updated_date": "2023-02-07T23:33:49.000Z",
					"del": 0
				},
				{
					"id": 1306,
					"pid": 1300,
					"text_en": "I",
					"text_cn": "我",
					"audio_url": "http://teach.cdn.ireadabc.com/344070143e6a32e3795ecf48140ef804.mp3",
					"audio_cn_url": "http://teach.cdn.ireadabc.com/8324f125f5ef342a6b06bdc84e11fd13.mp3",
					"image_url": "[\"http://teach.cdn.ireadabc.com/2d47ee18a14fc1f3b41b834b390a60c7.jpg\"]",
					"phonetic": null,
					"description": null,
					"data": null,
					"seq": 6,
					"has_child": 0,
					"depth": 4,
					"created_date": "2023-02-02T02:44:13.000Z",
					"updated_date": "2023-02-07T23:33:49.000Z",
					"del": 0
				},
				{
					"id": 1307,
					"pid": 1300,
					"text_en": "have",
					"text_cn": "有",
					"audio_url": "http://teach.cdn.ireadabc.com/4f01d61ccfee16f7bead3521205d7a33.mp3",
					"audio_cn_url": "http://teach.cdn.ireadabc.com/abde4e66a080f67d00f8e6426a1e7823.mp3",
					"image_url": null,
					"phonetic": null,
					"description": null,
					"data": null,
					"seq": 7,
					"has_child": 0,
					"depth": 4,
					"created_date": "2023-02-02T02:44:13.000Z",
					"updated_date": "2023-02-07T23:33:49.000Z",
					"del": 0
				},
				{
					"id": 1308,
					"pid": 1300,
					"text_en": "a/an",
					"text_cn": "一（个）",
					"audio_url": "http://teach.cdn.ireadabc.com/69280aedfbcc98e3e3727ba8eeff8274.mp3",
					"audio_cn_url": "http://teach.cdn.ireadabc.com/63862c6504bedd237b58d7fd311b27ef.mp3",
					"image_url": null,
					"phonetic": null,
					"description": null,
					"data": null,
					"seq": 8,
					"has_child": 0,
					"depth": 4,
					"created_date": "2023-02-02T02:44:13.000Z",
					"updated_date": "2023-02-07T23:33:49.000Z",
					"del": 0
				}
			]
		}

	},

	preload() {
		const preloadArr = this._imageResList.concat(this._audioResList).concat(this._animaResList);
		console.log(' in preload preloadArr: ', preloadArr);
		cc.assetManager.loadAny(preloadArr, null, null, (err, data) => {
			console.log(' preload data, ', data);


			this.addServerListener();
			// if (window && window["air"]) {
			// 	window["air"].hideAirClassLoading();
			// }
		});
	},

	addServerListener() {
		
		if (window && window["air"]) {
			// cc.find('Canvas').opacity = 0;
			// window.air.onCourseInScreen = (next) => {
			// 	//  cc.find('Canvas').opacity = 255;
			// 	this.loadEnd();
			// 	next();
			// }
			this.loadEnd();
			window.air.hideAirClassLoading();
		} else {
			this.loadEnd();
		}



		if (window.air) {
			window.air.osmoHandwritingMlkitCallback = (data) => {

				if (!data) {
					console.log('data is not exist!!!');
					return;
				}

				console.log('@ data: ', data);

				if (typeof (data) == 'string') {
					console.log('data is string ');
					const dataObj = JSON.parse(data);

					this.photoEnd(dataObj);
					return;
				}

				// 哲学逻辑
				this.photoEnd(data);

			}
		}

		// if (window.air) {

		// 	window.air.osmoHandwritingCallback = (data) => {

		// 		if (!data) {
		// 			console.log('data is not exist!!!');
		// 			return;
		// 		}

		// 		console.log('osmoHandwritingCallback data: ', data);

		// 		if (typeof (data) == 'string') {
		// 			console.log('data is string ');
		// 			const dataObj = JSON.parse(data);

		// 			this.photoEnd(dataObj);
		// 			return;
		// 		}

		// 		// 哲学逻辑
		// 		this.photoEnd(data);

		// 	}

			
		// }

	},

	addPreloadImage() {
	
		if (this.data.bg_pic_url) {
			this._imageResList.push({ url: this.data.bg_pic_url || ''});
		}

		if (this.data.bgItem) {
			this._imageResList.push({ url: this.data.bgItem.url || ''});
		}

		if (this.data.bgItem2) {
			this._imageResList.push({ url: this.data.bgItem2.url || ''});
		}

		if (!this.data.hotZoneItemArr) {
			return;
		}
		this.data.hotZoneItemArr.forEach((item) => {
			if (item.pic_url) {
				this._imageResList.push({ url: item.pic_url || ''});
			}
		})
	},

	addPreloadAudio() {

		const arr = this.data.rows;

		if (arr) {
			for (let i=0 ;i<arr.length; i++) {
				this._audioResList.push({url: arr[i].audio_url || ''});
				this._audioResList.push({url: arr[i].audio_cn_url || ''});
			}
		}

	},

	addPreloadAnima() {
		if (!this.data.hotZoneItemArr) {
			return;
		}
		this.data.hotZoneItemArr.forEach((item) => {
			if (item.skeJsonData) {
				this._animaResList.push({ url: item.skeJsonData.url || '' });
				this._animaResList.push({ url: item.texJsonData.url || ''});
				this._animaResList.push({ url: item.texPngData.url || ''});
			}
		})
	},

	loadEnd() {
		console.log(' in loadEnd');

		// this.data.isDebug = true;

		this.initData();
		this.initView();
		this.initListener();
		// this.initMusic();

		// this.startTesting();

		// cc.debug.setDisplayStats(true);

	},

	initMusic() {
		cc.assetManager.loadRemote(this.data.bg_audio_url, (err, clip) => {
			cc.audioEngine.setMusicVolume(0.3);
			const audioID = cc.audioEngine.playMusic(clip, true);
		});
	},

	curGroupIndex: null,
	curQuestionIndex: null,
	curQuestionData: null,

	picNodeArr: null,


	firstItemData: null,
	bottomItemData: null,
	animaNodeArr: null,
	circleAnimaNodeArr: null,
	signAnimaNodeArr: null,

	initData() {
		console.log(' in initData');

		this.initAudioEffect();

		const rows = [];
		for (let i=0; i<this.data.rows.length; i++) {

			const text = this.data.rows[i].text_en;
			const pattern = /^[a-zA-Z]{2,}$/;
			
			if (pattern.test(text)) {
				console.log("文本只包含英文字符且长度大于1");

				// this.data.rows[i].text_en += "aaaaaa"
				rows.push(this.data.rows[i])
			} else {
				console.log("文本不符合要求");
			}
		}

		this.data.rows = randomSortByArr( rows );


		this.score = 0;
		this.curDataIndex = 0;



		return;


		this.CHECK_TYPE_LINE = 'LINE';
		this.CHECK_TYPE_WRITE = 'WRITE';
		this.CHECK_TYPE_CIRCLE = 'CIRCLE';
		this.CHECK_TYPE_SIGN = 'SIGN';
		this.CHECK_TYPE_FINGER = 'FINGER';


		this.quesNodeArr = [];

		this.totalLineArr = [];
		this.rectNodeArr = [];

		this.animaNodeArr = [];

		this.circleAnimaNodeArr = [];
		this.signAnimaNodeArr = [];
		this.fingerAnimaNodeArr = [];

		this.picNodeArr = [];

		this.linkRectGroup = [];


		// this.newRectArr = this.getGroupArrByGIdx(this.data.hotZoneItemArr2, '0');

		this.titleWidth = 70;
		if (this.canvas.width < this.canvas.height) {
			this.isVertical = true;
			this.titleWidth = 50;
		}

		// this.isVertical = true;

		this.wordBgArr = [];



		console.log("this.data.quesArr: ", this.data.quesArr);

	},

	initTypeArr() {
		const typeArr = this.data.typeArr;
		
		if (!this.data.firstGIdx) {
			this.data.firstGIdx = typeArr[0].gIdx;
		}

		this.typeArr = [];
		const firstType = typeArr.find((t) => {
			return t.gIdx == this.data.firstGIdx;
		})

		const index = typeArr.indexOf(firstType);
		typeArr.splice(index, 1);

		this.typeArr = [firstType];
		this.typeArr = this.typeArr.concat(typeArr)
		this.typeArrIndex = 0;

		console.log("this.typeArr: ", this.typeArr);
	},

	initCheckBase() {


		console.log('benchmark1Data: ', this.benchmark1Data);
		console.log('benchmark2Data: ', this.benchmark2Data);
		console.log('centerItemArr: ', this.centerItemArr);

		const benchmark1Rect = this.benchmark1Data.rect;
		const benchmark2Rect = this.benchmark2Data.rect;
		
		const benchmark1CenterY = (benchmark1Rect.y + benchmark1Rect.height / 2);
		const benchmark2CenterY = (benchmark2Rect.y + benchmark2Rect.height / 2);
		
		let unitH = benchmark2CenterY - benchmark1CenterY;
		let unitW = benchmark2Rect.x + benchmark2Rect.width - benchmark1Rect.x;
		let baseX = benchmark1Rect.x;
		let baseY = benchmark1CenterY;


		if (this.firstItemData) {
			const firstItemRect = this.firstItemData.rect;
			baseX = firstItemRect.x + firstItemRect.width / 2;
			baseY = firstItemRect.y + firstItemRect.height / 2;
			unitW = benchmark1Rect.x + benchmark1Rect.width - (firstItemRect.x + firstItemRect.width / 2);
			unitH = (firstItemRect.y + firstItemRect.height / 2) - benchmark1CenterY;
		}


		for(let i=0; i<this.centerItemArr.length; i++) {

			const itemRect = this.centerItemArr[i].rect;
			const x = itemRect.x + itemRect.width / 2;
			const y = itemRect.y + itemRect.height / 2;

			const unitX = (x - baseX) / unitW;
			const unitY = (y - baseY) / unitH;
			const unitW2 = itemRect.width / unitW;
			const unitH2 = itemRect.height / unitH;


			this.centerItemArr[i].unitX = unitX;
			this.centerItemArr[i].unitY = unitY;
			this.centerItemArr[i].unitW = unitW2;
			this.centerItemArr[i].unitH = unitH2;

			// console.log('unitX: ', unitX)
			// console.log('unitY: ', unitY)
		}

		console.log('unitH: ', unitH)
		console.log('unitW: ', unitW)
		console.log('baseX: ', baseX)
		console.log('baseY: ', baseY)

	
		const centerX = this.data.bgItem2.rect.width / 2;
		this.centerUnitW = (centerX - baseX) / unitW;



	},

	getGroupArrByGIdx(arr, gIdx) {
		const groupArr = [];
		for (let i=0; i<arr.length; i++) {
			if (arr[i].gIdx == gIdx) {

				const data = JSON.parse(JSON.stringify(arr[i]));
				groupArr.push(data);
				// groupArr.push(arr[i]);
			}
		}

		return groupArr;
	},

	curGroup: null,
	setCurGroupAndQuestion() {
		this.curGroup = this.data.groupArr[this.curGroupIndex];

		if (!this.curGroup) {
			this.gameEnd();
		} else {
			this.curQuestionIndex = 0;
			this.setCurQuestionData();
		}
	},

	setCurQuestionData() {
		this.curQuestionData = this.curGroup.questionArr[this.curQuestionIndex];

		if (!this.curQuestionData) {

			this.hideVideo();
			this.showBigStar();
		}
	},

	hideVideo() {
		this.videoNode.active = false;

		this.videoNode.player.pause();
		this.videoNode.pauseBtn.active = false;
		this.videoNode.playBtn.active = true;
	},


	rightClip: null,
	wrongClip: null,
	bigStarClip: null,
	btnClip: null,
	finishClip: null,
	selectClip: null,
	starCountClip: null,
	beginTipClip: null,

	move1Clip: null,
	move2Clip: null,
	failClip: null,
	initAudioEffect() {
		// this.move1Clip = cc.find('Canvas/res/audio/move_1').getComponent(cc.AudioSource).clip;
		// this.move2Clip = cc.find('Canvas/res/audio/move_2').getComponent(cc.AudioSource).clip;
		// this.failClip = cc.find('Canvas/res/audio/fail_4').getComponent(cc.AudioSource).clip;
		this.rightClip = cc.find('Canvas/res/audio/right').getComponent(cc.AudioSource).clip;
		this.clickClip = cc.find('Canvas/res/audio/click').getComponent(cc.AudioSource).clip;
		this.nextClip = cc.find('Canvas/res/audio/next').getComponent(cc.AudioSource).clip;
		// this.wrongClip = cc.find('Canvas/res/audio/wrong').getComponent(cc.AudioSource).clip;
		// this.bigStarClip = cc.find('Canvas/res/audio/big_star').getComponent(cc.AudioSource).clip;
		// this.btnClip = cc.find('Canvas/res/audio/btn').getComponent(cc.AudioSource).clip;
		// this.finishClip = cc.find('Canvas/res/audio/finish').getComponent(cc.AudioSource).clip;
		// this.selectClip = cc.find('Canvas/res/audio/select').getComponent(cc.AudioSource).clip;
		// this.starCountClip = cc.find('Canvas/res/audio/star_count').getComponent(cc.AudioSource).clip;

		// this.beginTipClip = cc.find('Canvas/res/audio/begin_tip').getComponent(cc.AudioSource).clip;

	},



	initView() {

		console.log(' in initView');

		this.initBg();
		this.initCurData();
		this.initCurWord();
		this.initScorePanel();
		this.startTiming();

	},

	showCurWordSound() {
		if (!this.curData) {
			return;
		}
		delayCall(0.8, () => {
			if (this.isDestroy) {
				return;
			}
			playAudioByUrl(this.curData.audio_url);
		})
	},


	initScorePanel() {

		const scorePanel = getSprNode("score_item");
		scorePanel.x = this.canvas.width / 2 - scorePanel.width / 2 - 15;
		scorePanel.y = this.canvas.height / 2 - scorePanel.height / 2 - 15;
		this.canvas.addChild( scorePanel );
		// scorePanel.active = false;

		// c05610
		const scoreLabelNode = this.getRichText("0", 35, "#ffffff", 2, "#e6a519");
		scoreLabelNode.x = 20;
		scoreLabelNode.y = 5;
		scorePanel.addChild(scoreLabelNode);
		this.scoreLabel = scoreLabelNode.getComponent(cc.RichText);
		
	},


	addScore() {
		this.score ++;
		this.refreshRichText(this.scoreLabel.node, this.score);
	},


	startTiming() {

		console.log(" in startTiming 1 ")
		const middleLayer = cc.find('middleLayer');
		if (middleLayer) {
			console.log(" in startTiming 2")
			middleLayer.getComponent('middleLayer').startTiming();
		}
	},


	initBg() {
		
		console.log("this.data.bg_pic_url: ", this.data.bg_pic_url);

		const bgLayer = new cc.Node();
		bgLayer.width = this.canvas.width;
		bgLayer.height = this.canvas.height;
		this.canvas.addChild(bgLayer);
		this.bgLayer = bgLayer;


		const bg = getSprNode("bg");
		this.bgLayer.addChild(bg);
		bg.scale = this._mapScaleMax;

		const panel = getSprNode("panel");
		this.bgLayer.addChild(panel);
		panel.scale = this._mapScaleMin;
		// panel.anchorY =0;
		panel.y = -this.canvas.height / 2 + panel.height / 2 * panel.scale;
		this.panel = panel;

		
		const wordNumLabel = this.getRichText("--/--", 40, "#ffffff", 0, "#ffffff", true, true);
		panel.addChild(wordNumLabel);
		wordNumLabel.y = panel.height / 2 - 113.5;
		this.groupLabel = wordNumLabel;




		const wordBg = getSprNode("word_bg");
		panel.addChild(wordBg);
		wordBg.y = 170 - 521;
		const wordBgSpr = wordBg.getComponent(cc.Sprite);
		wordBgSpr.type = cc.Sprite.Type.SLICED;
		wordBg.baseW = wordBg.width;
		this.wordBg = wordBg;

	},

	refreshGroupLabel() {

		if (this.curDataIndex >= this.data.rows.length) {
			return;
		}

		const text = this.curDataIndex + 1 + " / " + this.data.rows.length;
		this.refreshRichText(this.groupLabel, text);
	},

	initCurData() {
		this.curData = this.data.rows[this.curDataIndex];

		this.refreshGroupLabel(); 
		this.showCurWordSound();

	},

	initCurWord() {
		this.initPanelText();
		this.initLetter();
	},

	initPanelText() {
		// const panelLabelNode = this.getRichText("", 240, "#fff195", 12, "#953b1c")
		// this.panel.addChild(panelLabelNode, 5);
		// panelLabelNode.y = this.panel.height / 2 - 0;
		// this.panel.labelNode = panelLabelNode;

		let isAnim = true;
		if (!this.panelLabelNode) {
			const labelNode = this.getRichText("", 240, "#fff195", 12, "#953b1c", true)
			this.panel.addChild(labelNode, 5);
			labelNode.x = -20;
			labelNode.y = this.panel.height / 2 + 80 - 521;
			this.panelLabelNode = labelNode;
			isAnim = false;
		}

		const panelLabelNode = this.panelLabelNode;
		const panelLabel = panelLabelNode.getComponent(cc.RichText);


		const refreshSize = () => {
			this.delayCall(0.01, () => {

				const maxW = this.panel.width * 0.73
				if (panelLabelNode.width > maxW) {
					panelLabelNode.scale = maxW / panelLabelNode.width;
				} else {
					panelLabelNode.scale = 1;
				}
			})
		}


		if (isAnim) {

			console.log('isAnim: ' , this.isAnim);
			this.disappearAnim(panelLabelNode, 0.3, ()=> {

				this.refreshRichText(panelLabelNode, this.curData.text_cn);
				// panelLabel.cacheMode = cc.Label.CacheMode.CHAR
				refreshSize();

				this.appearAnim(panelLabelNode, 0.3);
			})
		} else {
			this.refreshRichText(panelLabelNode, this.curData.text_cn);
			// panelLabel.cacheMode = cc.Label.CacheMode.CHAR
			refreshSize();
		}

	

	
	},

	delayCall(time, callback) {

		delayCall(time, () => {
			if(this.isDestroy) {
				return;
			}

			callback && callback();
		})
	},




	async initLetter() {

		let isAnim = true;
		if (!this.letterLayer) {
			this.letterLayer = new cc.Node();
			this.wordBg.addChild(this.letterLayer);
			isAnim = false;	
		} else {
			this.letterLayer.removeAllChildren();
		}

		this.disappearAnim(this.letterLayer, 0.3);
		await asyncDelay(0.3)
		this.appearAnim(this.letterLayer, 0.3);


		const curTextEN = this.curData.text_en;
		const curRandomText = this.shuffleWord(curTextEN)

		const edgeW = 50;
		const disW = 20;
		const itemW = 185;

		let totalW = curRandomText.length * (itemW + disW);
		const startX = -totalW / 2 + (itemW + disW) / 2;

		this.letterBgArr = [];
		this.letterArr = [];

		const maxW = this.canvas.width * 0.97 * 0.95 ;
		if (totalW > maxW) {
			this.letterLayer.scale = maxW / totalW;
			// totalW = maxW;
		} else {
			this.letterLayer.scale = 1;
		}

		for (let i=0; i<curRandomText.length; i++) {
			const letterBg = this.getLetterBg();
			letterBg.index = i;
			this.letterLayer.addChild(letterBg);
			this.letterBgArr.push(letterBg);
			letterBg.x = startX + i * (disW + itemW);

			console.log("letterBg.y: " + letterBg.y);

			const letter = this.getLetter(curRandomText[i]);
			letter.y = letterBg.y;
			letter.x = letterBg.x;
			letter.offY = letter.y;
			letter.baseX = letter.x;
			letter.baseY = letter.y;
			this.letterLayer.addChild(letter);
			this.letterArr.push(letter);
			letter.baseParent = letter.parent;

			letterBg.rect = letterBg.getBoundingBoxToWorld();
			
			letterBg.letter = letter;
			letter.letterBg = letterBg;

			this.checkChangeLetterBg(letter, i);
		}



		this.wordBg.width = Math.max(this.wordBg.baseW, totalW);

		console.log('curRandomText: ' , curRandomText);
	},

	getLetterBg() {
		const bgNode = new cc.Node();
		const yellowBg = getSprNode("letter_bg_y");
		bgNode.addChild(yellowBg);
		const blueBg = getSprNode("letter_bg_b");
		bgNode.addChild(blueBg);
		yellowBg.active = false;
		// blueBg.active = false;

		bgNode.yNode = yellowBg;
		bgNode.bNode = blueBg;

		bgNode.width = yellowBg.width;
		bgNode.height = yellowBg.height;

		bgNode.on('touchstart', () => {

			// console.log(' in touch~')
			// if (!bgNode.letter) {
			// 	return;
			// }

			// const letter = bgNode.letter;
			// this._curShowItem = letter;			

			if (bgNode.isRight) {
				return;
			}

			const letter = bgNode.letter;

			if (letter.isMove) {
				return;
			}

			this._curShowItem = letter;		


			const worldPos = letter.parent.convertToWorldSpaceAR(cc.v2(letter.x, letter.y));
			this._curShowItem.parent = this.canvas;
			this._curShowItem.x = worldPos.x - this.canvas.width / 2;
			this._curShowItem.y = worldPos.y - this.canvas.height / 2;

			if (letter.baseX == null) {
				letter.baseX = letter.x;
				letter.baseY = letter.y;
			}


			



		})


		return bgNode;
	},

	getLetter(text) {
		const node = new cc.Node();
		// const letterY = this.getRichText(text, 140, "#b4502e", 2, "#ffffff", true, true);
		// const letterB = this.getRichText(text, 140, "#3a77ad", 2, "#ffffff", true, true);
		const letterY = this.getLabelNew(text, 140, "#b4502e", 4, "#ffffff", true);
		const letterB = this.getLabelNew(text, 140, "#3a77ad", 4, "#ffffff", true);

		letterB.cacheMode = cc.Label.CacheMode.CHAR
		letterY.cacheMode = cc.Label.CacheMode.CHAR

		letterY.active = false;



		node.yNode = letterY;
		node.bNode = letterB;

		node.addChild(letterY);
		node.addChild(letterB);

		node.text = text;

		node.on('touchstart', () => {

			if (node.isRight) {
				return;
			}

			if (node.isMove) {
				return;
			}

			this._curShowItem = node;			

			const worldPos = node.parent.convertToWorldSpaceAR(cc.v2(node.x, node.y));
			this._curShowItem.parent = this.canvas;
			this._curShowItem.x = worldPos.x - this.canvas.width / 2;
			this._curShowItem.y = worldPos.y - this.canvas.height / 2;

			if (node.baseX == null) {
				node.baseX = node.x;
				node.baseY = node.y;
			}
		})

		return node;
	},

	checkChangeLetterBg(letter, index) {

		// const letter = this.letterArr[index];
		const letterText = letter.text;
		const letterBg = this.letterBgArr[index];

		const curTextEN = this.curData.text_en;
		if (letterText == curTextEN[index]) {
	
			letter.yNode.active = true;
			letter.bNode.active = false;

			letterBg.yNode.active = true;
			letterBg.bNode.active = false;

			letterBg.isRight = true;
			letter.isRight = true;
		} else {

			letter.yNode.active = false;
			letter.bNode.active = true;

			letterBg.yNode.active = false;
			letterBg.bNode.active = true;
		}
	},


	shuffleWord(word) {
		const letters = word.split("");
	
		if (letters.length <= 1 || new Set(letters).size === 1) {
			return word;
		}
	
		for (let i = letters.length - 1; i > 0; i--) {
			const j = Math.floor(Math.random() * (i));
			[letters[i], letters[j]] = [letters[j], letters[i]];
		}
	
		return letters.join("");
	},



	getRichText(text, fontSize, color, outlineWidth, outlineColor, isBold=false, isFont=false) {

		const labelNode = new cc.Node();
		const label = labelNode.addComponent(cc.RichText);


		label.string = `<outline color=${outlineColor} width=${outlineWidth}><color=${color}><size=${fontSize}>${text}</></color></outline>`
		if (isBold) {
			label.string = `<b>${label.string}</b>`
			labelNode.isBold = true;
		}
		
		labelNode.color = cc.Color.BLACK;
		// label.fontSize = fontSize;

		labelNode.baseFontSize = fontSize;
		labelNode.baseColor = color;
		labelNode.baseOutlineColor = outlineColor;
		labelNode.baseOutlineWidth = outlineWidth;

		label.lineHeight = fontSize * 1.2;

		label.horizontalAlign = cc.macro.TextAlignment.CENTER;

		if (isFont) {
			label.font = cc.find('Canvas/res/font/MMTB').getComponent(cc.Label).font;
			label.MMTB = label.font;
		}
	
		return labelNode;
	},


	refreshRichText(labelNode, text) {

		const label = labelNode.getComponent(cc.RichText);
		const {baseFontSize, baseColor, baseOutlineColor, baseOutlineWidth} = labelNode;
		label.string = `<outline color=${baseOutlineColor} width=${baseOutlineWidth}> <color=${baseColor}><size=${baseFontSize}>${text}</></color></outline>`
		if (label.MMTB) {
			label.font = label.MMTB;
		}
	},






	showInsertCard() {
		const middleLayer = cc.find('middleLayer');
		if (middleLayer) {
			const script = middleLayer.getComponent('middleLayer');
			if (script.showTipInsertCard) {
				script.showTipInsertCard(() => {
					
					this.showCurCard();
					this.startTiming();
					this.startTesting();
				})
			}

			delayCall(7, () => {
				if (this.isDestroy) {
					return;
				}
				if (script.closeTipAnim) {
					script.closeTipAnim()
				}
			})
		}
	},

	startTiming() {

		console.log(" in startTiming 1 ")
		const middleLayer = cc.find('middleLayer');
		if (middleLayer) {
			console.log(" in startTiming 2")
			middleLayer.getComponent('middleLayer').startTiming();
		}
	},


	showResultLayer() {

		console.log('show resultPanel ')
		const middleLayer = cc.find('middleLayer');
		if (middleLayer) {
			middleLayer.getComponent('middleLayer').showResultLayer(this.data.rankingType, this.score);
		}
	},



	initQuesCountLabel() {
		const labelNode = this.getLabel("1 / " + this.quesArr.length, 60);
		labelNode.color = cc.Color.fromHEX(new cc.Color(), '#26723d');
		this.bgLayer.addChild(labelNode, 3);
		labelNode.y = -this.canvas.height / 2 + 100 * this._mapScaleMin;
		this.quesCountLabel = labelNode.getComponent(cc.Label);
	},


	initBtn() {
		const soundBtn = getSprNode("btn_bg");
		// const soundIcon = getSprNode("sound_icon");
		// soundBtn.addChild(soundIcon);


		const soundIconBase = cc.find("Canvas/res/anim/soundAnim");
		const soundIcon = cc.instantiate(soundIconBase);
		soundBtn.addChild(soundIcon);

		const soundAnimBase = cc.find("Canvas/res/anim/soundAnim");
		const soundAnimNode = cc.instantiate(soundAnimBase);
		soundBtn.addChild(soundAnimNode);
		const soundAnim = soundAnimNode.getComponent(cc.Animation);
		soundAnim.play('sound');
		soundAnimNode.opacity = 255;

		soundBtn.icon = soundIcon;
		soundBtn.anim = soundAnimNode;

		soundBtn.scale = this._mapScaleMin;
		this.bgLayer.addChild(soundBtn, 2);
		soundBtn.x = -this.canvas.width / 2 + 100 * this._mapScaleMin;
		soundBtn.y = -this.canvas.height / 2 + 100 * this._mapScaleMin;
		this.soundBtn = soundBtn;

		this.stopSoundAnim();


		const nextBtn = getSprNode("btn_next");
		nextBtn.scale = this._mapScaleMin;
		this.bgLayer.addChild(nextBtn, 2);
		nextBtn.x = this.canvas.width / 2 - 100 * this._mapScaleMin;
		nextBtn.y = -this.canvas.height / 2 + 100 * this._mapScaleMin;
		this.nextBtn = nextBtn;

		soundBtn.on(cc.Node.EventType.TOUCH_START, () => {
			if (soundBtn.opacity < 254) {
				return;
			}

			this.playSoundAnim();

			playBtnAnim(soundBtn);
			this.playCurQuesAudio(() => {
				this.stopSoundAnim();
			});
		})

		nextBtn.on(cc.Node.EventType.TOUCH_START, () => {
			if (nextBtn.opacity < 254) {
				return;
			}
			playBtnAnim(nextBtn);
	
			this.showCardWrong();

			this.btnDisable(nextBtn);
			this.btnDisable(soundBtn);
			this.stopSoundAnim();

		})

	},

	playSoundAnim() {
		const {icon, anim} = this.soundBtn;
		icon.active = false;
		anim.active = true;
	},

	stopSoundAnim() {
		const {icon, anim} = this.soundBtn;
		icon.active = true;
		anim.active = false;
	},


	initCurWordCard() {
		const card = this.getCard();
		this.bgLayer.addChild(card);

		card.x = -this.canvas.width / 2 - card.width / 2 * card.scale;
		this.curCard = card;

		this.quesCountLabel.string = (this.quesArrIndex + 1) + " / " + this.quesArr.length;
	},

	playCurQuesAudio(callback) {
		cc.audioEngine.stopAll();
		playAudioByUrl(this.curQues.audio_url, () => {
			if(this.isDestroy) {
				return;
			}
			playAudioByUrl(this.curQues.audio_cn_url, callback);
		});
	},

	showCurCard() {

		this.btnDisable(this.nextBtn);

		cc.tween(this.curCard)
			.to(1, {x: 0}, {easing:"quintOut"})
			.call(() => {
				this.isCanCheck = true;
				this.btnEnable(this.nextBtn);
				this.btnEnable(this.soundBtn);
			})
			.start();

		this.playCurQuesAudio();
		console.log('curQues: ', this.curQues);
	},

	

	getCard() {
		const cardNode = new cc.Node();
		const cardTop = getSprNode("card_top");
		const cardBottom = getSprNode("card_bottom");
		cardNode.addChild(cardTop);
		cardNode.addChild(cardBottom);
		cardTop.opacity = 0;

		cardNode.width = cardTop.width;
		cardNode.height = cardTop.height;

		cardNode.scale = this._mapScaleMin;
		cardNode.baseS = this._mapScaleMin;
		cardNode.top = cardTop;
		cardNode.bottom = cardBottom;

		cardBottom.on("touchstart", () => {

			// this.showCardRight();
			// return;

			// if (Math.abs(cardNode.x) < 10 ) {
			// 	this.playCurQuesAudio();
			// }

			if (this.soundBtn.opacity < 254) {
				return;
			}
			this.playSoundAnim();

			this.playCurQuesAudio(() => {
				this.stopSoundAnim();
			});

		})

		const labelNode = this.getLabel(this.curQues.text_en, 137);
		labelNode.color = cc.Color.fromHEX(new cc.Color(), '#ff5638')
		const maxW = cardTop.width * 0.8;
		delayCall(0.01, () => {
			console.log("labelNode.width: ", labelNode.width);
			console.log("maxW: ", maxW);
			if (labelNode.width > maxW) {
				labelNode.scale = maxW / labelNode.width;
			}
			cardTop.active = false;
			cardTop.opacity = 255;


		})
		cardTop.addChild(labelNode);

		const imgArr = JSON.parse(this.curQues.image_url)

		const picUrl =imgArr[0]
		console.log(" picUrl: ", picUrl);
		getSprNodeByUrl(picUrl, (spr) => {
			const sprNode = spr.node;
			setSprNodeMaxLen(sprNode, cardTop.height * 0.4, cardTop.height * 0.4);
			cardTop.addChild(sprNode)
			sprNode.anchorY = 0;
			sprNode.y = -50;
			labelNode.y = -150;
		})


		return cardNode;
	},

	showCardWrong() {
		this.isCanCheck = false;

		this.cardBottomLeave(this.curCard, () => {
			this.enterNewCard();
		});
	},

	cardBottomLeave(card, callback) {

		playAudio(this.failClip);

		const time = 0.4;
		cc.tween(card)
			.delay(0.1)
			.parallel(
				cc.tween().to(time, {angle: -360}, {easing: "sineOut"}),
				cc.tween().to(time, {x: this.canvas.width / 2 + card.height * card.scale}, {easing: "sineOut"})
			)
			.delay(0.05)
			.call(() => {
				callback();
			})
			.start();

	},

	showCardRight() {

		this.isCanCheck = false;

		this.cardToTop(this.curCard, () => {

			delayCall(0.5, () => {
				this.cardTopLeave(this.curCard, () => {

					this.enterNewCard();
				});

			})
		});
	},

	cardToTop(card, callback) {


		const baseS = card.baseS || 1;
		const time = 1;
		const changeAngle = 10;
		// const t = cc.tween;
		cc.tween(card)
			.parallel(
				cc.tween().to(time/2, {skewY: changeAngle}),
				cc.tween().to(time/2, {scaleX: 0, scaleY: baseS * 1}, {easing: "cubicIn"})
			)
			.call(() => {
				card.top.active = true;
				card.bottom.active = false;
				card.skewY = 180 - changeAngle;
				playAudio(this.rightClip);

			})
			.parallel(
				cc.tween().to(time/2, {skewY: 180}),
				cc.tween().to(time/2, {scaleX: baseS, scaleY: baseS}, {easing: "cubicOut"})
			)
			.call(() => {
				// this.playCardRightAnim(card);
				callback();
			})
			.start();

	},
	

	cardTopLeave(card, callback) {

		playAudio(this.move2Clip);

		const time = 0.4;
		cc.tween(card)
			.to(time, {x: this.canvas.width / 2 + card.height * card.scale}, {easing: "cubicIn"})
			.delay(0.1)
			.call(() => {
				callback();
			})
			.start();
	},

	enterNewCard() {

		this.quesArrIndex ++;
		this.initCurQues();
		if (!this.curQues) {
				this.gameEnd();
			return;
		}

		this.initCurWordCard();
		this.showCurCard();
	},

	btnDisable(btn) {
		cc.tween(btn)
			.to(0.2, {opacity: 120}, {easing:"sineInOut"})
			.start();
	},
	btnEnable(btn) {
		cc.tween(btn)
			.to(0.2, {opacity: 255}, {easing:"sineInOut"})
			.start();
	},






	initRestartNode() {
		this.restartNode = cc.find("Canvas/restart_node");
		this.restartNode.zIndex = 10;
		this.restartNode.active = false;

		const restartBtn = cc.find("btn_restart", this.restartNode);

		restartBtn.on('click', () => {
			console.log('in restartNode ');
			const middleLayer = cc.find('middleLayer');
			if (middleLayer) {
				middleLayer.getComponent('middleLayer').reloadBundle();
			}
		})
	},

	initVideoNode() {
		const videoNode = cc.find("Canvas/video_node");
		this.videoNode = videoNode;
		videoNode.zIndex = 11;


		// videoNode.width = 720;
		// videoNode.height = 1280;

		const closeBtn = cc.find("videoCloseBtn", videoNode)
		closeBtn.on("click", () => {
			console.log(' in closeBtn')
			this.hideVideoNode();
		})


		const videoPlayerNode = cc.find("videoPlayer", videoNode);
		const video = videoPlayerNode.getComponent(cc.VideoPlayer);

		video.stayOnBottom = true;

		this.video = video;

		video.node.on('meta-loaded', (e) => {
			console.log('meta-loaded e:', e);
		})
		video.node.on('ready-to-play', async (e) => {

			console.log('e: ', e);
			if (this.isDestroy) {
				return;
			}

			// video.play();
			// checkIsPlaying();

		})

		const checkIsPlaying = () => {

			delayCall(0.05, () => {

				if (video.currentTime > 0) {
		
					video.node.isLoadEnd = true;
					video.pause();

					// this.checkCanPlayVideo();
				} else {
					checkIsPlaying();
				}
			})

		}

		video.node.on('completed', () => {
			console.log(' in completed!!!!');

			// if (this.isLast && this.playTimes > 0) {
			// 		this.showGoodjob();
			// } else {
			// 	this.showMask(() => {
			// 		if (!this.isLocal) {
			// 			callMiddleLayerFunction('PSQS_play_animate_over', null, () => {})
			// 		}
			// 	})
			// }
		})
	},

	showVideoNode() {
		// if (!this.video.node.isLoadEnd) {
		// 	delayCall(0.1, () => {
		// 		this.showVideoNode();
		// 	})
		// 	return
		// }

		this.videoNode.active = true;
		this.video.play();

		this.bgLayer.active = false;
		this.scrollView.node.active = false;
		this.tipNode.active = false;
		console.log(" in showVideoNode");

	},

	hideVideoNode() {
		this.video.pause();
		this.video.currentTime = 0;
		this.videoNode.active = false;

		this.bgLayer.active = true;
		this.scrollView.node.active = true;
		this.tipNode.active = true;

	},

	initTipPanel() {
		const tipNode = cc.find("Canvas/tip_node");
		tipNode.zIndex = 10;

		if (this.isVertical) {
			tipNode.scale = this.canvas.width / 1080;
		}
		this.tipNode = tipNode;

		
		const clickFunc = () => {
			tipNode.active = false;
			this.showStartAudio();
		}


		const guideVideoNode = cc.find("tip_panel/btn_guide_video", tipNode);
		guideVideoNode.on("click", () => {
			this.showVideoNode();
		});

		const guideJumpNode = cc.find("tip_panel/btn_guide_jump", tipNode);
		guideJumpNode.on("click", clickFunc);

		// const okBtn = cc.find("tip_panel/ok_btn", tipNode);
		// okBtn.on("click", clickFunc);

		const closeBtn = cc.find("tip_panel/close_btn", tipNode);
		closeBtn.on("click", clickFunc);
	},


	initWord() {

		if (this.isVertical) {
			this.initVerticalWord();
			return;
		}

		this.wordBgArr = [];

	
		const sv = this.getScrollView(); 
		this.scrollView = sv;

		
		const content = sv.content;
		content.width = sv.node.width;
		content.height = sv.node.height;
		

		const offX = this.titleWidth;
		const baseX = -460;
		const baseY = 0 //sv.node.height / 2 //-200 //300 - this.bg.height / 2;
		const disX = 50;
		const disY = 100;
		const lineBaseY = -150;
		const lineDisY = 220;
		let curY;
		let row = 0;
		let col = 0;
		const quesArr = this.quesArr
		let curPage;

		console.log("quesArr: " + JSON.stringify(quesArr));

		for (let i=0; i<quesArr.length; i++) {

			let pageBg;
			if (i % 6 == 0) {
				pageBg = getSprNode("h_page_1");
				curPage = pageBg;
				content.addChild(pageBg, 1);
				pageBg.anchorY = 1;
				pageBg.x = -pageBg.width / 2 - disX / 2;
				if (curY == null) {
					pageBg.y = baseY;
				} else {
					pageBg.y = curY - disY - pageBg.height; 
				}
				curY = pageBg.y;

				col = 0;
				row = 0;
			}

			if ( (i + 3) % 6 == 0 ) {
				const itemBttom = getSprNode("h_book_item_b");
				itemBttom.y = curPage.y - curPage.height / 2;
				const itemTop = getSprNode("h_book_item_t");
				itemTop.y = itemBttom.y;

				content.addChild(itemBttom);
				content.addChild(itemTop, 2);

				pageBg = getSprNode("h_page_2");
				curPage = pageBg;
				content.addChild(pageBg, 1);
				pageBg.anchorY = 1;
				pageBg.x = pageBg.width / 2 + disX / 2;
				pageBg.y = curY;

				row = 0;
				col = 0;
			}

			const bgResName = 'bg_line';
			const wordBg = getSprNode(bgResName)

			curPage.addChild(wordBg);

			wordBg.x = curPage.width / 2 - wordBg.width / 2 - 50 //baseX + col * disX + offX;
			wordBg.y = lineBaseY - row * lineDisY;

			row ++;

			// if ((i+1) % 2 == 0) {
			// 	row ++;
			// 	col = 0;
			// }

			wordBg.data = quesArr[i];
			// content.addChild(wordBg);
			// this.bg.addChild(wordBg);

			this.wordBgArr.push(wordBg);


			this.setWordQuesText(quesArr[i], wordBg);

			this.setTitleSound(quesArr[i], wordBg)
			
			this.setWordCountdown(quesArr[i], wordBg);
			
			this.setOneWord(quesArr[i], wordBg);

			this.setWordAnswerIcon(quesArr[i], wordBg);

			this.setWordSound(quesArr[i], wordBg);

			console.log('i: ', i);
			console.log('wordBg: ', wordBg);

			// const curTempH = Math.abs( wordBg.y - wordBg.height / 2 - disY /2);
			const curTempH = Math.abs(curY) + curPage.height + disY / 2;
			console.log('curTempH: ', curTempH);

			if (content.height < curTempH) {
				content.height = curTempH;
				console.log('curTempH 2: ', curTempH);
			}
		
		}
	},

	addOnePageBg(content, curY) {


		const pageBg = getSprNode("bg_write_2");
		pageBg.anchorY = 0.96;
		pageBg.scale = content.width / pageBg.width;
		pageBg.y = -curY;

		const pageH = pageBg.height * pageBg.scaleY * pageBg.anchorY;
		if (curY + pageH > content.height) {
			content.height = curY + pageH
		}

		const pageLine = getSprNode("bg_write_line");
		pageLine.scale = pageBg.scale;
		pageLine.y = -curY;
		pageLine.anchorY = 0.8;
		content.lineLayer.addChild(pageLine);


		content.addChild(pageBg)

		return pageBg.y;
	},

	getScrollView() {

		const svNode = cc.find("Canvas/ScrollView");
		svNode.x = this.bg.x;
		svNode.y = this.bg.y;
		svNode.zIndex = 10;
		svNode.width = this.bg.width;
		svNode.height = this.bg.height * 0.98;

		const svMaskNode = cc.find("Canvas/ScrollView/view");
		svMaskNode.width = svNode.width;
		svMaskNode.height = svNode.height;

		const sv = svNode.getComponent(cc.ScrollView);
		return sv;
	},

	setWordQuesText(quesData, wordBg) {

		let rate = 1;
		if (this.isVertical) {
			rate = wordBg.scale;
		}


		let textMaxW = (wordBg.parent.width - wordBg.width * wordBg.scaleX) / 2 + wordBg.x;
		textMaxW *= 0.9;
		wordBg.textMaxW = textMaxW;

		const labelNode = this.getLabel(quesData.text_cn || '', 37);
		labelNode.color = this.getColor('#999999');
		// labelNode.x = wordBg.x - wordBg.width / 2 * wordBg.scaleX - 140;
		labelNode.x = wordBg.x - wordBg.width / 2 * wordBg.scaleX - textMaxW / 2;
		labelNode.y = wordBg.y + 40 * rate;
		labelNode.scale = wordBg.scale * 0.8;
		wordBg.parent.addChild(labelNode);

		labelNode.active = false;
		wordBg.titleNode = labelNode;

		delayCall(0.01, () => {
			const maxW = textMaxW ;
			// console.log("width: ", labelNode.width);
			if (labelNode.width > maxW) {
				labelNode.scale = maxW / labelNode.width;
			}
		})

	},

	setTitleSound(quesData, wordBg) {

		let rate = 1;
		if (this.isVertical) {
			rate = wordBg.scale;
		}

		const soundNode = new cc.Node();
		soundNode.parent = wordBg.parent;
		// soundNode.x = wordBg.x - wordBg.width / 2 * wordBg.scaleX - 200;//wordBg.x - 450;
		// soundNode.x = wordBg.x - wordBg.width / 2 * wordBg.scaleX - 200;//wordBg.x - 450;
		soundNode.x = wordBg.titleNode.x - 50;

		soundNode.y = wordBg.y - 40;

		// const soundIcon = getSprNode("sound_ani_1");
		// soundNode.addChild(soundIcon);
		const soundAnimNode = cc.instantiate( cc.find("Canvas/res/anim/laba") );
		soundNode.addChild(soundAnimNode);
		const soundAnim = soundAnimNode.getComponent(cc.Animation);


		// soundAnim.play('laba');
		soundNode.active = false;
		// soundAnimNode.active = false;
		
		wordBg.textSoundNode = soundNode;
		// wordBg.textSoundAnimNode = soundAnimNode;
		wordBg.textSoundAnim = soundAnim;

	},

	setWordCountdown(quesData, wordBg) {

		let rate = 1;
		if (this.isVertical) {
			rate = wordBg.scale;
		}

		const cdNode = cc.instantiate( cc.find("Canvas/res/progress/cd") );
		cdNode.parent = wordBg.parent;
		// cdNode.x = wordBg.x - wordBg.width / 2 * wordBg.scaleX - 100;
		cdNode.x = wordBg.titleNode.x + 50;

		cdNode.y = wordBg.y - 40;

		cdNode.scale = 0.8;

		const cd = cdNode.getComponent(cc.ProgressBar);

		const labelNode = this.getLabel(0, 40);
		const label = labelNode.getComponent(cc.Label);
		label.font = '';
		labelNode.color = this.getColor("#a9be67");
		labelNode.parent = cdNode;
		// labelNode.x = cdNode.x;
		labelNode.y = - 3;

		console.log('cdNode: ', cdNode);
		cdNode.active = false;
		cdNode.label = label;

		wordBg.cdNode = cdNode;
		wordBg.cd = cd;
	},

	setOneWord(quesData, wordBg) {

		let rate = 1;
		if (this.isVertical) {
			rate = wordBg.scale;
		}

		const labelNode = this.getLabel(quesData.text_en || '', 120);
		labelNode.parent = wordBg.parent;
		labelNode.x = wordBg.x;
		labelNode.y = wordBg.y - 5 * rate;

		labelNode.active = false;
		labelNode.data = quesData;

		labelNode.scale = rate;

		wordBg.on('touchstart', () => {
			// this.showLetterLabel(labelNode, true);
			// this.showAnswerIcon(wordBg, true)
		})

		wordBg.wordNode = labelNode;
	},

	setWordAnswerIcon(quesData, wordBg) {

		let rate = 1;
		if (this.isVertical) {
			rate = wordBg.scale;
		}

		
		const answerNode = new cc.Node();
		answerNode.parent = wordBg.parent;
		answerNode.zIndex = 10;
		answerNode.x = wordBg.x + wordBg.width/2 * wordBg.scaleX + 50 * rate;
		answerNode.y = wordBg.y;
		answerNode.scale = 0.5 * rate;

		const rightIcon = getSprNode("icon_right");
		answerNode.addChild(rightIcon);
		const rightAnimNode = cc.instantiate( cc.find("Canvas/res/anim/rightIcon") );
		const rightAnim = rightAnimNode.getComponent(dragonBones.ArmatureDisplay);
		// rightAnim.playAnimation('newAnimation', 1);
		rightAnimNode.scale = 1 / answerNode.scale;
		rightAnimNode.y = 20 * rate;
		rightAnimNode.x = -wordBg.width / 3;
		answerNode.addChild(rightAnimNode);

		const wrongIcon = getSprNode("icon_wrong");
		answerNode.addChild(wrongIcon);
		const wrongAnimNode = cc.instantiate( cc.find("Canvas/res/anim/wrongIcon") );
		const wrongAnim = wrongAnimNode.getComponent(dragonBones.ArmatureDisplay);
		// wrongAnim.playAnimation('newAnimation', 1);
		wrongAnimNode.scale = 1 / answerNode.scale;
		wrongAnimNode.y = 15 * rate;
		wrongAnimNode.x = rightAnimNode.x
		answerNode.addChild(wrongAnimNode);

		rightAnimNode.active = false;
		wrongAnimNode.active = false;
		rightIcon.active = false;
		wrongIcon.active = false;

		wordBg.rightIcon = rightIcon;
		wordBg.rightAnim = rightAnim;
		wordBg.wrongIcon = wrongIcon;
		wordBg.wrongAnim = wrongAnim;

	},

	setWordSound(quesData, wordBg) {

		let rate = 1;
		if (this.isVertical) {
			rate = wordBg.scale;
		}


		const soundBtn = getSprNode("sound_1");
		soundBtn.parent = wordBg.parent;
		soundBtn.x = wordBg.x + wordBg.width/2 * wordBg.scaleX + 50 * rate;
		soundBtn.y = wordBg.y - 50 * rate;
		soundBtn.scale = 0.8 * rate;


		soundBtn.active = false;
		wordBg.wordSoundBtn = soundBtn;

		soundBtn.on("touchstart", () => {
			playAudioByUrl(quesData.audio_url, () => {

			})
		})
	},


	getColor(colorText) {
		const temp = new cc.Color();
		const color = temp.fromHEX(colorText)
		return color;
	},

	initVerticalWord() {


		const sv = this.getScrollView(); 
		this.scrollView = sv;

		
		const content = sv.content;
		content.width = sv.node.width;
		content.height = 0;

		const lineLayer = new cc.Node();
		content.addChild(lineLayer);
		content.lineLayer = lineLayer;

		const pageBg1 = getSprNode("bg_write_1");
		pageBg1.anchorY = 1;
		pageBg1.scale = content.width / pageBg1.width;
		content.addChild(pageBg1);

		this.wordBgArr = [];

		const offX = this.titleWidth;
		const baseX = 50;
		const baseY = -300;
		const disX = -baseX * 2;
		const disY = 380;
		let row = 0;
		let col = 0;

		console.log('baseY: ', baseY);
		let curY = 0;
		let pageY = 0;
		let lastWordBg;
		const quesArr = this.quesArr;
		for (let i=0; i<quesArr.length; i++) {
			// const bgResName = 'horizontal/' + (i+1);

			let pageTempY;
			if (i != 0 && i % 3 == 0) {
				pageY += -200 * content.scale;
				pageTempY = this.addOnePageBg(content, curY);
			} 
			// const bgResName = 'horizontal/' + (1);
			const wordBg = getSprNode("bg_line")
			wordBg.x = baseX + col * disX + offX;
			wordBg.y = baseY - row * disY + pageY;

			if (lastWordBg) {
				wordBg.y = lastWordBg.y - disY;
			}

			if (pageTempY != null) {
				wordBg.y = pageTempY - 330;
			}

			col ++;

			// if ((i+1) % 2 == 0) {
				row ++;
				col = 0;
			// }

			wordBg.data = quesArr[i];
			wordBg.scale = pageBg1.scale;
			// this.bg.addChild(wordBg);
			content.addChild(wordBg);

			this.wordBgArr.push(wordBg);


			this.setWordQuesText(quesArr[i], wordBg);

			this.setTitleSound(quesArr[i], wordBg)
			
			this.setWordCountdown(quesArr[i], wordBg);
			
			this.setOneWord(quesArr[i], wordBg);

			this.setWordAnswerIcon(quesArr[i], wordBg);

			this.setWordSound(quesArr[i], wordBg);


			const curTempH = Math.abs( wordBg.y - wordBg.height / 2 - disY /2);
			console.log('curTempH: ', curTempH);

			if (content.height < curTempH) {
				content.height = curTempH;
				console.log('curTempH 2: ', curTempH);
			} 
			curY = content.height;

			lastWordBg = wordBg;

		
		}

	},


	initQuesArr() {
		this.quesArr = [];
		for (let i=0; i<this.data.rows.length; i++) {
			this.quesArr.push(this.data.rows[i]);
		}

		this.quesArr = randomSortByArr(this.quesArr);

		for (let i=0; i<this.quesArr.length; i++) {
			this.sortOneSameWord(this.quesArr[i], i);
		}

		// console.log('this.quesArr: ', this.quesArr);

		this.quesArrIndex = 0;
	},

	sortOneSameWord(wordData, index) {

		const word = wordData.text_en;
		
		let replaceIndex = -1;
		let replaceData;

		for (let i = index+1; i<this.quesArr.length; i++) {
			const {text_en} = this.quesArr[i];

			const newWord = this.trimWord(word);
			const newTextEn = this.trimWord(text_en);

			if (newWord.indexOf(newTextEn) != -1) {

				if (!replaceData) {
					replaceData = this.quesArr[i];
					replaceIndex = i;
				} else {
					if (text_en.length < replaceData.text_en.length) {
						replaceData = this.quesArr[i];
						replaceIndex = i;
					}
				}

			}
		}

		if (replaceData) {
			const temp = this.quesArr[replaceIndex]
			this.quesArr[replaceIndex] = wordData;
			this.quesArr[index] = temp;
		}
	},

	trimWord(_text) {

		let text;
		text = _text.toLowerCase();
		text = text.replace(/(^\s+)|(\s+)|(\s+$)/g,"");
		text = text.replace(/(\'+)|(\’+)|(\.+)|(\!+)/g, "");
		text = text.replace(/(\(+.*\)+)/g, "");
		text = text.replace(/(\（+.*\）+)/g, "");
		return text;
	},

	initCurQues() {

		this.curQues = this.quesArr[this.quesArrIndex];
	},

	initFingerQuesData() {

		const fingerQuesArr = [];

		const fingerAnimaNodeArr = this.fingerAnimaNodeArr;
		for (let i=0; i<fingerAnimaNodeArr.length; i++) {
			const quesData = fingerAnimaNodeArr[i].data;
			fingerQuesArr.push(quesData);
		}

		this.fingerQuesArr = randomSortByArr(fingerQuesArr);

		this.nextFingerQues();

		console.log('fingerQuesArr: ', this.fingerQuesArr);
	},

	showStartAudio() {

		console.log(' in showStartAudio ', this.data.begin_audio_url)
		if (!this.data.begin_audio_url) {
			this.startAudioPlayend();
			return;
		}

		playAudioByUrl(this.data.begin_audio_url, () => {

			console.log(' in playAudio ~~ ')

			this.startAudioPlayend();
		}) 
	},

	startAudioPlayend() {

		console.log(' in startAudioPlayend ')

		this.isBeginAudioEnd = true;

		this.checkStart();


		// if (this.fingerRectArr && this.fingerRectArr.length > 0) {
		// 	this.checkShowFingerQues();
		// }


		// this.startTesting();
	},

	// playCurQuesAudio() {
		
	// 	if (this.curQues && !this.curQues.isFirstEnd) {
	// 		this.curQues.isFirstEnd = true;
	// 		this.curQues.playTimes = 0;
	// 		this.showCurQuesNode();

			
	// 	}

	// 	if (!this.curQues) {
	// 		return;
	// 	}
	// 	// playAudioByUrl(this.curQues.audio_url, () => {

	// 	// })

	// 	console.log(' this.curQues: ', this.curQues);


	// 	let audio_url;
	// 	if (this.curQues.isPlayingCN) {
	// 		audio_url = this.curQues.audio_url;
	// 		this.curQues.isPlayingCN = false;
	// 	} else {
	// 		audio_url = this.curQues.audio_cn_url;
	// 		this.curQues.isPlayingCN = true;
	// 	}

	// 	cc.assetManager.loadRemote(audio_url, (err, audioClip) => {


	// 		const playAudioFunc = (duration) => {
	// 			playAudio(audioClip, () => {

	// 				if (!this.curQues.isAudioPlayed) {
	// 					this.curQues.isAudioPlayed = true;
	// 					this.isCanCheck = true;
	// 				}

	// 				// let time = 0.1;
	// 				// const minDisTime = 3;
	// 				// if (Number(duration) < minDisTime) {
	// 				// 	time = minDisTime - Number(duration);
	// 				// }
	
	// 				// console.log('2 duration is : ', duration);
	
	// 				// if (this.curQues.playTimes >= 3) {
	// 				// 	this.changeNextQues();
	// 				// } 
	
	// 				// delayCall(time, () => {
	// 				// 	this.playCurQuesAudio();
	// 				// })

	// 				delayCall(1.5, () => {
	// 					if (this.isDestroy) {
	// 						return;
	// 					}
	// 					this.playCurQuesAudio();
	// 				})
					
	// 			});
	
	// 			this.curQues.playTimes ++;
	// 		}
      



	// 		const audioId = cc.audioEngine.play(audioClip, false, 0);
	// 		delayCall(0.05, () => {
	// 			const duration = cc.audioEngine.getDuration(audioId)
	// 			// cc.audioEngine.pause(audioId)
				
	// 			console.log('1 duration is : ', duration);
	// 			playAudioFunc(duration);
	// 		})

	// 	});
	
	// },

	changeScrollViewPos(wordBg) {

		let curH;
		if (this.isVertical) {
			curH = Math.abs(wordBg.y);
		} else {
			curH = Math.abs(wordBg.y + wordBg.parent.y);
		}
		const tempH = this.scrollView.node.height / 2;

		this.scrollView.scrollToOffset(cc.v2(0, curH - tempH), 1);
	},


	checkCurQuesWrong() {
		if (!this.curQues.isRight) {
			this.showCurQuesWrong();
		}
	},

	showCurQuesWrong() {
		
		
		const curWordBg = this.wordBgArr[this.quesArrIndex];
		const {wordNode} = curWordBg;

		this.showLetterLabel(wordNode, false);
		this.showAnswerIcon(curWordBg, false)


		return;

		const wordKey = this.curQues.quesLabelId;
		let curQuesWordNode;
		for (let i=0; i<this.animaNodeArr.length; i++) {

			const key = this.animaNodeArr[i].data.index + 1;
			if (wordKey == key) {
				curQuesWordNode = this.animaNodeArr[i];
			}
		}

		if (curQuesWordNode) {
			this.showLetterLabel(curQuesWordNode, false);
		}
		
	},

	hideCurTitle() {
		const curWordBg = this.wordBgArr[this.quesArrIndex];
		const {textSoundNode, cdNode} = curWordBg;

		this.disappearAnim(textSoundNode);
		this.disappearAnim(cdNode);
	},

	changeNextQues() {

		this.isCanCheck = false;

		this.hideJumpBtn();
		this.hideCurTitle();
		this.checkCurQuesWrong();

		this.quesArrIndex ++;
		this.initCurQues();
		if (!this.curQues) {
			// delayCall(1,() => {
				this.gameEnd();
			// })
			return;
		}

	},

	showCurQuesNode() {
		const wordBg = this.wordBgArr[this.quesArrIndex];
		const titleNode = wordBg.titleNode;
		const textSoundNode = wordBg.textSoundNode;
		const textSoundAnim = wordBg.textSoundAnim;
		const cdNode = wordBg.cdNode;
		const cd = wordBg.cd;


		this.countDown(cdNode, cd);
		textSoundAnim.play('laba');

		this.appearAnim(titleNode);
		this.appearAnim(textSoundNode)
		this.appearAnim(cdNode)

		this.changeScrollViewPos(wordBg);

	},

	countDown(cdNode, cdProgress) {
		const data = this.curQues;
		let maxTime = data.text_en.length * 1.5 // data.time;
		// console.log('data.text_en: ' , data.text_cn);
		// if (maxTime < 7) {
		// 	maxTime = 7;
		// }

		cdProgress.progress = 0;
		

		maxTime = 30;
		const baseTime = maxTime;

		let saveTime = new Date().getTime();
		let curTime = saveTime;

		const updateFunc = () => {
			if (this.isDestroy) {
				return;
			}

			if (this.curQues.isRight) {
				cdProgress.progress = 0;
				this.changeNextQues();
				return;
			}

			curTime = new Date().getTime();
			maxTime -= (curTime - saveTime)/1000;

			saveTime = curTime;

			const rate = maxTime / baseTime;
			cdProgress.progress = rate;

			cdNode.label.string = Math.ceil(maxTime);

			if (baseTime - maxTime > 6) {
				this.showJumpBtn();
			}
			if (this.isJump) {
				cdProgress.progress = 0;
				this.isJump = false;
				this.changeNextQues();
				return;
			}

			if (maxTime > 0) {
				delayCall(0.05, () => {
					updateFunc();
				})
			} else {
				cdProgress.progress = 0;

				this.changeNextQues();
			}
			
		}
		
		updateFunc();
	},

	initJumpBtn() {
		this.jumpBtn = getSprNode("btn_skip")
		this.jumpBtn.y = -this.canvas.height / 2 / 4 * 3;
		this.canvas.addChild(this.jumpBtn, 11);
		this.jumpBtn.on("touchstart", () => {
			this.isJump = true;
			this.hideJumpBtn();
		})
	},
	showJumpBtn() {
		console.log(' in showJumpBtn')
		if (!this.jumpBtn) {
			this.initJumpBtn();
		}
		if (this.jumpBtn.active) {
			return;
		}
		this.jumpBtn.active = true;
	},
	hideJumpBtn() {
		if (!this.jumpBtn) {
			return;
		}
		this.jumpBtn.active = false;
	},

	
	appearAnim(node, time=1, callback=null) {
		node.active = true;
		node.opacity = 0
		cc.tween(node)
			.to(time, {opacity: 255}, {easing: "cubicIn"})
			.call(() => {
				callback && callback();
			})
			.start();
	},

	disappearAnim(node, time=1, callback=null) {
		node.active = true;
		node.opacity = 255
		cc.tween(node)
			.to(time, {opacity: 0}, {easing: "cubicOut"})
			.call(() => {
				callback && callback();
			})
			.start();
	},

	checkShowFingerQues() {

		console.log(' in checkShowFingerQues')
		if (this.curFingerQues && this.isBeginAudioEnd) {
			if (this.curFingerQues.audio_url) {

				this.isStopFingerCheck = true;
				playAudioByUrl(this.curFingerQues.audio_url, () => {
					this.isStopFingerCheck = false;
				});
			}
		}
	},

	initTestPointArr() {
		
		const linkeItemArr = this.data.hotZoneItemArr.filter(hzItem => {
			return hzItem.gIdx == '0';
		})

		const bgRect = this.data.bgItem2.rect;

		const setDebugCenterPos = (hzItem) => {

			const debugItemIndex = (Number(hzItem.pointItem) - 1) 
			const debugItem = this.data.hotZoneItemArr2[debugItemIndex];
			const {rect} = debugItem

			const left = Math.round( (rect.x ) / bgRect.width  * 1000 ) / 1000;
			const right =  Math.round( (rect.x + rect.width) / bgRect.width * 1000 ) / 1000;
			const top =  Math.round( (rect.y ) / bgRect.height * 1000 ) / 1000;
			const bottom =  Math.round( (rect.y + rect.height) / bgRect.height * 1000 ) / 1000;
	
			
			const x = left + (right - left) / 2;
			const y = bottom - (bottom - top) / 2;

			hzItem.debugCenterPos = [x, y];
		}

		console.log('linkeItemArr: ', linkeItemArr);

		linkeItemArr.forEach(hzItem => {
			return setDebugCenterPos(hzItem);
		})

		const startPosObj = {};
		const endPosObj = {};

		for (let i=0; i<linkeItemArr.length; i++) {
			const index = this.data.hotZoneItemArr.indexOf(linkeItemArr[i]);
			const key = (index + 1).toString();
			if (!startPosObj[key] && !endPosObj[key]) {
				startPosObj[key] = linkeItemArr[i];


				const endKey = linkeItemArr[i].linkItem.toString();
				const endIndex = Number(endKey) - 1;
				const endItem = this.data.hotZoneItemArr[endIndex];
				endPosObj[endKey] = endItem;
			}
		}

		console.log('startPosObj: ', startPosObj);
		console.log('endPosObj: ', endPosObj);

		
		console.log('this.end_points: ', this.end_points);

	
	},

	checkStart() {

		console.log(' in checkStart')

		// if (this.debugBgImg && this.isBeginAudioEnd) {

		playAudio(this.beginTipClip, () => {
			

			this.playCurQuesAudio();
		

			delayCall(0.2 ,( ) =>{

				this.startTesting();

			})
		})

		// }
		

	},

	getSendCirclePoints(tempCirclePointArr) {

		console.log('tempCirclePointArr: ' , tempCirclePointArr);


		
		const sendCirclePointArr = [];

		for (let i=0; i<tempCirclePointArr.length; i++) {
			const {left, top, right, bottom} = tempCirclePointArr[i];

			const newLeft = left + (right - left) / 2;
			const newTop = top + (bottom - top) / 2;
			const data = {
				left: newLeft,
				right: newLeft,
				top: newTop,
				bottom: newTop
			}

			sendCirclePointArr.push(data);
			// const tempLink1 = tempCirclePointArr[i];
			// const key2 = tempLink1.linkItem;
			// const tempLink2 = tempCirclePointArr[Number(key2)-1];

			// if (!tempLink1.isGetLinked && !tempLink2.isGetLinked) {
			// 	tempLink1.isGetLinked = true;
			// 	tempLink2.isGetLinked = true;

			// 	const pKey1 = tempLink1.pointItem;
			// 	const pKey2 = tempLink2.pointItem;

			// 	const pointItem1 = this.data.hotZoneItemArr2[Number(pKey1) - 1];
			// 	const pointItem2 = this.data.hotZoneItemArr2[Number(pKey2) - 1];

			// 	const region1 = this.getRegionByRect(pointItem1.rect, bgRect);
			// 	const region2 = this.getRegionByRect(pointItem2.rect, bgRect);

			// 	let x1 = region1.left + (region1.right - region1.left) / 2;
			// 	let y1 = region1.top + (region1.bottom - region1.top) / 2;

			// 	let x2 = region2.left + (region2.right - region2.left) / 2;
			// 	let y2 = region2.top + (region2.bottom - region2.top) / 2;

			// 	x1 = Math.floor(x1 * 1000) / 1000;
			// 	y1 = Math.floor(y1 * 1000) / 1000;
			// 	x2 = Math.floor(x2 * 1000) / 1000;
			// 	y2 = Math.floor(y2 * 1000) / 1000;

			// 	sendCirclePointArr.push( {left:x1, top: y1, right:x2, bottom: y2} )
			// }
		}

		console.log("sendCirclePointArr: ", sendCirclePointArr);
		return sendCirclePointArr;
	},


	getSendLinePoints() {

		const hotZoneItemArr = JSON.parse( JSON.stringify(this.data.hotZoneItemArr) );

		const tempLinkArr = this.getGroupArrByGIdx(hotZoneItemArr, '0');
		console.log('tempLinkArr: ' , tempLinkArr);

		const bgRect = this.data.bgItem2.rect;
		
		const sendLinkPointArr = [];

		for (let i=0; i<tempLinkArr.length; i++) {
			const tempLink1 = tempLinkArr[i];
			const key2 = tempLink1.linkItem;
			const tempLink2 = hotZoneItemArr[Number(key2)-1];

			if (!tempLink1.isGetLinked && !tempLink2.isGetLinked) {
				tempLink1.isGetLinked = true;
				tempLink2.isGetLinked = true;

				const pKey1 = tempLink1.pointItem;
				const pKey2 = tempLink2.pointItem;

				const pointItem1 = this.data.hotZoneItemArr2[Number(pKey1) - 1];
				const pointItem2 = this.data.hotZoneItemArr2[Number(pKey2) - 1];

				const region1 = this.getRegionByRect(pointItem1.rect, bgRect);
				const region2 = this.getRegionByRect(pointItem2.rect, bgRect);

				let x1 = region1.left + (region1.right - region1.left) / 2;
				let y1 = region1.top + (region1.bottom - region1.top) / 2;

				let x2 = region2.left + (region2.right - region2.left) / 2;
				let y2 = region2.top + (region2.bottom - region2.top) / 2;

				x1 = Math.floor(x1 * 1000) / 1000;
				y1 = Math.floor(y1 * 1000) / 1000;
				x2 = Math.floor(x2 * 1000) / 1000;
				y2 = Math.floor(y2 * 1000) / 1000;

				sendLinkPointArr.push( {left:x1, top: y1, right:x2, bottom: y2} )
			}
		}

		console.log("sendLinkPointArr: ", sendLinkPointArr);
		return sendLinkPointArr;

		// for (let i=0; i<regions.length; i++) {
		// 	const oneRegion = regions[i];
		// 	console.log('oneRegion: ', oneRegion);
		// 	const x = oneRegion.left + (oneRegion.right - oneRegion.left) / 2;
		// 	const y = oneRegion.top + (oneRegion.bottom - oneRegion.top) / 2;
		// }
	},


	//调起检测
	startTesting() {



		// setInterval(() => {
		// 	this.getPhotoData((data) => {
		// 		this.photoEnd(data);
		// 	});           

		// }, 1000);

		this.isTesting = true;

		const cw = window.courseware;
		if (!cw || !cw.openOsmoHandwritingMlkit) {

			console.log('cw.openOsmoHandwritingMlkit not exist');
			return;
		}
		cw.openOsmoHandwritingMlkit(0.3);

	},

	endTesting() {

		this.isTesting = false;

		const cw = window.courseware;
		if (!cw || !cw.closeOsmoHandwritingMlkit) {

			return;
		}
		cw.closeOsmoHandwritingMlkit();
		// this.isTesting = false;
	},
	

	changeRegionTo4Pos(regions) {

		for (let i=0; i<regions.length; i++) {
			const {left, top, right, bottom} = regions[i];
			regions[i] = [

					left, top,
					right, top,
					right, bottom,
					left, bottom

			]
		}
		
	},

	getRegionsByGidx(gIdx) {

		const arr = this.getGroupArrByGIdx(this.data.hotZoneItemArr2, gIdx);
		const bgRect = this.data.bgItem2.rect;
		
		console.log("arr:", arr);
		const newLocationArr = [];
		for (let i=0; i<arr.length; i++) {

			const hzItem = arr[i];
			const regionRect = hzItem.rect;

			const region = this.getRegionByRect(regionRect, bgRect);

			newLocationArr.push(region)
		}

		return newLocationArr;

	},

	getRegionByRect(regionRect, bgRect) {

		const left = Math.round( (regionRect.x ) / bgRect.width  * 1000 ) / 1000;
		const right =  Math.round( (regionRect.x + regionRect.width) / bgRect.width * 1000 ) / 1000;
		const top =  Math.round( (regionRect.y ) / bgRect.height * 1000 ) / 1000;
		const bottom =  Math.round( (regionRect.y + regionRect.height) / bgRect.height * 1000 ) / 1000;

		return {left, top, right, bottom};
	},



	changeWriteData(result) {
		const curTextArr = result.text;
		const bboxTextArr = [];
		for (let i=0; i<curTextArr.length; i++) {

			const score = curTextArr[i].score;

			const {left, right, top, bottom} = curTextArr[i];
			const text = curTextArr[i].content;

			console.log('text..', JSON.stringify( curTextArr[i] ));
			console.log('text..', text);
			const disW = (right - left) / text.length;
			const disH = (bottom - top);
			for (let j=0; j<text.length; j++) {

				const x1 = left + j * disW;
				const y1 = top;

				const x2 = x1 + disW;
				const y2 = y1;

				const x3 = x2;
				const y3 = y2 + disH;

				const x4 = x1;
				const y4 = y3;

				// const bbox = [{x1, y1}, {x2, y2}, {x3, y3}, {x4, y4}]
				const bbox = {left: x1, right: x2, top: y1, bottom: y3}


				// this.changeBboxPos(bbox);

				const content = text[j];
				bboxTextArr.push({bbox, content, score});
			}

		}

		result.text = bboxTextArr;

	},


	locate(x1, y1, x2, y2, x3, y3) {
			var a, b;
			a = (y2 - y1) / (x2 - x1);
			b = y1 - a * x1;

			var xMiddle = (x1 + x2) / 2;
			var yMiddle = (y1 + y2) / 2;
			var c, lastX, lastY;
			if (a != 0) {
					c = yMiddle - (-1 / a) * xMiddle;
					lastX = (Math.pow(x1, 2) + Math.pow(y1, 2) - Math.pow(x3, 2) - Math.pow(y3, 2) - 2 * c * y1 + 2 * c * y3) / (2 * ((x1 - x3) - (1 / a) * (y1 - y3)));
					lastY = (-1 / a) * lastX + c;
			} else {
					lastX = c = xMiddle;
					lastY = (Math.pow(x1, 2) + Math.pow(y1, 2) - Math.pow(x3, 2) - Math.pow(y3, 2) + 2 * lastX * (x3 - x1)) / (2 * (y1 - y3));
			}
			console.log("定位点X坐标: " + lastX);
			console.log("定位点Y坐标: " + lastY);

			return {x: lastX, y: lastY};
	},

	

	setOneAnswerDataCircle(colorRect, answerData) {
		const rect = colorRect.ccRect;
		const dotV2 = new cc.Vec2(rect.x + rect.width/2, rect.y + rect.height / 2);


		// const targetLabelText = colorRect.labelText;

		// const newRectCheckArr = this.newRectCheckArr;
		const checkArr = this.circleRectCheckArr;

		for (let i=0; i<checkArr.length; i++) {

			const checkRect = checkArr[i].ccRect;
			const key = checkArr[i].data.index + 1;

			// if (labelText.toLowerCase().indexOf(targetLabelText.toLowerCase()) != -1 && rect.intersects(dotRect)) {
			if (checkRect.contains(dotV2)) {

				answerData[key] = {isFinish: true};

			}

		}

	},


	setOneAnswerDataLink(firstPos, lastPos, answerData) {


		const w = this.debugLayer.width;
    const h = this.debugLayer.height;
    const checkP1 = cc.v2(firstPos.x * w, -firstPos.y * h);
    const checkP2 = cc.v2(lastPos.x * w, -lastPos.y * h);



		let firstPosRectId = -1;
		let lastPosRectId = -1;

		const worldPos1 = this.debugLayer.convertToWorldSpaceAR(cc.v2(checkP1.x, checkP1.y));
		const worldPos2 = this.debugLayer.convertToWorldSpaceAR(cc.v2(checkP2.x, checkP2.y));


		// console.log('worldPos1: ', JSON.stringify(worldPos1));
		// console.log('worldPos2: ', JSON.stringify(worldPos2));

		for (let i=0; i<this.linkRectGroup.length; i++) {
			const rect = this.linkRectGroup[i].ccRect;

			// console.log('rect: ', JSON.stringify(rect));


      if (rect.contains(worldPos1)) {
        firstPosRectId = i;
        // break;
			} 
      if (rect.contains(worldPos2)) {
        lastPosRectId = i;
        // break;
			} 
		}

		console.log('firstPosRectId: ', firstPosRectId);
		console.log('lastPosRectId: ', lastPosRectId);

		if (firstPosRectId != -1 && lastPosRectId != -1 && firstPosRectId != lastPosRectId) {

      answerData[firstPosRectId.toString()] = [firstPosRectId, lastPosRectId];
      this.addDebugLayerDot(checkP1.x, checkP1.y, 10, cc.Color.GREEN);
      this.addDebugLayerDot(checkP2.x, checkP2.y, 10, cc.Color.GREEN);
    }

	},

	addDebugLayerDot(x, y, r=10, color = null) {
    const dotNode = new cc.Node();

    const ctx = dotNode.addComponent(cc.Graphics);
    ctx.fillColor = color || cc.Color.BLUE;
    ctx.circle(x, y, r);
    ctx.fill();

    this.debugDrawLayer.addChild(dotNode);

    const w = this.debugLayer.width;
    const h = this.debugLayer.height;
    const rateX = x / w;
    const rateY = y / h;
    
    console.log('ratePos: {x: ' + rateX + ', y: ' + rateY + '}')
  },

	photoEndLineRect(data) {
		const textArr = data?.result?.text;
		if (!textArr) {
			return;
		}



		const answerData = {};

		for (let i=0; i<textArr.length; i++) {
			const oneTextData = textArr[i];
			const points = oneTextData.points;

			const point1_x = points[0];
			const point1_y = points[1];
			const point2_x = points[2];
			const point2_y = points[3];

			// const rect1 = {
			// 	x:point1_x,
			// 	y: -point1_y,
			// 	width: 0.01,
			// 	height: 0.01
			// }

			// const colorRect1 = this.getColorDot(rect1.x, rect1.y, rect1.width, rect1.height, "purple");
			// this.debugDrawLayer.addChild(colorRect1, 1);
		

			// const rect2 = {
			// 	x:point2_x,
			// 	y: -point2_y,
			// 	width: 0.01,
			// 	height: 0.01
			// }

			// const colorRect2 = this.getColorDot(rect2.x, rect2.y, rect1.width, rect1.height, "purple");
			// this.debugDrawLayer.addChild(colorRect2, 1);

			this.drawUserLine([{x:point1_x, y: point1_y}, {x: point2_x, y: point2_y}]);

			this.setOneAnswerDataLink({x:point1_x, y: point1_y}, {x: point2_x, y: point2_y}, answerData);
		}


		this.showLinkAnswer(answerData);
	},

	drawUserLine(path) {
		this.drawOnePath(path);
	},

	drawOnePath(path) {
    const lineNode = new cc.Node();
    this.debugDrawLayer.addChild(lineNode);

    const w = this.debugLayer.width;
    const h = this.debugLayer.height;



    const subY = 0; //-canvas.height / 2;
    const ctx = lineNode.addComponent(cc.Graphics);
    ctx.lineWidth = 10;
    ctx.strokeColor = cc.Color.RED;
    ctx.fillColor = cc.Color.BLACK;
    

    ctx.moveTo(path[0].x * w, -path[0].y * h + subY);

    for (let i = 1; i < path.length; i++) {
      const x = path[i].x * w;
      const y = -path[i].y * h + subY;

      ctx.lineTo(x, y);
    }
    ctx.stroke();
  },

	showLinkAnswer(answerData) {

    for (let key in answerData) {

      const tempArr = answerData[key];

      const firstItemIndex = tempArr[0];
      const lastItemIndex = tempArr[1];

			const debugFirstItem = this.linkRectGroup[firstItemIndex];
			const debugLastItem = this.linkRectGroup[lastItemIndex];

			console.log('linkdebugId: ', debugFirstItem.linkData.linkDebugItemId);
			console.log('debugLastItem.linkData.debugItemId: ', debugLastItem.linkData.debugItemId)
			console.log('debugFirstItem.isRightPoint: ', debugFirstItem.isRightPoint)

			const hzItemIdFirst = debugFirstItem.linkData.hzItemId
			const hzItemIdLast = debugLastItem.linkData.hzItemId
			const startItem = this.getItemById(hzItemIdFirst);
			const endItem = this.getItemById(hzItemIdLast);
			if (startItem.isShowEnd || endItem.isShowEnd) {
				return;
			}

			if ((startItem.isRightPoint && endItem.isRightPoint) && debugFirstItem.linkData.linkDebugItemId == debugLastItem.linkData.debugItemId) {
				
				const {hzItemId, linkHzItemId} = debugFirstItem.linkData
				this.showSuccess(hzItemId, linkHzItemId);

			} else {			

			}

    }


		// for (let key in answerData) {

    //   const tempArr = answerData[key];

    //   const firstItemIndex = tempArr[0];
    //   const lastItemIndex = tempArr[1];

		// 	const debugFirstItem = this.linkRectGroup[firstItemIndex];
		// 	const debugLastItem = this.linkRectGroup[lastItemIndex];

		// 	console.log('linkdebugId: ', debugFirstItem.linkData.linkDebugItemId);
		// 	console.log('debugLastItem.linkData.debugItemId: ', debugLastItem.linkData.debugItemId)
		// 	console.log('debugFirstItem.isRightPoint: ', debugFirstItem.isRightPoint)

		// 	const hzItemIdFirst = debugFirstItem.linkData.hzItemId
		// 	const hzItemIdLast = debugLastItem.linkData.hzItemId
		// 	const startItem = this.getItemById(hzItemIdFirst);
		// 	const endItem = this.getItemById(hzItemIdLast);
		// 	if (startItem.isShowEnd || endItem.isShowEnd) {
		// 		return;
		// 	}

		// 	if (debugFirstItem.isRightPoint && debugFirstItem.linkData.linkDebugItemId == debugLastItem.linkData.debugItemId) {
				
		// 		// const {hzItemId, linkHzItemId} = debugFirstItem.linkData
		// 		// this.showSuccess(hzItemId, linkHzItemId);

		// 	} else {			

				
		// 		this.showFail(hzItemIdFirst, hzItemIdLast);
		// 		this.playCatAudio(this.data.error_link_audio_url);

		// 	}

    // }


  },

	showSuccess(startItemId, endItemId) {

		console.log( ' in showSuccess');

		const startItem = this.getItemById(startItemId);
		const endItem = this.getItemById(endItemId);

		if (startItem.isShowEnd || endItem.isShowEnd) {
			return;
		}
		startItem.isShowEnd = true;
		endItem.isShowEnd = true;

		const isLinked = this.checkIsLinked(startItem, endItem);
		if (isLinked) {
			return;
		}

		this.addLinkItem(startItem, endItem);
		this.addLinkItem(endItem, startItem);




		const pos1 = startItem.getPosition();
		pos1.x += startItem.width / 2;
		pos1.y += startItem.height / 2;
		const pos2 = endItem.getPosition();
		pos2.x += endItem.width / 2;
		pos2.y += endItem.height / 2;

		const greenColor = new cc.Color();
		greenColor.fromHEX("#519F00"); 
		const line = this.getLine(pos1, pos2, greenColor);
		this.addLinkLine(startItem, endItem, line);
		line.isRight = true;

		const maskNode = new cc.Node();
		maskNode.width = 0;
		maskNode.height = 0;
		maskNode.x = pos1.x;
		maskNode.y = pos1.y;
		this.hotZoneBg.addChild(maskNode);


		const mask = maskNode.addComponent(cc.Mask);
		mask.type = cc.Mask.Type.ELLIPSE;
		mask.segments = 32;

		maskNode.addChild(line);
		// line.mask = mask;

		this.isCurLinked = true;

		cc.tween(maskNode)
			.to(1.5, {width: this.canvas.width * 2, height: this.canvas.height * 2}, {easing: 'sineOut'})
			.call(() => {
				maskNode.removeComponent(cc.Mask);
			})
			.start();
		
		playAudio(this.rightClip, () => {
			
		})
		
		if (!this.isGameEnd) {
			const arr = this.rectNodeArr.filter((r) => {
				return r.isRightPoint == true;
			})
			this.checkGameEnd(arr);
		}
	},

	addLinkLine(item1, item2, line) {
		if ( !item1.lineArr ) {
			item1.lineArr = [];
		}

		if (!item2.lineArr) {
			item2.lineArr = [];
		}
		
		item1.lineArr.push(line);
		item2.lineArr.push(line);
		line.itemArr = [item1, item2];
		this.totalLineArr.push(line);
	},

	checkIsLinked(startItem, endItem) {
		const linkItemArr1 = startItem.linkItemArr || [];
		const linkItemArr2 = endItem.linkItemArr || [];

		return (linkItemArr1.indexOf(endItem) != -1 && linkItemArr2.indexOf(startItem) != -1);
	},

	addLinkItem(item, linkItem) {
		if (!item.linkItemArr) {
			item.linkItemArr = [];
		}

		if (item.linkItemArr.indexOf(linkItem) == -1) {
			item.linkItemArr.push(linkItem);
		}
	},

	getLine(item1, item2, color=cc.Color.BLACK) {
		const lineNode = new cc.Node();


		const ctx = lineNode.addComponent(cc.Graphics);
		ctx.lineWidth = 5;
    ctx.strokeColor = color;
    ctx.fillColor = color;

    ctx.moveTo(0, 0);
		ctx.lineTo(item2.x - item1.x, item2.y - item1.y);
		ctx.stroke();

		const dot1 = this.getDot(0, 0, ctx.lineWidth/2, ctx.strokeColor);
		dot1.parent = lineNode;

		const dot2 = this.getDot(item2.x - item1.x, item2.y - item1.y, ctx.lineWidth/2, ctx.strokeColor);
		dot2.parent = lineNode;

		return lineNode;
	},

	getDot(x, y, r, color) {

		const dotNode = new cc.Node();

    const ctx = dotNode.addComponent(cc.Graphics);
    ctx.fillColor = color || cc.Color.BLUE;
    ctx.circle(x, y, r);
    ctx.fill();

		return dotNode;
	},


	getItemById(id) {

		console.log('getItemById id:', id);
		console.log('this.rectNodeArr: ', this.rectNodeArr);

		const targetItem = this.rectNodeArr.find( node => {

			const data = node.data;

			console.log('data~~: ', JSON.stringify(data));


			if (data && (data.index + 1 == id)) {
				return true;
			}
		})
		return targetItem;
	},

	photoEndSignRect(data) {

		const textArr = data?.result?.text;
		if (!textArr) {
			return;
		}

		const symbol = textArr[0]?.symbol
		if (!symbol) {
			return;
		}

		// return 
		const answerData = {};


		for (let i=0; i<this.signRectCheckArr.length; i++) {
			
			const signDebugItem = this.signRectCheckArr[i];
			const dropDownItem = signDebugItem.data.dropDownItem;

			const curSignKey = symbol[i].toString();
			
			if (dropDownItem.key == curSignKey) {


				const label = this.getLabel(dropDownItem.label, signDebugItem.ccRect.width);
				label.x = signDebugItem.x;
				label.y = signDebugItem.y;
				label.color = cc.Color.BLACK;
	
				this.debugDrawLayer.addChild(label, 2);


				const key = signDebugItem.data.index + 1;
				answerData[key] = {isFinish: true};

			}
		}

		this.showSignAnswer(answerData);

		return ;

		for (let i=0; i<textArr.length; i++) {
			const oneTextData = textArr[i];

			const signId = '2'

			// const points = oneTextData.points;

			// const tempDisNum = Math.floor(points.length / 2);
			// const point1_x = points[0];
			// const point1_y = points[1];
			// const point2_x = points[tempDisNum];
			// const point2_y = points[tempDisNum + 1];

			// let centerPX = Number(point1_x) + (point2_x - point1_x) / 2;
			// let centerPY = Number(point1_y) + (point2_y - point1_y) / 2;

			// console.log('centerPX: ' ,centerPX);
			// console.log('centerPY: ' ,centerPY);

			// const colorRect = this.getColorDot(centerPX, -centerPY, 0.02, 0.02, "purple");
			// this.debugDrawLayer.addChild(colorRect, 1);


			// this.setOneAnswerDataCircle(colorRect, answerData);

		}

		console.log('answerData: ' , answerData);


		// this.showCircleAnswer(answerData);

	},

	showSignAnswer(answerData) {

		console.log('answerData: ', answerData);
		if (Object.keys(answerData).length == 0) {
			return;
		}

		console.log("signAnimaNodeArr: ", this.signAnimaNodeArr);

		for (let i = 0; i < this.signAnimaNodeArr.length; i++) {

			const animaNode = this.signAnimaNodeArr[i];

			const key = animaNode.data.signItem // i.toString();


			console.log('~animaNode.data: ', animaNode.data)
			console.log('~key: ', key)

			if (!animaNode.hitCount) {
				animaNode.hitCount = 0;
			}

			if (answerData[key] && answerData[key].isFinish) {
				console.log('~showSign')
				this.showSign(animaNode);

			} else {

				animaNode.hitCount = 0;
			}
		}

	},

	showSign(node, isRight = true) {

		console.log('in showCircle 1');


		node.hitCount++;
		if (node.hitCount < 1) {
			return;
		}


		console.log('in showCircle 2');


		if (node.isShowEnd) {
			return;
		}

		console.log('in showCircle 3');

		node.isShowEnd = true;
		node.isRight = isRight;


		// node.playRightAnim();
		this.playRightAnim(node);

		if (!this.isGameEnd) {
			this.checkGameEnd(this.signAnimaNodeArr);
		}

		return;

	},

	photoEndCircleRect(data) {
		const textArr = data?.result?.text;
		if (!textArr) {
			return;
		}

		const answerData = {};

		for (let i=0; i<textArr.length; i++) {
			const oneTextData = textArr[i];
			const points = oneTextData.points;

			const tempDisNum = Math.floor(points.length / 2);
			const point1_x = points[0];
			const point1_y = points[1];
			const point2_x = points[tempDisNum];
			const point2_y = points[tempDisNum + 1];
			// const point3_x = points[tempDisNum*2];
			// const point3_y = points[tempDisNum*2 + 1];

			// let centerP = this.locate(point1_x, point1_y, point2_x, point2_y, point3_x, point3_y);
			let centerPX = Number(point1_x) + (point2_x - point1_x) / 2;
			let centerPY = Number(point1_y) + (point2_y - point1_y) / 2;

			console.log('centerPX: ' ,centerPX);
			console.log('centerPY: ' ,centerPY);


			const colorRect = this.getColorDot(centerPX, -centerPY, 0.02, 0.02, "purple");
			this.debugDrawLayer.addChild(colorRect, 1);


			this.setOneAnswerDataCircle(colorRect, answerData);


			// console.log('points: ', points);
		
			// for (let j=0; j<points.length; j+=2) {
			// 	const x = points[j]//centerP.x
			// 	const y = -points[j+1]//-centerP.y
			// 	const w = 0.01;
			// 	const h = 0.01;
	
			// 	const rect = {
			// 		x, y,
			// 		width: w,
			// 		height: h
			// 	}
	

	
			// 	const colorRect = this.getColorDot(rect.x, rect.y, w, h, "red");
			// 	this.debugDrawLayer.addChild(colorRect, 1);


			// 	// this.setCirclePosInRectArr(colorRect);
				
	
			// }
		


		}

		console.log('answerData: ' , answerData);


		this.showCircleAnswer(answerData);

		// this.showUserRightNew(answerData);
	},

	showCircleAnswer(answerData) {

		if (Object.keys(answerData).length == 0) {
			return;
		}


		for (let i = 0; i < this.circleAnimaNodeArr.length; i++) {

			const animaNode = this.circleAnimaNodeArr[i];

			const key = animaNode.data.circleItem // i.toString();

			console.log('~animaNode.data: ', animaNode.data)
			console.log('~key: ', key)

			console.log('~key: ', key)

			if (!animaNode.hitCount) {
				animaNode.hitCount = 0;
			}

			if (answerData[key] && answerData[key].isFinish) {
				console.log('~showLetter')
				this.showCircle(animaNode);
				// this.showLetter(animaNode);
			} else {

				animaNode.hitCount = 0;
			}
		}

	},

	showCircle(node, isRight = true) {

		console.log('in showCircle 1');


		node.hitCount++;
		if (node.hitCount < 1) {
			return;
		}


		console.log('in showCircle 2');


		if (node.isShowEnd) {
			return;
		}

		console.log('in showCircle 3');

		node.isShowEnd = true;
		node.isRight = isRight;


		// node.playRightAnim();
		this.playRightAnim(node);

		if (!this.isGameEnd) {
			this.checkGameEnd(this.circleAnimaNodeArr);
		}

		return;

	},
	

	photoEndFingerRect(data) {
		
		console.log('in photoEndFingerRect, data:', data);

		const answerData = {};


		const {x, y} = data;

		const colorDot = this.getColorDot(x, -y, 0.05, 0.05);
		this.debugDrawLayer.addChild(colorDot, 1);


		this.setOneAnswerDataFinger(colorDot, answerData);

		console.log('answerData:' , answerData);
		this.showFingerAnswer(answerData);


	},

	nextFingerQues() {

		if (this.fingerQuesArr.length > 0) {
			this.curFingerQues = this.fingerQuesArr.pop();

			this.checkShowFingerQues();
		}

	},

	setOneAnswerDataFinger(colorDot, answerData) {
		const rect = colorDot.dotRect;
		const dotV2 = new cc.Vec2(rect.x + rect.width/2, rect.y + rect.height / 2);

		const checkArr = this.fingerRectCheckArr;

		for (let i=0; i<checkArr.length; i++) {

			const checkRect = checkArr[i].ccRect;
			const key = checkArr[i].data.index + 1;

			if (checkRect.contains(dotV2)) {
				answerData[key] = {isFinish: true};
			}

		}

	},

	showFingerAnswer(answerData) {

		console.log(' in showFingerAnswer 1')
		if (Object.keys(answerData).length == 0) {
			return;
		}

		for (let i = 0; i < this.fingerAnimaNodeArr.length; i++) {

			const animaNode = this.fingerAnimaNodeArr[i];

			const key = animaNode.data.fingerItem // i.toString();

			console.log('~animaNode.data: ', animaNode.data)
			console.log('~key: ', key)

			if (animaNode.data.id != this.curFingerQues.id) {
				continue;
			}


			if (!animaNode.hitCount) {
				animaNode.hitCount = 0;
			}

			if (answerData[key] && answerData[key].isFinish) {
				console.log('~showFinger')
				this.showFinger(animaNode);
				

			


				// this.showLetter(animaNode);
			} else {

				animaNode.hitCount = 0;
			}
		}


	},

	showFinger(node, isRight = true) {

		console.log('in showFinger 1');

		node.hitCount++;
		if (node.hitCount < 1) {
			return;
		}


		console.log('in showFinger 2');

		if (node.isShowEnd) {
			return;
		}

		console.log('in showFinger 3');

		node.isShowEnd = true;
		node.isRight = isRight;

		delayCall(1.5, () => {
			this.nextFingerQues();
		})

		// node.playRightAnim();
		this.playRightAnim(node);

		if (!this.isGameEnd) {
			this.checkGameEnd(this.fingerAnimaNodeArr);
		}

		return;

	},


	photoEndNewRect(data) {

		const textArr = data?.result?.text;
		if (!textArr) {
			return;
		}

		const answerData = {};

		for (let i=0; i<textArr.length; i++) {
			const oneTextData = textArr[i];
			const x = oneTextData.left//oneTextData.left + (oneTextData.right - oneTextData.left) / 2;
			const y = -oneTextData.bottom//-oneTextData.top - (oneTextData.bottom - oneTextData.top) / 2;
			const w = oneTextData.right - oneTextData.left;
			const h = oneTextData.bottom - oneTextData.top;

			const rect = {
				x, y,
				width: w,
				height: h
			}

			console.log('oneTextData: ', oneTextData);

			const content = oneTextData.content;
			const colorRect = this.getColorRect(rect, "red");
			colorRect.labelText = content;
			this.debugDrawLayer.addChild(colorRect, 1);

			const label = this.getLabel(content, colorRect.scaleX *  colorRect.width);
			label.x = colorRect.x + colorRect.width / 2 * colorRect.scaleX;
			label.y = colorRect.y + colorRect.height / 2 * colorRect.scaleY;
			label.color = cc.Color.BLACK;

			this.debugDrawLayer.addChild(label, 2);

			this.setOneAnswerDataNew(colorRect, answerData);

		}

		console.log('answerData:' , answerData);
		this.showUserRightNew(answerData);
	},

	
	

	showUserRightNew(answerData) {

		if (Object.keys(answerData).length == 0) {
			return;
		}






		for (let i = 0; i < this.wordBgArr.length; i++) {

			const animaNode = this.wordBgArr[i].wordNode;

			const key = (i+1).toString();

			console.log('~animaNode.data: ', animaNode.data)
			console.log('~key: ', key)

			if (!animaNode.hitCount) {
				animaNode.hitCount = 0;
			}

			if (answerData[key] && answerData[key].isFinish) {
				console.log('~showLetter')
				
				this.showLetterLabel(animaNode);
				this.showAnswerIcon(this.wordBgArr[i], true)

			} else {

				animaNode.hitCount = 0;
			}
		}
	},

	photoEnd(data) {

		if (this.isGameEnd) {
			return;
		}

		if (!this.isCanCheck) {
			return;
		}
		
		console.log(' this.photo end ', data);

		loopLog(data);

		// console.log('photoEnd data: ', JSON.stringify(data));

		this.debugLayer.removeAllChildren();

		const answerData = this.getAnswerData(data);

		this.showUserRight(answerData);

		return;

		// this.debugDrawLayer.removeAllChildren();

		// if (this.curCheckGroup == this.CHECK_TYPE_FINGER) {

		// 	if (this.isStopFingerCheck) {
		// 		return;
		// 	}

		// 	this.photoEndFingerRect(data);
		// 	return;
		// }


		// // if (this.newRectArr && this.newRectArr.length > 0) {
		// if (this.curCheckGroup == this.CHECK_TYPE_WRITE) {
		// 	this.photoEndNewRect(data);
		// 	return;
		// }


		// // if (this.circleRectArr && this.circleRectArr.length > 0) {
		// if (this.curCheckGroup == this.CHECK_TYPE_CIRCLE) {
		// 	this.photoEndCircleRect(data);
		// 	return;
		// }

		// // if (this.lineRectArr && this.lineRectArr.length > 0) {
		// if (this.curCheckGroup == this.CHECK_TYPE_LINE) {
		// 	this.photoEndLineRect(data);
		// 	return;
		// }

		// // if (this.signRectArr && this.signRectArr.length > 0) {
		// if (this.curCheckGroup == this.CHECK_TYPE_SIGN) {
		// 	this.photoEndSignRect(data);
		// 	return;
		// }

		


		// // this.changeBboxPos(data);

		// const isRightArea = this.checkIsRightArea(data);
		// if (!isRightArea) {
		// 	console.log('没有检测到区域')
		// 	return;
		// }



		// if (this.isCanDraw) {
		// 	return;
		// }
		// this.isCanDraw = true;


		// delayCall(0.01, () => {
		// 	this.isCanDraw = false;
		// })




		// const answerData = this.getAnswerData(data);

		// this.showUserRight(answerData, data);

		return;


		const answerWrongData = this.getAnswerWrongData(data);
		let isShowWrong = false;
		if (this.oldAnswerWrongData) {
		
			for (let key in answerWrongData) {
				const wrongData = answerWrongData[key];
				const oldWrongData = this.oldAnswerWrongData[key];
				if (oldWrongData && oldWrongData.sentence == wrongData.sentence) {
					wrongData.count += oldWrongData.count;

					if (wrongData.count >= 3) {
						isShowWrong = true;
					}
				}
			}
		}

		if (isShowWrong) {
			this.showUserWrong(answerWrongData);
		}

		this.oldAnswerWrongData = answerWrongData;


		console.log('answerWrongData: ', JSON.stringify( answerWrongData) );
	},







	checkIsRightArea(data) {

		const text = data?.result?.text
		if (!text) {
			return false;
		}

		const benchmark1Text = this.benchmark1Data.labelText
		const benchmark1TextArr = benchmark1Text.split(' ');
		console.log('benchmark1TextArr: ', benchmark1TextArr);
		// const letter = this.data.letter || 'Aa';

		const benchmark1LabelData = this.getPhotoLabelData(benchmark1TextArr, text, false);
		if (!benchmark1LabelData) {
			console.log('!benchmark1LabelData')
			return false;
		}
		this.benchmark1LabelData = benchmark1LabelData;
		console.log('benchmark1LabelData: ', benchmark1LabelData);

		

		if ( this.firstItemData ) {

			const firstText = this.firstItemData.labelText
			const firstTextArr = firstText.split(' ');

			const firstItemLabelData = this.getTopLeftLetter2(firstText, text, this.benchmark1LabelData);

			if (!firstItemLabelData) {
				return false;
			}
			this.firstItemLabelData = firstItemLabelData;

			console.log('firstItemLabelData: ', firstItemLabelData);
			return true

		} else if (this.benchmark2Data) {
		
			const benchmark2Text = this.benchmark2Data.labelText
			const benchmark2TextArr = benchmark2Text.split(' ');
			const benchmark2LabelData = this.getPhotoLabelData(benchmark2TextArr, text, false);
			if (!benchmark2LabelData) {
				return false;
			}
			this.benchmark2LabelData = benchmark2LabelData;
			return true;
		}



		return false;

	


		// const block = data?.block
		// if (!block) {
		// 	return false;
		// }

		// const topText = this.topItemData.labelText
		// const topTextArr = topText.split(' ');
		// console.log('topTextArr: ', topTextArr);
		// // const letter = this.data.letter || 'Aa';

		// const topLabelData = this.getPhotoLabelData(topTextArr, block);
		// if (!topLabelData) {
		// 	console.log('!topLabelData')
		// 	return false;
		// }
		// this.topLabelData = topLabelData;
		// console.log('topLabelData: ', topLabelData);

		

		// if (this.bottomItemData) {
			
		// 	const bottomText = this.bottomItemData.labelText
		// 	const bottomTextArr = bottomText.split(' ');
		// 	const bottomLabelData = this.getPhotoLabelData(bottomTextArr, block);
		// 	if (!bottomLabelData) {
		// 		return false;
		// 	}
		// 	this.bottomLabelData = bottomLabelData;
		// 	return true

		// } else if (this.firstItemData) {

		// 	const firstText = this.firstItemData.labelText
		// 	const firstTextArr = firstText.split(' ');
		// 	const topLeftLetter = this.getPhotoLabelData(firstTextArr, block);


		// 	// const topLeftLetter = this.getTopLeftLetter(this.firstItemData.labelText, block, topLabelData);
		// 	if (!topLeftLetter) {
		// 		return false;
		// 	}
		// 	this.topLeftLetter = topLeftLetter;

		// 	console.log('topLeftLetter: ', topLeftLetter);
		// 	return true;
		// }



		// return false;

	
	},

	changeBboxPos(data) {

		const text = data?.result?.text;
		if (!text) {
			return;
		}


		for (let i=0; i<text.length; i++) {

			let {left, top, right, bottom} = text[i];

			const q_left = this.ques_region[0];
			const q_top = this.ques_region[1];
			const q_right = this.ques_region[2];
			const q_bottom = this.ques_region[7];

			const rect = {x: q_left, y: q_top, width: q_right - q_left, height: q_bottom - q_top};

			text[i].left = q_left + left * rect.width;
			text[i].top = q_top + top * rect.height;
			text[i].right = q_left + right * rect.width;
			text[i].bottom = q_top + bottom * rect.height;

		}

		// console.log('bbox: ', bbox);
		// const x1 = bbox[0].x1;
		// const y1 = bbox[0].y1;
		// const x2 = bbox[1].x2;
		// const y2 = bbox[1].y2;
		// const x3 = bbox[2].x3;
		// const y3 = bbox[2].y3;
		// const x4 = bbox[3].x4;
		// const y4 = bbox[3].y4;

		// const left = this.ques_region[0];
		// const top = this.ques_region[1];
		// const right = this.ques_region[2];
		// const bottom = this.ques_region[7];

		// const rect = {x: left, y:top, width: right - left, height: bottom - top};

		// const y1_new = top + y1 * rect.height;
		// const y2_new = y1_new;
		// const y3_new = top + y3 * rect.height;
		// const y4_new = y3_new;

		// const x1_new = left + x1 * rect.width;
		// const x2_new = left + x2 * rect.width;
		// const x3_new = x2_new;
		// const x4_new = x1_new;

		// bbox[0].x1 = x1_new;
		// bbox[0].y1 = y1_new;
		// bbox[1].x2 = x2_new;
		// bbox[1].y2 = y2_new;
		// bbox[2].x3 = x3_new;
		// bbox[2].y3 = y3_new;
		// bbox[3].x4 = x4_new;
		// bbox[3].y4 = y4_new;

		// console.log('~~rect: ', rect);

	
	},



	getTopLeftLetter2(text, block, topLabelData) {

		const benchmark1Rect = this.benchmark1Data.rect;

		const rect = {
			x: topLabelData.left, 
			y: -topLabelData.bottom, 
			width: Math.abs( topLabelData.right - topLabelData.left ), 
			height: Math.abs( topLabelData.bottom - topLabelData.top ), 
		}                        
		const colorRect = this.getColorRect(rect, "green");
		this.debugDrawLayer.addChild(colorRect);
		


		const tempUnitW = benchmark1Rect.x + benchmark1Rect.width;
		const tempUnitH = benchmark1Rect.y + benchmark1Rect.height;
		const tempBaseX = benchmark1Rect.x + benchmark1Rect.width / 2;
		const tempBaseY = benchmark1Rect.y + benchmark1Rect.height / 2;


		const firstItemData = this.firstItemData;		
		const firstItemRect = this.firstItemData.rect;

	
		const firstItemX = firstItemRect.x + firstItemRect.width / 2;
		const firstItemY = firstItemRect.y + firstItemRect.height / 2;

		const unitX = (firstItemX - tempBaseX) / tempUnitW;
		const unitY = (firstItemY - tempBaseY) / tempUnitH;
		const unitW2 = firstItemRect.width / tempUnitW;
		const unitH2 = firstItemRect.height / tempUnitH;



		console.log('tempUnitW: ', tempUnitW);
		console.log('tempUnitH: ', tempUnitH);
		console.log('tempBaseX: ', tempBaseX);
		console.log('tempBaseY: ', tempBaseY);

		console.log('firstItemY: ', firstItemY);
		console.log('tempBaseY: ', tempBaseY);
		console.log('tempUnitH: ', tempUnitH);

		firstItemData.unitX = unitX;
		firstItemData.unitY = unitY;
		firstItemData.unitW = unitW2;
		firstItemData.unitH = unitH2;



		const topLocationLeft = topLabelData.left;
		const topLocationTop = topLabelData.top;
		const topLocationRight = topLabelData.right;
		const topLocationBottom = topLabelData.bottom;

		const baseX = topLocationLeft + (topLocationRight - topLocationLeft) / 2;
		const baseY =	topLocationTop + (topLocationBottom - topLocationTop) / 2;
		const unitW = topLocationRight;
		const unitH = topLocationTop + (topLocationBottom - topLocationTop);
		

		const checkLetter = firstItemData;

		console.log('baseY: ', baseY);
		console.log('checkLetter.unitY: ', checkLetter.unitY);
		console.log('unitH: ', unitH);


		let x = baseX + checkLetter.unitX * unitW;
		const y = baseY + checkLetter.unitY * unitH;
		const w = checkLetter.unitW * unitW;
		const h = checkLetter.unitH * unitH;
		const r = Math.min(w, h) / 2;


		console.log(' baseX:  ', baseX);
		console.log(' checkLetter.unitX:  ', checkLetter.unitX);
		console.log(' unitW:  ', unitW);
		console.log(' x:  ', x);
		console.log(' y:  ', y);
		console.log(' r:  ', r);
		console.log(' checkLetter:  ', checkLetter);

		const dot = this.getColorDot(x, -y, r, r, 'blue');
		this.debugDrawLayer.addChild(dot, 5);

		dot.labelText = checkLetter.labelText;


		const wordDataArr =  this.getPhotoWordArr(text, block, topLabelData);
		let topLeftLetterData;


		const {dotRect, labelText} = dot
		


		for (let i=0; i<wordDataArr.length; i++) {

			// const tempWordArr = wordDataArr[i].word;
			const tempWordArr = this.getTempWordArr(wordDataArr[i],['']);



			for (let k=0; k<tempWordArr.length; k++) {
					
				const {location , content} = tempWordArr[k];

				const rect = {
					x: location.left, 
					y: -location.bottom, 
					width: Math.abs( location.right - location.left ), 
					height: Math.abs( location.bottom - location.top ), 
				}                        
				const colorRect = this.getColorRect(rect, "purple");
				colorRect.labelText = content;
				this.debugDrawLayer.addChild(colorRect);

				// console.log('colorRect: ', colorRect);

				const label = this.getLabel(content);
				label.x = colorRect.x + colorRect.width / 2 * colorRect.scaleX;
				label.y = colorRect.y - colorRect.height / 2 //* colorRect.scaleY;
				label.color = cc.Color.GREEN;
				this.debugDrawLayer.addChild(label);




				///------

				const checkRect = colorRect.ccRect;
				const targetLabelText = colorRect.labelText;

				const {dotRect, labelText, key} = dot;

				if (labelText.toLowerCase().indexOf(targetLabelText.toLowerCase()) != -1 && checkRect.intersects(dotRect)) {
					return tempWordArr[k];
				}

				///------
				

			}





			// const lineRect = this.getLineRect( wordDataArr[i] );
			// const isInLineRect = lineRect.intersects(dotRect)
			// if (!isInLineRect) {
			// 	continue;
			// }

			// for (let k=0; k<tempWordArr.length; k++) {
			// 	const {location , content} = tempWordArr[k];

			// 	const tempRect = {
			// 		x: location.left, 
			// 		y: -location.bottom, 
			// 		width: Math.abs( location.right - location.left ), 
			// 		height: Math.abs( location.bottom - location.top ), 
			// 	}
			// 	const colorRect = this.getColorRect(tempRect);
			// 	colorRect.labelText = content;
			// 	// this.debugDrawLayer.addChild(colorRect);

			// 	const label = this.getLabel(content);
			// 	label.x = colorRect.x + colorRect.width / 2 * colorRect.scaleX;
			// 	label.y = colorRect.y - colorRect.height / 2 //* colorRect.scaleY;
			// 	label.color = cc.Color.GREEN;
			// 	// this.debugDrawLayer.addChild(label);
				


						
			// 	const rect = colorRect.ccRect;
			// 	const targetLabelText = colorRect.labelText;



			

			// 	// console.log('targetLabelText.toLowerCase() : ', targetLabelText.toLowerCase() );
			// 	// console.log('labelText.toLowerCase()  : ', labelText.toLowerCase()  );


			// 	const isInLineText = this.checkWordIsInLine(wordDataArr[i], labelText);

			// 	if (isInLineText) {
			// 	// if (targetLabelText.toLowerCase().indexOf(labelText.toLowerCase()) != -1  && rect.intersects(dotRect)) {
			// 		topLeftLetterData = wordDataArr[i];
			// 		// answerData[i.toString()] = colorRect;
			// 		// return;
			// 	}

			// }
			
		}

			
		return null;


	},


	getTopLeftLetter(text, block, topLabelData) {

		// const topItemRect = this.topItemData.rect;

		// const tempUnitW = topItemRect.width;
		// const tempUnitH = topItemRect.height;
		// const tempBaseX = topItemRect.x;
		// const tempBaseY = topItemRect.y + topItemRect.height / 2;


		// const firstItemData = this.firstItemData;
		// console.log('firstItemData: ', firstItemData);
		
		// const firstItemRect = this.firstItemData.rect;


	
		// const firstItemX = firstItemRect.x + firstItemRect.width / 2;
		// const firstItemY = firstItemRect.y + firstItemRect.height / 2;

		// const unitX = (firstItemX - tempBaseX) / tempUnitW;
		// const unitY = (firstItemY - tempBaseY) / tempUnitH;
		// const unitW2 = firstItemRect.width / tempUnitW;
		// const unitH2 = firstItemRect.height / tempUnitH;


		// console.log('firstItemY: ', firstItemY);
		// console.log('tempBaseY: ', tempBaseY);
		// console.log('tempUnitH: ', tempUnitH);

		// firstItemData.unitX = unitX;
		// firstItemData.unitY = unitY;
		// firstItemData.unitW = unitW2;
		// firstItemData.unitH = unitH2;



		// // const topLabelData = this.topLabelData;

		// const firstTopWordLocation = topLabelData.word[0].location;
		// const lastTopWordLocation = topLabelData.word[topLabelData.word.length - 1].location
		// const topLocationLeft = firstTopWordLocation.left;
		// const topLocationTop = firstTopWordLocation.top;
		// const topLocationRight = lastTopWordLocation.right;
		// const topLocationBottom = lastTopWordLocation.bottom;

		// const baseX = topLocationLeft;
		// const baseY =	topLocationTop + (topLocationBottom - topLocationTop) / 2;
		// const unitW = topLocationRight - topLocationLeft;
		// const unitH = topLocationBottom - topLocationTop;
		

		// const checkLetter = firstItemData;

		// console.log('baseY: ', baseY);
		// console.log('checkLetter.unitY: ', checkLetter.unitY);
		// console.log('unitH: ', unitH);


		// let x = baseX + checkLetter.unitX * unitW;
		// const y = baseY + checkLetter.unitY * unitH;
		// const w = checkLetter.unitW * unitW;
		// const h = checkLetter.unitH * unitH;
		// const r = Math.min(w, h) / 2;

		// 	// const centerX = baseX + this.centerUnitW * unitW;
		// 	// x += (centerX - x) * 0.005  * (y * 0.05);

		// console.log(' x:  ', x);
		// console.log(' y:  ', y);
		// console.log(' r:  ', r);

		// const dot = this.getColorDot(x, -y, r, r, 'purple');
		// this.debugDrawLayer.addChild(dot, 5);

		// dot.labelText = checkLetter.labelText;


		// const wordDataArr =  this.getPhotoWordArr(text, block, topLabelData);
		// let topLeftLetterData;


		// const {dotRect, labelText} = dot
		


		// for (let i=0; i<wordDataArr.length; i++) {

		// 	const tempWordArr = wordDataArr[i].word;

		// 	const lineRect = this.getLineRect( wordDataArr[i] );
		// 	const isInLineRect = lineRect.intersects(dotRect)
		// 	if (!isInLineRect) {
		// 		continue;
		// 	}

		// 	for (let k=0; k<tempWordArr.length; k++) {
		// 		const {location , content} = tempWordArr[k];

		// 		const tempRect = {
		// 			x: location.left, 
		// 			y: -location.bottom, 
		// 			width: Math.abs( location.right - location.left ), 
		// 			height: Math.abs( location.bottom - location.top ), 
		// 		}
		// 		const colorRect = this.getColorRect(tempRect);
		// 		colorRect.labelText = content;
		// 		// this.debugDrawLayer.addChild(colorRect);

		// 		const label = this.getLabel(content);
		// 		label.x = colorRect.x + colorRect.width / 2 * colorRect.scaleX;
		// 		label.y = colorRect.y - colorRect.height / 2 //* colorRect.scaleY;
		// 		label.color = cc.Color.GREEN;
		// 		// this.debugDrawLayer.addChild(label);
				


						
		// 		const rect = colorRect.ccRect;
		// 		const targetLabelText = colorRect.labelText;



			

		// 		// console.log('targetLabelText.toLowerCase() : ', targetLabelText.toLowerCase() );
		// 		// console.log('labelText.toLowerCase()  : ', labelText.toLowerCase()  );


		// 		const isInLineText = this.checkWordIsInLine(wordDataArr[i], labelText);

		// 		if (isInLineText) {
		// 		// if (targetLabelText.toLowerCase().indexOf(labelText.toLowerCase()) != -1  && rect.intersects(dotRect)) {
		// 			topLeftLetterData = wordDataArr[i];
		// 			// answerData[i.toString()] = colorRect;
		// 			// return;
		// 		}

		// 	}
			
		// }

			
		// return topLeftLetterData;









		// // const topRect = this.topItemData.rect;

		// // const topCenterY = (topRect.y + topRect.height / 2);
		// // const bottomCenterY = (bottomRect.y + bottomRect.height / 2);
		
		// // const unitH = bottomCenterY - topCenterY;
		// // const unitW = topRect.width;
		// // const baseX = topRect.x;
		// // const baseY = topRect.y + topRect.height;


		

		// // const titleBottom = this.getTitleBottom();
		// // console.log("titleBottom: ", titleBottom);

		// // let topLeftLetter;
		// // const wordDataArr =  this.getPhotoWordArr(text, block, topLabelData);
		// // for (let i=0; i<wordDataArr.length; i++) {

		// // 	const tempWordArr = wordDataArr[i].word;
		// // 	for (let k=0; k<tempWordArr.length; k++) {
		// // 		const {location , content} = tempWordArr[k];


		// // 		// console.log('location: ~~ ', location);

		// // 		// if (location.top <= titleBottom) {
		// // 		// 	continue;
		// // 		// }

		// // 		wordDataArr[i].tmpLen = this.getToZeroLen(location)

					



		// // 		if (!topLeftLetter) {
		// // 			topLeftLetter = wordDataArr[i];
		// // 		} else {
		// // 			if (topLeftLetter.tmpLen > wordDataArr[i].tmpLen) {
		// // 				topLeftLetter = wordDataArr[i];
		// // 			}
		// // 		}
		// // 	}
			
		// // }

		// // return topLeftLetter;


	},

	getLineRect(line) {

		const tempWordArr = line.word;

		let sentenceRect;
		let left;
		let right;
		for (let k=0; k<tempWordArr.length; k++) {
			const {location , content} = tempWordArr[k];

			const tempRect = {
				x: location.left, 
				y: -location.bottom, 
				width: Math.abs( location.right - location.left ), 
				height: Math.abs( location.bottom - location.top ), 
			}
			const colorRect = this.getColorRect(tempRect);
			colorRect.labelText = content;
			// this.debugDrawLayer.addChild(colorRect);

					
			const rect = colorRect.ccRect;
			if (!sentenceRect) {
				sentenceRect = rect;
				left = rect.x;
				right = rect.x + rect.width;
			} else {
				if (rect.x + rect.width > right) {
					right = rect.x + rect.width;
				}
			}



		


		}

		if (sentenceRect) {
			sentenceRect.width = right - left;
		}

		return sentenceRect;



	},

	checkWordIsInLine(line, text) {

		console.log(" in checkWordIsInLine ");
		console.log(" line:  ", line);
		console.log(" word:  ", text);

		const textArr = text.trim().toLowerCase().split('');

		const word = line.word;
		let sentence = ''
		word.forEach(item => {
			sentence += item.content + ' ';
		});

		sentence.trim();
		sentence = sentence.toLowerCase();

		line.sentence = sentence;

		console.log(" sentence:  ", sentence);
		

		if (this.checkIsInsert(textArr, sentence)) {
			return true;
		}

		
		return false;

	},


	getTitleBottom() {
		let maxBottom = 0;
		const word = this.topLabelData.word;
		for (let i=0; i<word.length; i++) {
			if (word[i].location.bottom > maxBottom) {
				maxBottom = word[i].location.bottom;
			}
		}

		return maxBottom;
	},

	getToZeroLen(location) {
		const {top, left} = location;
		const len = Math.sqrt( Math.pow(left, 2) + Math.pow(top, 2) );
		return len;
	},



	getPhotoLabelData(textArr, block, isShow=true) {


		for(let j=0; j<block.length; j++) {

			const line = block[j];
			if (!line) {
				continue;
			}

			const sentence = line.content;


			if (isShow) {
				const label = this.getLabel(sentence, 150);
				label.x = line.left * this.debugBgImg.width;
				label.y = -(line.top + (line.bottom - line.top) / 2) * this.debugBgImg.height;
				label.parent = this.debugDrawLayer;
				label.zIndex = 200;
				// label.color = cc.Color.RED;
				const l = label.getComponent(cc.Label);
				label.anchorX = 0;
				console.log(' sentence~:  ', sentence);
			}




			if (this.checkIsInsert(textArr, sentence)) {
				return line;
			}

		}

		return false;

		// for(let j=0; j<block.length; j++) {

		// 	const line = block[j].line;
		// 	if (!line) {
		// 		continue;
		// 	}

		// 	for (let i=0; i<line.length; i++) {

		// 		const word = line[i].word;
		// 		let sentence = ''
		// 		word.forEach(item => {
		// 			sentence += item.content + ' ';
		// 		});
	
		// 		sentence.trim();
		// 		sentence = sentence.toLowerCase();
	
		// 		line[i].sentence = sentence;

		// 		if (this.checkIsInsert(textArr, sentence)) {
		// 			return line[i];
		// 		}
		// 	}
		// }

		// return false;
	},

	checkIsInsert(textArr, sentence) {
		// console.log('textArr: ', textArr);
		// console.log('sentence: ', sentence);

		sentence = sentence.toLowerCase();

		let index = -1;
		for (let i=0; i<textArr.length; i++) {
			index = sentence.indexOf(textArr[i].toLowerCase(), index);
			// console.log('index: ', index);
			if (index == -1) {
				return false;
			}
		}

		return true;
	},

	showUserRight(answerData) {

		console.log('answerData: ', answerData);

		if (Object.keys(answerData).length == 0) {

			// const curWordBg = this.wordBgArr[this.quesArrIndex];
			// const {wordNode} = curWordBg;
			// wordNode.hitCount = 0;
			return;
		}

		// this.showCurAnswerPic();

		this.showCardRight();

		return;
	},

	showCurAnswerPic() {

		const curWordBg = this.wordBgArr[this.quesArrIndex];
		const {wordNode} = curWordBg;

		if (!wordNode.hitCount) {
			wordNode.hitCount = 0;
		}

		wordNode.hitCount ++;
		if (wordNode.hitCount < 1) {
			return;
		}


		this.showLetterLabel(wordNode, true);
		this.showAnswerIcon(curWordBg, true)
		return;

		// for (let i=0; i<this.wordBgArr.length; i++) {
		// 	const wordBg = this.wordBgArr[i];
		// 	if (wordBg.data == this.curQues) {
		// 		console.log('aaa')
		// 		this.showLetterLabel(wordBg);
		// 		this.showAnswerIcon(this.wordBgArr[i], true)
		// 		return;
		// 	}
		// }

	},

	showUserRight_(answerData, data) {

		const text = data?.result?.text
		if (!text) {
			return false;
		}


		console.log('answerData: ', answerData);
		// console.log('this.picNodeArr: ', this.picNodeArr);

		if (Object.keys(answerData).length == 0) {
			return;
		}



		for (let i = 0; i < this.animaNodeArr.length; i++) {

			const animaNode = this.animaNodeArr[i];

			const key = animaNode.data.rectItem // i.toString();

			console.log('key: ', key)

			console.log('~key: ', key)

			if (!animaNode.hitCount) {
				animaNode.hitCount = 0;
			}

			if (answerData[key] && answerData[key].isFinish) {
				this.showLetter(animaNode);
				// this.removeLine(answerData[key].line, block);
			} else {

				animaNode.hitCount = 0;
			}
		}


		// for (let i = 0; i < this.picNodeArr.length; i++) {

		// 	const picNode = this.picNodeArr[i];

		// 	const key = picNode.data.rectItem // i.toString();

		// 	console.log('key: ', key)

		// 	if (answerData[key] && answerData[key].isFinish) {
		// 		this.showLetter(picNode);
		// 		this.removeLine(answerData[key].line, block);
		// 	} else {

		// 		picNode.hitCount = 0;
		// 	}
		// }


	},

	removeLine(line, block) {

		console.log('block: ', JSON.stringify(block));
		for (let i=0; i<block.length; i++) {
			const lineArr = block[i].line;
	
			const index = lineArr.indexOf(line);
			if (index != -1) {
				lineArr.splice(index, 1);
				console.log(' ```splice lineArr.length: ' , lineArr.length);
			}
		}
	},

	showUserWrong(answerData) {

		console.log('answerData: ', answerData);
		console.log('this.picNodeArr: ', this.picNodeArr);

		if (Object.keys(answerData).length == 0) {
			return;
		}


		for (let i = 0; i < this.picNodeArr.length; i++) {

			const picNode = this.picNodeArr[i];

			const key = picNode.data.rectItem // i.toString();

			console.log('key: ', key)

			if (answerData[key] && answerData[key].count >= 3) {
				this.showLetter(picNode, false);
			}
		}


	},


	showAnswerIcon(wordBg, isRight) {

		if (wordBg.isIconShowEnd) {
			return;
		}
		wordBg.isIconShowEnd = true;

		const {rightIcon, rightAnim, wrongIcon, wrongAnim} = wordBg;
		if (isRight) {
			// this.appearAnim(rightIcon);
			rightAnim.node.active = true;
			rightAnim.playAnimation('right', 1);

		} else {
			// this.appearAnim(wrongIcon);
			wrongAnim.node.active = true;
			wrongAnim.playAnimation('right', 1);
		}

	},
	
	showLetterLabel(picNode, isRight = true) {

		// let writeRect = this.writeNodeArr[Number(index)];

		console.log('in showLetter 1');


		picNode.hitCount++;
		if (picNode.hitCount < 1) {
			return;
		}


		console.log('in showLetter 2');


		if (picNode.isShowEnd) {
			return;
		}

		console.log('in showLetter 3');

		picNode.active = true;
		picNode.isShowEnd = true;
		picNode.isRight = isRight;

		if (picNode.data) {
			picNode.data.isRight = isRight;
		}


		let clip = this.rightClip;
		if (!isRight) {

			
			clip = this.wrongClip;
			picNode.color =  cc.Color.fromHEX(new cc.Color(), '#f35936')//cc.Color.RED;
			
		} else {
			picNode.color =  cc.Color.fromHEX(new cc.Color(), '#2b62b0')
		}



		cc.tween(picNode)
			.to(1, {opacity: 255}, {easing: "cubicOut"})
			.start();

		playAudio(clip, () => {
		
		})

		// picNode.playRightAnim();
		// this.playRightAnim(picNode);

		// if (!this.isGameEnd) {
		// 	this.checkGameEnd(this.animaNodeArr);
		// }
	
	},

	showLetter(picNode, isRight = true) {

		// let writeRect = this.writeNodeArr[Number(index)];

		console.log('in showLetter 1');


		picNode.hitCount++;
		if (picNode.hitCount < 1) {
			return;
		}


		console.log('in showLetter 2');


		if (picNode.isShowEnd) {
			return;
		}

		console.log('in showLetter 3');

		picNode.isShowEnd = true;
		picNode.isRight = isRight;


		// picNode.playRightAnim();
		this.playRightAnim(picNode);

		if (!this.isGameEnd) {
			this.checkGameEnd(this.animaNodeArr);
		}

		return;


		picNode.answerPic.active = true;



		if (!isRight) {
			console.log(' ~ !isRight');
			picNode.answerPic.color = cc.Color.fromHEX(new cc.Color(), '#ef7961')
			playAudio(this.wrongClip);

			if (!this.isGameEnd) {
				this.checkGameEnd();
			}
			return;
		} else {
			picNode.answerPic.color = cc.Color.fromHEX(new cc.Color(), '#548fd4')
			playAudio(this.rightClip);

		}

		this.showAnimaStar(picNode, ()=> {
			
			if (!this.isGameEnd) {
				this.checkGameEnd();
			}

		});

	
	},

	showAnimaStar(node, cb) {

		const resDragonBone = cc.find("Canvas/res/anim/right")
		const dNode = cc.instantiate(resDragonBone)
		node.addChild(dNode, 20);

		const dragonDisplay = dNode.getComponent(dragonBones.ArmatureDisplay);

		dragonDisplay.playAnimation('newAnimation', 1);

		dragonDisplay.on(dragonBones.EventObject.COMPLETE, ()=> {
			console.log('play end');
			cb && cb();
		})
		

	},

	getAnswerData(data) {
		
		const answerData = {};
		const wordData = this.curQues;
		console.log('wordData:' , wordData);
		let targetText = wordData.text_en;


		// const hasAnswer = this.checkHasAnswer(data, targetText);
		// console.log('hasAnswer:', hasAnswer);

		// if (hasAnswer) {
		// 	answerData['1'] = true;
		// 	return answerData;
		// } 





		// let targetText = wordData.text_en;
		let targetText1;
		let targetText2;
		if (targetText.indexOf('(') != -1) {
			targetText1 = targetText.replace(/(\(+)|(\)+)/g, "");
			targetText2 = targetText.replace(/(\(+.*\)+)/g, "");
		}
		if (targetText.indexOf('（') != -1) {
			targetText1 = targetText.replace(/(\（+)|(\）+)/g, "");
			targetText2 = targetText.replace(/(\（+.*\）+)/g, "");
		}


		const checkFunc = (targetT) => {
			console.log('targetT: ', targetT);
			const hasAnswer = this.checkHasAnswer2(data, targetT);
			if (hasAnswer) {
				answerData['1'] = true;
			}
		}

		checkFunc(targetText);
		if (answerData['1']) {
			return answerData;
		}

		if (targetText1) {
			checkFunc(targetText1);
			if (answerData['1']) {
				wordData.text_en = targetText1;
				return answerData;
			}
		}
		
		if (targetText2) {
			checkFunc(targetText2);
			if (answerData['1']) {
				wordData.text_en = targetText2;
				return answerData;
			}
		}
		

		// const hasAnswer = this.checkHasAnswer2(data, targetText);
		// // const hasAnswer = this.checkHasAnswer(data, targetText);

		// console.log('hasAnswer:', hasAnswer);
		// if (hasAnswer) {
		// 	answerData['1'] = true;
		// } else if(targetText2) {
			
		// 	const hasAnswer2 = this.checkHasAnswer2(data, targetText2);
		// 	if (hasAnswer2) {
		// 		answerData['1'] = true;
		// 	}
		// }

		// console.log('hasAnswer:', hasAnswer);

		return answerData;
	},


	getTempWordArr(line, splitText) {

		const lineBox = {left: line.left, top: line.top, right: line.right, bottom: line.bottom};
		const baseX = lineBox.left;

		let textIndex = 0;
		const oneDisW = (lineBox.right - lineBox.left) / line.content.length;

		const arr = line.content.split(splitText);
		const wordArr = [];
		for (let i=0; i<arr.length; i++) {
			const content = arr[i];
			const location = {}
			location.left = baseX + textIndex * oneDisW;
			location.right = location.left + oneDisW * content.length;
			location.top = lineBox.top;
			location.bottom = lineBox.bottom;
			
			wordArr.push({content, location});

			textIndex += content.length;
		}

		return wordArr;
	},






	setCirclePosInRectArr(colorRect) {


		const rect = colorRect.ccRect;
		const dotV2 = new cc.Vec2(rect.x + rect.width/2, rect.y + rect.height / 2);

		const circleRectCheckArr = this.circleRectCheckArr;

		for (let i=0; i<circleRectCheckArr.length; i++) {

			const checkRect = circleRectCheckArr[i].ccRect;
			const key = circleRectCheckArr[i].data.index + 1;

			console.log("labelText: ", labelText);
			console.log("key: ", key);

			// if (labelText.toLowerCase().indexOf(targetLabelText.toLowerCase()) != -1 && rect.intersects(dotRect)) {
			if (checkRect.contains(dotV2)) {
				if (!colorRect.inRectArr) {
					colorRect.inRectArr = []
				}
				colorRect.inRectArr.push(key);
			}

		}
	},



	setOneAnswerDataNew(colorRect, answerData) {
		const rect = colorRect.ccRect;
		const dotV2 = new cc.Vec2(rect.x + rect.width/2, rect.y + rect.height / 2);


		const targetLabelText = colorRect.labelText;

		const newRectCheckArr = this.newRectCheckArr;

		for (let i=0; i<newRectCheckArr.length; i++) {

			const labelText = newRectCheckArr[i].data.labelText;
			const checkRect = newRectCheckArr[i].ccRect;
			const key = newRectCheckArr[i].data.index + 1;


			console.log("labelText: ", labelText);
			console.log("key: ", key);

			// if (labelText.toLowerCase().indexOf(targetLabelText.toLowerCase()) != -1 && rect.intersects(dotRect)) {
			// if (labelText == targetLabelText && checkRect.contains(dotV2)) {
			if (checkRect.contains(dotV2)) {
				// const len = targetLabelText.trim().length;

				// console.log('len: ', len);

				// if (labelText.length == 1) {

				// 	if (labelText.toLowerCase().indexOf(targetLabelText.toLowerCase()) != -1 ) {
				// 		answerData[key] = {isFinish: true};
				// 	}

				// } else {
					if (labelText.toLowerCase() == targetLabelText.toLowerCase()) {
						answerData[key] = {isFinish: true};
						console.log('finish key:', key);
					}
				// }


			}

		}
	},

	setOneAnswerData(colorRect, dotArr, answerData, line) {

		console.log(' in setOneAnswerData')
		console.log('colorRect: ', colorRect)
		console.log('dotArr: ', dotArr)
		console.log('answerData: ', answerData)

		
		const rect = colorRect.ccRect;
		const targetLabelText = colorRect.labelText;

		for (let i=0; i<dotArr.length; i++) {

			const {dotRect, labelText, key} = dotArr[i];

				console.log('targetLabelText.toLowerCase() : ', targetLabelText.toLowerCase() );
				console.log('labelText.toLowerCase()  : ', labelText.toLowerCase()  );
				console.log('rect.intersects(dotRect) : ', rect.intersects(dotRect) );

			if (labelText.toLowerCase().indexOf(targetLabelText.toLowerCase()) != -1 && rect.intersects(dotRect)) {
				const len = targetLabelText.trim().length;

				console.log('len: ', len);

				if (!answerData[key]) {
					answerData[key] = {colorRect, count: len};
				} else {
					answerData[key].count += len;

					// console.log('len: ', len);
					// console.log('	answerData[key].count: ', 	answerData[key].count);

				}

				if ( labelText.length <= 1) {
					answerData[key].isFinish = true;
					answerData[key].line = line;

				} else {
					if (answerData[key].count >= labelText.length) {
						answerData[key].isFinish = true;
						answerData[key].line = line;
					}
				}
				

			
				// return;
			}

		}

	},

	getColorRect(rect, color=null) {

		if (!color) {
			color = 'red'
		}


		rect.x *= this.debugBgImg.width;
		rect.y *= this.debugBgImg.height;
		rect.width *= this.debugBgImg.width;
		rect.height *= this.debugBgImg.height;

		const node = getSprNode(color);
		node.anchorX = 0;
		node.anchorY = 0;
		node.x = rect.x;
		node.y = rect.y;
		node.scaleX = rect.width / node.width;
		node.scaleY = rect.height / node.height;

		node.ccRect = new cc.Rect(rect.x, rect.y, rect.width, rect.height);



		return node;
	},



	getColorDot(x, y, w=100, h=100, color='red') {
		const node = new cc.Node();

		if (!h) {
			h = w;
		}

		x *= this.debugBgImg.width;
		y *= this.debugBgImg.height;
		w *= this.debugBgImg.width;
		h *= this.debugBgImg.height;

		if (this.debugLayer.parent && this.debugLayer.active) {

			const rect = {
				x:- w/2,
				y: - h/ 2, 
				width:w, 
				height:h
			}
			// const colorDot = this.getColorRect(rect,'blue');
			// colorDot.fillColor = cc.Color.BLUE;
			// colorDot.fillRect( - r/2, - r/ 2, r, r);

			const colorDot = getSprNode(color);

			
			// colorDot.anchorX = 0;
			// colorDot.anchorY = 0;
			// colorDot.x = rect.x;
			// colorDot.y = rect.y;
			colorDot.scaleX = rect.width / colorDot.width;
			colorDot.scaleY = rect.height / colorDot.height;
			node.addChild(colorDot);



			// const rect1 = new cc.Rect(node.x -r/2, node.y -r/2, r, r);
			// const colorDot = this.getColorRect(rect1, 'green');

			// colorDot.dotRect = rect1;
			// return colorDot;
		}

		node.x = x;
		node.y = y;


		// node.opacity = 0.5;

		const rect = new cc.Rect(node.x -w/2, node.y -h/2, w, h);
		node.dotRect = rect;
		node.ccRect = rect;
		return node;
	},

	
	checkHasAnswer2(_data, text) {

		text = text.toLowerCase();
		text = text.replace(/(^\s+)|(\s+)|(\s+$)/g,"");
		text = text.replace(/(\'+)|(\’+)|(\.+)|(\!+)/g, "");


		let sentenceArr = this.getFilterSentence(_data);

		for (let i=0; i<sentenceArr.length; i++) {
			const sentence = sentenceArr[i];
			if (sentence.indexOf(text) != -1) {
				console.log('sentence: ' + sentence + ', text: ' + text);

				return true;
			}
		}

		return false;



		const targetHitCount = this.getTargetHitCount(text);
		console.log('targetHitCount: ', targetHitCount);
		let curHitCount = 0;
		const block = data.block;
		for (let j = 0; j < block.length; j++) {

			const line = block[j].line;
			if (!line) {
				continue;
			}


			for (let i = 0; i < line.length; i++) {


				const word = line[i].word;



				console.log('word: ', word);
				// for (let k=0; k<word.length; k++) {

				// 	let content = word[k].content;
				
				// 	content = content.trim();
				// 	content = content.toLowerCase();

					

				// 	this.setTestLabel(line[i], word[k])

	
				// 	if (content == text) {
				// 		return true;
				// 	}
				// }


				let sentence = ''
				word.forEach(item => {
					sentence += item.content.trim();
				});

				sentence = sentence.trim();
				sentence = sentence.toLowerCase();
				sentence = sentence.replace(/(\'+)|(\’+)/g, "");
				sentence = sentence.replace(/(\'+)|(\’+)|(\.+)|(\!+)/g, "");


				line[i].sentence = sentence;
				console.log('sentence: ' + sentence + ', text: ' + text);

				if (sentence) {
					this.setTestLabel(line[i], sentence)
				}

				if (sentence.indexOf(text) != -1) {
				// if (sentence == text) {

				console.log('sentence: ' + sentence + ', text: ' + text);

					curHitCount ++;
					if (curHitCount >= targetHitCount) {
						return true;
					}

				}
			}
		}
	},

	getFilterSentence(data) {
		
		const sentenceArr = [];

		const block = data.block;
		for (let j = 0; j < block.length; j++) {

			const line = block[j].line;
			if (!line) {
				continue;
			}

			for (let i = 0; i < line.length; i++) {

				const word = line[i].word;

				console.log('word: ', word);

				let sentence = ''
				word.forEach(item => {
					sentence += item.content.trim();
				});

				sentence = sentence.trim();
				sentence = sentence.toLowerCase();
				sentence = sentence.replace(/(\'+)|(\’+)/g, "");
				sentence = sentence.replace(/(\'+)|(\’+)|(\.+)|(\!+)/g, "");

				line[i].sentence = sentence;
				// console.log('sentence: ' + sentence + ', text: ' + text);

				if (sentence) {
					this.setTestLabel(line[i], sentence)

					sentenceArr.push(sentence);
				}

			}
		}




		const deleteRightText = () => {

			// 排序一个新数组 防止有相同部分 先把长的某部分删除了
			const tempQuesArr = [];
			for (let i=0; i<this.quesArrIndex+1; i++) {
				tempQuesArr.push( this.quesArr[i] );
			}

			tempQuesArr.sort((a, b) => {
				return  b.text_en.length - a.text_en.length;
			})

			console.log('tempQuesArr: ', tempQuesArr);

			for (let i=0; i<tempQuesArr.length; i++) {
				let {text_en, isRight} = tempQuesArr[i];
	
				text_en = text_en.toLowerCase();
				text_en = text_en.replace(/(^\s+)|(\s+)|(\s+$)/g,"");
				text_en = text_en.replace(/(\'+)|(\’+)|(\.+)|(\!+)/g, "");

				//只找之前识别对的
				if (!isRight) {
					continue;
				}

				//识别到的句子中查找之前对的单词，找到的话从句子中删除
				for (let j=0; j<sentenceArr.length; j++) {
					const sentence = sentenceArr[j]

					if (sentence.indexOf(text_en) != -1) {
						sentenceArr[j] = sentence.replace(text_en, "");
						break;
					}
				}

			}

		}

		// deleteRightText();

		return sentenceArr;
	},

	getTargetHitCount(text) {

		let targetHitCount = 1;
		for (let i=0; i<this.quesArrIndex+1; i++) {
			let {text_en, isRight} = this.quesArr[i];

			text_en = text_en.toLowerCase();
			text_en = text_en.replace(/(^\s+)|(\s+)|(\s+$)/g,"");
			text_en = text_en.replace(/(\'+)|(\’+)|(\.+)|(\!+)/g, "");

			if (isRight && text_en.indexOf(text) != -1) {
				targetHitCount ++;
			}

			if (!isRight && text_en.indexOf(text) != -1) {
				console.log('isRight no: ', text_en);
			}
		}

		return targetHitCount;
	},

	checkHasAnswer(data, text) {

		text = text.toLowerCase();
		text = text.replace(/(^\s+)|(\s+)|(\s+$)/g,"");
		text = text.replace(/(\'+)|(\’+)|(\.+)|(\!+)/g, "");


		// const targetHitCount = this.getTargetHitCount(text);
		// console.log('targetHitCount: ', targetHitCount);
		// let curHitCount = 0;
		const block = data.block;
		for (let j = 0; j < block.length; j++) {

			const line = block[j].line;
			if (!line) {
				continue;
			}


			for (let i = 0; i < line.length; i++) {


				const word = line[i].word;

				console.log('word: ', word);
				for (let k=0; k<word.length; k++) {

					let content = word[k].content;


					content = content.trim();
					content = content.toLowerCase();
					content = content.replace(/(\'+)|(\’+)/g, "");
					content = content.replace(/(\'+)|(\’+)|(\.+)|(\!+)/g, "");

					

					this.setTestLabel(line[i], word[k])

	
					if (content == text) {
						return true;
					}
				}


				// let sentence = ''
				// word.forEach(item => {
				// 	sentence += item.content.trim();
				// });

				// sentence = sentence.trim();
				// sentence = sentence.toLowerCase();
				// sentence = sentence.replace(/(\'+)|(\’+)/g, "");
				// sentence = sentence.replace(/(\'+)|(\’+)|(\.+)|(\!+)/g, "");


				// line[i].sentence = sentence;
				// console.log('sentence: ' + sentence + ', text: ' + text);

				// if (sentence) {
				// 	this.setTestLabel(line[i], sentence)
				// }

				// if (sentence.indexOf(text) != -1) {
				// // if (sentence == text) {

				// console.log('sentence: ' + sentence + ', text: ' + text);

				// 	curHitCount ++;
				// 	if (curHitCount >= targetHitCount) {
				// 		return true;
				// 	}

				// }
			}
		}
	},

	


	setTestLabel(labelData, sentence) {

		console.log(' in setTestLabel')
		if (!this.debugLayer.parent || !this.debugLayer.active) {
			return;
		}
		console.log('labelData: ', labelData)
		const location = labelData.word[0].location;
		const label = this.getLabel(sentence);
		label.anchorX = 0;

		const l = label.getComponent(cc.Label);
		l.fontSize = 100 * this.canvas.width / 1080;
		l.lineHeight = l.fontSize;


		// label.anchorY = 1;
		label.x = location.left * 2;
		label.y = -location.top * 3
		label.zIndex = 50;


		const rect = {};
		rect.width = location.right - location.left;
		rect.height = location.bottom - location.top;
		rect.x = location.left;
		rect.y = -location.top;
		// const colorRect = this.getColorRect(rect, cc.Color.YELLOW);
		// this.debugLayer.addChild(colorRect);

		this.debugLayer.addChild(label);
	},

	getLabel(text, fontSize = 20) {
		const labelNode = new cc.Node();
		const label = labelNode.addComponent(cc.Label);
		label.string = text;
		labelNode.color = cc.Color.BLACK;
		label.fontSize = fontSize;
		label.lineHeight = fontSize;

		label.font = cc.find('Canvas/res/font/MMTB').getComponent(cc.Label).font;
	


		return labelNode;
	},

	getLabelNew(text, fontSize, color, outlineWidth, outlineColor, isBold=false) {
		

		const baseNode = cc.find('Canvas/res/font/MMTB_label');
		const labelNode = cc.instantiate(baseNode);
		const label = labelNode.getComponent(cc.Label);
		const labelOutline = labelNode.getComponent(cc.LabelOutline);


		label.string = text;
		label.fontSize = fontSize;
		labelNode.color = cc.Color.fromHEX(new cc.Color(), color);
		labelOutline.width = outlineWidth;
		labelOutline.color = cc.Color.fromHEX(new cc.Color(), outlineColor);
		label.enableBold = isBold;
		label.lineHeight = fontSize;





		// const labelNode = new cc.Node();
		// const label = labelNode.addComponent(cc.Label);
		// label.string = text;
		// labelNode.color = cc.Color.BLACK;
		// label.fontSize = fontSize;
		// label.lineHeight = fontSize;

		// label.font = cc.find('Canvas/res/font/MMTB').getComponent(cc.Label).font;
	


		// if (isBold) {
		// 	label.string = `<b>${label.string}</b>`
		// 	labelNode.isBold = true;
		// }
		
		// labelNode.color = cc.Color.BLACK;
		// // label.fontSize = fontSize;

		// labelNode.baseFontSize = fontSize;
		// labelNode.baseColor = color;
		// labelNode.baseOutlineColor = outlineColor;
		// labelNode.baseOutlineWidth = outlineWidth;

		// label.lineHeight = fontSize * 1.2;

		// label.horizontalAlign = cc.macro.TextAlignment.CENTER;

		// if (isFont) {
		// 	label.font = cc.find('Canvas/res/font/MMTB').getComponent(cc.Label).font;
		// 	label.MMTB = label.font;
		// }
	
		return labelNode;

	},



	debugLayer: null,
	initDebugLayer() {


		const layer = new cc.Node();
		layer.x = -this.canvas.width / 2 + 10;
		layer.y = this.canvas.height / 2 - 10;
		layer.active = false;


		this.canvas.addChild(layer, 20)
		this.debugLayer = layer;

		layer.scale = 0.5;

		layer.width = this.canvas.width;
		layer.height = this.canvas.height;
		// layer.anchorX = 0;
		// layer.anchorY = 1;

		// const w = layer.width * layer.scaleX;
		// const h = layer.height * layer.scaleY;
		// if (layer.active ) {
		// 	const bgRectNode = new cc.Node();
		// 	const ctx = bgRectNode.addComponent(cc.Graphics);
		// 	ctx.rect(-w / 2, -h/2, w, h);
		// 	ctx.fillColor = cc.Color.WHITE.setA(130);
		// 	ctx.fill();
		// 	this.canvas.addChild(bgRectNode, 10);
		// }
	



		// console.log(' in initDebugLayer');
		// const layer = new cc.Node();

		// if (this.data.isDebug) {
		// 	layer.parent = cc.find('Canvas');
		// }


		// layer.width = this.canvas.width / 2;
		// layer.height = this.canvas.height / 2;

		// layer.zIndex = 100;
		// layer.anchorX = 0;
		// layer.anchorY = 1;


		// if (!this.data.bgItem2) {
		// 	return;
		// }


		// cc.loader.load({url: this.data.bgItem2.url}, (err, img) => {

		// 	this.debugBgImg = img;
		// 	this.checkBg = img;
		// 	layer.width = img.width;
		// 	layer.height = img.height;

		// 	layer.data = this.data.bgItem2;

		// 	const sprNode = layer;
	
		// 	var sf = new cc.SpriteFrame(img);

		// 	const spr = sprNode.addComponent(cc.Sprite);
		// 	spr.spriteFrame = sf			

		// 	const sx = this.canvas.width / 2 / layer.width;
		// 	const sy = (this.canvas.height) / 2 / layer.height;
		// 	const s = Math.min(sx, sy);
		// 	layer.scale = s;

		// 	this.addNewRect();
		// 	// this.addCircleItem();
		// 	// this.addSignItem();
		// 	// this.addFingerItem();

		// 	this.initDebugRect();

		// 	this.checkStart();
	
		// });

		// layer.x = -this.canvas.width / 2 + 10;
		// layer.y = this.canvas.height / 2 - this.canvas.height / 3;
		// layer.opacity = 150;

		// // layer.scale = 2;
		// this.debugLayer = layer;

		// // const bgRectNode = new cc.Node();
		// // const ctx = bgRectNode.addComponent(cc.Graphics);
		// // ctx.fillRect(0, -layer.height, layer.width, layer.height);
		// // ctx.fillColor = cc.Color.YELLOW.setA(100);
		// // ctx.fill();
		// // layer.addChild(bgRectNode);


		// const drawLayer = new cc.Node();
    // this.debugLayer.addChild(drawLayer, 2);

    // this.debugDrawLayer = drawLayer;



	},

	initDebugRect() {

		console.log(' in initDebugRect');

		
		this.linkRectGroup = [];
		this.data.hotZoneItemArr2.forEach((item) => {
			switch (item.gIdx) {
				// case "0":
				// 	this.setOneDebugLinkRect(item);
				// 	break;

				case "0":
					// this.setOneDebugWriteRect(item);
					break;

				default:
					break;
			}

		});
	

	},

	setOneDebugLinkRect(data) {
		const rate = (this.debugLayer.scale * this.debugLayer.width) / this.data.bgItem2.rect.width;
	
		const rectNode = new cc.Node();
		rectNode.name = 'rect' + data.index;
		this.debugLayer.addChild(rectNode);

		let ctx = rectNode.addComponent(cc.Graphics);
		// 红色矩形
		ctx.lineWidth = 4;
		ctx.strokeColor = cc.Color.BLACK;
		ctx.fillColor = cc.Color.WHITE.setA(100);

		const scale = rate / this.debugLayer.scaleY;

		rectNode.width = data.rect.width * scale;
		rectNode.height = data.rect.height * scale;
		rectNode.x = data.rect.x * scale;
		rectNode.y =  - data.rect.height * scale - data.rect.y * scale;
	

		rectNode.anchorX = 0;
		rectNode.anchorY = 0;

		if (this.data.isDebug) {
			ctx.rect(0, 0, rectNode.width, rectNode.height);
		}
		ctx.stroke();
		ctx.fill();


		rectNode['data'] = data;
		rectNode.opacity = 100;

		rectNode['ccRect'] = rectNode.getBoundingBoxToWorld()


		rectNode.isRightPoint = data.checkbox.list[0].value == true;

		this.linkRectGroup.push(rectNode);

		this.setLinkDataByDebugItem(rectNode, data.index);

	},

	setLinkDataByDebugItem(item, index) {

		let hzItemId;
		let debugItemId;
		let linkHzItemId;
		let linkDebugItemId;


		debugItemId = index + 1;

		const hzItem = this.getHzItemByPoint(debugItemId)

		hzItemId = this.data.hotZoneItemArr.indexOf(hzItem) + 1;

		console.log(' hzItem: ', hzItem);
		console.log(' debugItemId: ', debugItemId);

		linkHzItemId = hzItem.linkItem;

		const linkHzItem = this.data.hotZoneItemArr[linkHzItemId-1]

		linkDebugItemId = linkHzItem.pointItem;


		const linkData = {hzItemId, debugItemId, linkHzItemId, linkDebugItemId};
		item.linkData = linkData;

	},

	getHzItemByPoint(pointId, gidx = '0') {
		
		const hzItem = this.data.hotZoneItemArr.find((item) => {

			if (item.gIdx == gidx) {
				return item.pointItem == pointId
			}
		});

		return hzItem;
	},

	addFingerItem() {
		if (!this.fingerRectArr) {
			return;
		}

		this.fingerRectCheckArr = [];
		const bg = this.debugLayer;
		for (let i=0; i<this.fingerRectArr.length; i++) {
			const oneData = this.fingerRectArr[i];
			const rect = this.setDebugRectDot(oneData, bg);
			this.fingerRectCheckArr.push(rect);
			console.log('oneData: ', oneData);
		}
	},

	addSignItem() {
		if (!this.signRectArr) {
			return;
		}

		this.signRectCheckArr = [];
		const bg = this.debugLayer;
		for (let i=0; i<this.signRectArr.length; i++) {
			const oneData = this.signRectArr[i];
			const rect = this.setDebugRectDot(oneData, bg);
			this.signRectCheckArr.push(rect);
			console.log('oneData: ', oneData);
		}
	},

	addCircleItem() {

		if (!this.circleRectArr) {
			return;
		}

		this.circleRectCheckArr = [];
		const bg = this.debugLayer;
		for (let i=0; i<this.circleRectArr.length; i++) {
			const oneData = this.circleRectArr[i];
			const rect = this.setDebugRectDot(oneData, bg);
			this.circleRectCheckArr.push(rect);
			console.log('oneData: ', oneData);
		}
	},


	setDebugRectDot(data, bg) {
		const bgData = bg.data;
		const rate = (bg.scale * bg.width) / bgData.rect.width;

		const rectNode = new cc.Node();
		rectNode.name = 'rect' + data.index;
		bg.addChild(rectNode);


		const ctx = rectNode.addComponent(cc.Graphics);
		// 红色矩形
		ctx.lineWidth = 4;
		ctx.strokeColor = cc.Color.BLACK;
		ctx.fillColor = cc.Color.WHITE.setA(100);

		const scale = rate / bg.scaleY;

		console.log('scale: ', scale);

		rectNode.width = data.rect.width * scale;
		rectNode.height = data.rect.height * scale;
		rectNode.x = data.rect.x * scale;
		rectNode.y =  - data.rect.y * scale - data.rect.height * scale;


		rectNode.anchorX = rectNode.anchorY = 0;


		rectNode.x /= bg.width;
		rectNode.y /= bg.height;
		rectNode.width /= bg.width;
		rectNode.height /= bg.height;
		const colorRect = this.getColorRect(rectNode, 'blue');
		colorRect.opacity = 180;
		colorRect.data = data;
		bg.addChild(colorRect, 20);

		return colorRect;
	},

	addNewRect() {
		
		if (!this.newRectArr) {
			return;
		}

		this.newRectCheckArr = [];
		const bg = this.debugLayer;
		for (let i=0; i<this.newRectArr.length; i++) {
			const oneData = this.newRectArr[i];
			this.setNewRectDot(oneData, bg);
			console.log('oneData: ', oneData);
		}

	},


	setNewRectDot(data, bg) {
		const bgData = bg.data;
		const rate = (bg.scale * bg.width) / bgData.rect.width;

		const rectNode = new cc.Node();
		rectNode.name = 'rect' + data.index;
		bg.addChild(rectNode);


		const ctx = rectNode.addComponent(cc.Graphics);
		// 红色矩形
		ctx.lineWidth = 4;
		ctx.strokeColor = cc.Color.BLACK;
		ctx.fillColor = cc.Color.WHITE.setA(100);

		const scale = rate / bg.scaleY;

		console.log('scale: ', scale);

		rectNode.width = data.rect.width * scale;
		rectNode.height = data.rect.height * scale;
		rectNode.x = data.rect.x * scale;
		rectNode.y =  - data.rect.y * scale - data.rect.height * scale;


		rectNode.anchorX = rectNode.anchorY = 0;


		rectNode.x /= bg.width;
		rectNode.y /= bg.height;
		rectNode.width /= bg.width;
		rectNode.height /= bg.height;
		const colorRect = this.getColorRect(rectNode, 'green');
		colorRect.opacity = 180;
		colorRect.data = data;
		bg.addChild(colorRect, 20);

		this.newRectCheckArr.push(colorRect);                                                                                                                                                                                        


		// if (this.data.bgItem.isShowDebugLine || true) {
		// 	ctx.rect(0, 0, rectNode.width, rectNode.height);
		// }
		// ctx.stroke();
		// ctx.fill();

	},
	 


	getPhotoWordArr(text, block, benchmark1Data) {


		const wordArr = [];
		// const maxLen = 10;

		text = text.trim();

		const topY = -benchmark1Data.top;

		for(let j=0; j<block.length; j++) {

			const line = block[j];
			if (!line) {
				continue;
			}


			const sentence = line.content;
			if (sentence.indexOf(text) != -1 ) {
				wordArr.push( line );
			}

			// for (let i=0; i<line.length; i++) {


			// 	const location = line[i].word[0].location;

			// 	const curTop = -location.top;
			// 	if (curTop >= topY ) {
			// 		continue;
			// 	}


			// 	let word = line[i].word;
			// 	let sentence = ''

			// 	// if (word.length > maxLen) {
			// 	// 	console.log('continue ', word.length);
			// 	// 	continue;
			// 	// }

			// 	line[i].word = word = this.checkCutWordData(word);
			// 	// console.log('word1~ ', word);


			// 	word.forEach(item => {
			// 		sentence += item.content + '';
			// 	});

			// 	sentence = sentence.trim().toLowerCase();

			// 	text = text.toLowerCase();

			// 	line[i].sentence = sentence;
			// 	console.log('sentence: ', sentence);
			// 	console.log('text: ', text);

			// 	console.log('index: ', sentence.indexOf(text));
			// 	if (sentence.indexOf(text) != -1 ) {
			// 		wordArr.push( line[i] );
			// 	}
			// }
		}

		return wordArr;
	},


	checkCutWordData(wordArr) {


		// console.log('wordArr: ', wordArr);

		let newWordArr = [];
		for(let i=0; i<wordArr.length; i++) {

			let wordObj = wordArr[i];

			wordObj.content = wordObj.content.trim();

			if (wordObj.content.length > 1) {

				const tmpArr = [];
				const w = wordObj.location.right - wordObj.location.left
				const subW = w / wordObj.content.length;
				for (let j=0; j<wordObj.content.length; j++) {

					const subWordObj = {};
					subWordObj.content = wordObj.content[j];
					subWordObj.location = {
						top: wordObj.location.top,
						bottom: wordObj.location.bottom,
						left: wordObj.location.left + subW * j,
						right: wordObj.location.left + subW * (j + 1)
					}

					tmpArr.push(subWordObj);
				}
				newWordArr = newWordArr.concat(tmpArr)


			} else {
				newWordArr.push(wordObj)
			}

		}

		// console.log('newWordArr: ', newWordArr);
		return newWordArr;
	},

	getPhotoData(cb) {
	


		

		// const tmpData1 = {"x":"0.76","y":"0.36"}
		// const tmpData1 = {"page_id":"5","book_name":"Oxford_Phonics_World_1_SB"}

		
		const tmpData1 = {"allText":"juicy peach","block":[{"line":[{"word":[{"content":"juicy","cornerPoint":[{"x":317,"y":117},{"x":392,"y":98},{"x":401,"y":135},{"x":326,"y":154}],"location":{"bottom":154,"left":317,"right":401,"top":98},"recognizedLanguage":"und"},{"content":"peach","cornerPoint":[{"x":403,"y":101},{"x":476,"y":83},{"x":483,"y":116},{"x":410,"y":134}],"location":{"bottom":134,"left":403,"right":483,"top":83},"recognizedLanguage":"und"}]}]}]}
		// const tmpData1 =  {"allText":"book\nruler\npencil","block":[{"line":[{"word":[{"content":"book","cornerPoint":[{"x":265,"y":72},{"x":343,"y":76},{"x":341,"y":102},{"x":263,"y":98}],"location":{"bottom":102,"left":263,"right":343,"top":72},"recognizedLanguage":"und"}]}]},{"line":[{"word":[{"content":"ruler","cornerPoint":[{"x":277,"y":114},{"x":345,"y":114},{"x":344,"y":139},{"x":276,"y":139}],"location":{"bottom":139,"left":276,"right":345,"top":114},"recognizedLanguage":"und"}]},{"word":[{"content":"pencil","cornerPoint":[{"x":277,"y":142},{"x":338,"y":133},{"x":341,"y":160},{"x":280,"y":169}],"location":{"bottom":169,"left":277,"right":341,"top":133},"recognizedLanguage":"und"}]}]}]}
		// const tmpData1 =  {  "allText" : "book\nhelle\nfioe",  "block" : [    {      "line" : [        {          "word" : [            {              "content" : "book",              "location" : {                "bottom" : 466.4888916015625,                "top" : 418.13333129882812,                "right" : 278.39999389648438,                "left" : 220.80000305175781              },              "cornerPoint" : [                {                  "x" : 147,                  "y" : 139                },                {                  "x" : 147.81631469726562,                  "y" : 173.990478515625                },                {                  "x" : 163.81196594238281,                  "y" : 173.6173095703125                },                {                  "x" : 162.99565124511719,                  "y" : 138.6268310546875                }              ]            }          ]        }      ]    },    {      "line" : [        {          "word" : [            {              "content" : "helle",              "location" : {                "bottom" : 568.888916015625,                "top" : 517.68890380859375,                "right" : 262.39999389648438,                "left" : 214.39999389648438              },              "cornerPoint" : [                {                  "x" : 184,                  "y" : 134                },                {                  "x" : 182.19378662109375,                  "y" : 162.94369506835938                },                {                  "x" : 198.1627197265625,                  "y" : 163.94023132324219                },                {                  "x" : 199.96893310546875,                  "y" : 134.99653625488281                }              ]            }          ]        }      ]    },    {      "line" : [        {          "word" : [            {              "content" : "fioe",              "location" : {                "bottom" : 950.04443359375,                "top" : 932.977783203125,                "right" : 572.79998779296875,                "left" : 547.20001220703125              },              "cornerPoint" : [                {                  "x" : 328,                  "y" : 343                },                {                  "x" : 328.23532104492188,                  "y" : 357.9981689453125                },                {                  "x" : 333.23471069335938,                  "y" : 357.91973876953125                },                {                  "x" : 332.9993896484375,                  "y" : 342.92156982421875                }              ]            }          ]        }      ]    }  ]}
		// const tmpData1 =  {"allText":"pooy","block":[{"line":[{"word":[{"content":"pooy","cornerPoint":[{"x":229,"y":143},{"x":229,"y":118},{"x":240,"y":118},{"x":240,"y":143}],"location":{"bottom":240,"left":145,"right":170,"top":229},"recognizedLanguage":"und"}]}]}]}
		// const tmpData1 = {"result":{"text":[{"left":0.4309999942779541,"right":0.5609999895095825,"top":0.5094433426856995,"bottom":0.5751649737358093,"score":0.8339493274688721,"content":"Cc","characters":[{"character":"C","centerLoc":[0.47766668,0.53908247],"poly":[0.45433334,0.50944334,0.50266665,0.50944334,0.50266665,0.56872165,0.45433334,0.56872165]},{"character":"c","centerLoc":[0.531,0.55068046],"poly":[0.5126667,0.53135055,0.551,0.53135055,0.551,0.56872165,0.5126667,0.56872165]}]}]}}
		// const tmpData1 = {"result":{"text":[{"left":0.4259999990463257,"right":0.5609999895095825,"top":0.5081546306610107,"bottom":0.5777422785758972,"score":0.8703044652938843,"content":"Cc","characters":[{"character":"C","centerLoc":[0.476,0.5377938],"poly":[0.451,0.50815463,0.501,0.50815463,0.501,0.56872165,0.451,0.56872165]},{"character":"c","centerLoc":[0.5276667,0.54939175],"poly":[0.5093334,0.53135055,0.54766667,0.53135055,0.54766667,0.56872165,0.5093334,0.56872165]}]}]}}
		// const tmpData1 =  {"result":{"text":[{"points":[0.749,0.505,0.601,0.522]}]}}
		// const tmpData1 = {"result":{"text":[{"symbol":[4,2,3,3,3]}]}};
		// const tmpData1 = {"result":{"text":[{"points":[0.20666666,0.45618558,0.21,0.45618558,0.21333334,0.45618558,0.21666667,0.45618558,0.22,0.45618558,0.22333333,0.45618558,0.22666667,0.45618558,0.23,0.45618558,0.23333333,0.45618558,0.2,0.45876288,0.20333333,0.45876288,0.20666666,0.45876288,0.21,0.45876288,0.21333334,0.45876288,0.21666667,0.45876288,0.22,0.45876288,0.22333333,0.45876288,0.22666667,0.45876288,0.23,0.45876288,0.23333333,0.45876288,0.23666666,0.45876288,0.24,0.45876288,0.19,0.46134022,0.19333333,0.46134022,0.19666667,0.46134022,0.2,0.46134022,0.20333333,0.46134022,0.20666666,0.46134022,0.21,0.46134022,0.21333334,0.46134022,0.21666667,0.46134022,0.22,0.46134022,0.22333333,0.46134022,0.22666667,0.46134022,0.23,0.46134022,0.23333333,0.46134022,0.23666666,0.46134022,0.24,0.46134022,0.24333334,0.46134022,0.24666667,0.46134022,0.25,0.46134022,0.17666666,0.46391752,0.18333334,0.46391752,0.18666667,0.46391752,0.19,0.46391752,0.19333333,0.46391752,0.19666667,0.46391752,0.24333334,0.46391752,0.24666667,0.46391752,0.25,0.46391752,0.25333333,0.46391752,0.25666666,0.46391752,0.26333332,0.46391752,0.17333333,0.46649486,0.17666666,0.46649486,0.18,0.46649486,0.18333334,0.46649486,0.25666666,0.46649486,0.26,0.46649486,0.26333332,0.46649486,0.26666668,0.46649486,0.17,0.46907216,0.17333333,0.46907216,0.17666666,0.46907216,0.26333332,0.46907216,0.26666668,0.46907216,0.27,0.46907216,0.16333333,0.4716495,0.16666667,0.4716495,0.17,0.4716495,0.17333333,0.4716495,0.26666668,0.4716495,0.27,0.4716495,0.27333334,0.4716495,0.27666667,0.4716495,0.16,0.4742268,0.16333333,0.4742268,0.16666667,0.4742268,0.27333334,0.4742268,0.27666667,0.4742268,0.28,0.4742268,0.15666667,0.47680414,0.16,0.47680414,0.16333333,0.47680414,0.27666667,0.47680414,0.28,0.47680414,0.28333333,0.47680414,0.15666667,0.47938144,0.16,0.47938144,0.28,0.47938144,0.28333333,0.47938144,0.15333334,0.48195878,0.15666667,0.48195878,0.28333333,0.48195878,0.28666666,0.48195878,0.14666666,0.48453608,0.15,0.48453608,0.15333334,0.48453608,0.28666666,0.48453608,0.29,0.48453608,0.29333332,0.48453608,0.14666666,0.48711342,0.15,0.48711342,0.15333334,0.48711342,0.28666666,0.48711342,0.29,0.48711342,0.29333332,0.48711342,0.14333333,0.48969072,0.14666666,0.48969072,0.15,0.48969072,0.29,0.48969072,0.29333332,0.48969072,0.29666665,0.48969072,0.14333333,0.49226806,0.14666666,0.49226806,0.29333332,0.49226806,0.29666665,0.49226806,0.14333333,0.49484536,0.29666665,0.49484536,0.14,0.4974227,0.14333333,0.4974227,0.29666665,0.4974227,0.3,0.4974227,0.14,0.5,0.3,0.5,0.13666667,0.5025773,0.14,0.5025773,0.3,0.5025773,0.30333334,0.5025773,0.13666667,0.5051546,0.14,0.5051546,0.3,0.5051546,0.30333334,0.5051546,0.13333334,0.507732,0.13666667,0.507732,0.14,0.507732,0.3,0.507732,0.30333334,0.507732,0.30666667,0.507732,0.13333334,0.5103093,0.13666667,0.5103093,0.30333334,0.5103093,0.30666667,0.5103093,0.13333334,0.5128866,0.13666667,0.5128866,0.30333334,0.5128866,0.30666667,0.5128866,0.13333334,0.5154639,0.13666667,0.5154639,0.30333334,0.5154639,0.30666667,0.5154639,0.13333334,0.51804125,0.13666667,0.51804125,0.30333334,0.51804125,0.30666667,0.51804125,0.13333334,0.52061856,0.13666667,0.52061856,0.30333334,0.52061856,0.30666667,0.52061856,0.13333334,0.52319586,0.13666667,0.52319586,0.30333334,0.52319586,0.30666667,0.52319586,0.13,0.52577317,0.13333334,0.52577317,0.13666667,0.52577317,0.30333334,0.52577317,0.30666667,0.52577317,0.31,0.52577317,0.13333334,0.52835053,0.13666667,0.52835053,0.30333334,0.52835053,0.30666667,0.52835053,0.13333334,0.53092784,0.13666667,0.53092784,0.30333334,0.53092784,0.30666667,0.53092784,0.13333334,0.53350514,0.13666667,0.53350514,0.30333334,0.53350514,0.30666667,0.53350514,0.13333334,0.53608245,0.13666667,0.53608245,0.30333334,0.53608245,0.30666667,0.53608245,0.13333334,0.5386598,0.13666667,0.5386598,0.30333334,0.5386598,0.30666667,0.5386598,0.13333334,0.5412371,0.13666667,0.5412371,0.30333334,0.5412371,0.30666667,0.5412371,0.13333334,0.5438144,0.13666667,0.5438144,0.14,0.5438144,0.3,0.5438144,0.30333334,0.5438144,0.30666667,0.5438144,0.13666667,0.5463917,0.14,0.5463917,0.3,0.5463917,0.30333334,0.5463917,0.13666667,0.5489691,0.14,0.5489691,0.3,0.5489691,0.30333334,0.5489691,0.14,0.5515464,0.3,0.5515464,0.14,0.5541237,0.14333333,0.5541237,0.29666665,0.5541237,0.3,0.5541237,0.14333333,0.556701,0.29666665,0.556701,0.14333333,0.55927837,0.14666666,0.55927837,0.29333332,0.55927837,0.29666665,0.55927837,0.14333333,0.5618557,0.14666666,0.5618557,0.15,0.5618557,0.29,0.5618557,0.29333332,0.5618557,0.29666665,0.5618557,0.14666666,0.564433,0.15,0.564433,0.15333334,0.564433,0.28666666,0.564433,0.29,0.564433,0.29333332,0.564433,0.14666666,0.5670103,0.15,0.5670103,0.15333334,0.5670103,0.28666666,0.5670103,0.29,0.5670103,0.29333332,0.5670103,0.15333334,0.56958765,0.15666667,0.56958765,0.28333333,0.56958765,0.28666666,0.56958765,0.15666667,0.57216495,0.16,0.57216495,0.28,0.57216495,0.28333333,0.57216495,0.15666667,0.57474226,0.16,0.57474226,0.16333333,0.57474226,0.27666667,0.57474226,0.28,0.57474226,0.28333333,0.57474226,0.16,0.57731956,0.16333333,0.57731956,0.16666667,0.57731956,0.27333334,0.57731956,0.27666667,0.57731956,0.28,0.57731956,0.16333333,0.5798969,0.16666667,0.5798969,0.17,0.5798969,0.17333333,0.5798969,0.26666668,0.5798969,0.27,0.5798969,0.27333334,0.5798969,0.27666667,0.5798969,0.17,0.58247423,0.17333333,0.58247423,0.17666666,0.58247423,0.26333332,0.58247423,0.26666668,0.58247423,0.27,0.58247423,0.17333333,0.58505154,0.17666666,0.58505154,0.18,0.58505154,0.18333334,0.58505154,0.25666666,0.58505154,0.26,0.58505154,0.26333332,0.58505154,0.26666668,0.58505154,0.17666666,0.58762884,0.18333334,0.58762884,0.18666667,0.58762884,0.19,0.58762884,0.19333333,0.58762884,0.19666667,0.58762884,0.24333334,0.58762884,0.24666667,0.58762884,0.25,0.58762884,0.25333333,0.58762884,0.25666666,0.58762884,0.26333332,0.58762884,0.19,0.5902062,0.19333333,0.5902062,0.19666667,0.5902062,0.2,0.5902062,0.20333333,0.5902062,0.20666666,0.5902062,0.21,0.5902062,0.21333334,0.5902062,0.21666667,0.5902062,0.22,0.5902062,0.22333333,0.5902062,0.22666667,0.5902062,0.23,0.5902062,0.23333333,0.5902062,0.23666666,0.5902062,0.24,0.5902062,0.24333334,0.5902062,0.24666667,0.5902062,0.25,0.5902062,0.2,0.5927835,0.20333333,0.5927835,0.20666666,0.5927835,0.21,0.5927835,0.21333334,0.5927835,0.21666667,0.5927835,0.22,0.5927835,0.22333333,0.5927835,0.22666667,0.5927835,0.23,0.5927835,0.23333333,0.5927835,0.23666666,0.5927835,0.24,0.5927835,0.20666666,0.5953608,0.21,0.5953608,0.21333334,0.5953608,0.21666667,0.5953608,0.22,0.5953608,0.22333333,0.5953608,0.22666667,0.5953608,0.23,0.5953608,0.23333333,0.5953608]}]}}


		// const tmpData1 = {"result":{"text":[{"type":1,"points":[0.23666666,0.45360824,0.24,0.45360824,0.22,0.45618558,0.22333333,0.45618558,0.22666667,0.45618558,0.23,0.45618558,0.23333333,0.45618558,0.24333334,0.45618558,0.24666667,0.45618558,0.25,0.45618558,0.25333333,0.45618558,0.25666666,0.45618558,0.26,0.45618558,0.20666666,0.45876288,0.21,0.45876288,0.21333334,0.45876288,0.21666667,0.45876288,0.26333332,0.45876288,0.26666668,0.45876288,0.27,0.45876288,0.27333334,0.45876288,0.19666667,0.46134022,0.2,0.46134022,0.20333333,0.46134022,0.27666667,0.46134022,0.28,0.46134022,0.28333333,0.46134022,0.17666666,0.46391752,0.18,0.46391752,0.18333334,0.46391752,0.18666667,0.46391752,0.19,0.46391752,0.19333333,0.46391752,0.28666666,0.46391752,0.29,0.46391752,0.29333332,0.46391752,0.29666665,0.46391752,0.3,0.46391752,0.30333334,0.46391752,0.30666667,0.46391752,0.31,0.46391752,0.31333333,0.46391752,0.31666666,0.46391752,0.32,0.46391752,0.32333332,0.46391752,0.32666665,0.46391752,0.17,0.46649486,0.17333333,0.46649486,0.28666666,0.46649486,0.33,0.46649486,0.33333334,0.46649486,0.33666667,0.46649486,0.34,0.46649486,0.34333333,0.46649486,0.34666666,0.46649486,0.35,0.46649486,0.35333332,0.46649486,0.35666665,0.46649486,0.36,0.46649486,0.36333334,0.46649486,0.36666667,0.46649486,0.37,0.46649486,0.16666667,0.46907216,0.28666666,0.46907216,0.16333333,0.4716495,0.28666666,0.4716495,0.16333333,0.4742268,0.28666666,0.4742268,0.16333333,0.47680414,0.28666666,0.47680414,0.16,0.47938144,0.28666666,0.47938144,0.16,0.48195878,0.28666666,0.48195878,0.16,0.48453608,0.28666666,0.48453608,0.16,0.48711342,0.29,0.48711342,0.15666667,0.48969072,0.29,0.48969072,0.15333334,0.49226806,0.29,0.49226806,0.15333334,0.49484536,0.29,0.49484536,0.15333334,0.4974227,0.29,0.4974227,0.15,0.5,0.29,0.5,0.15,0.5025773,0.29,0.5025773,0.15,0.5051546,0.29,0.5051546,0.15,0.507732,0.28666666,0.507732,0.15,0.5103093,0.28666666,0.5103093,0.15,0.5128866,0.28666666,0.5128866,0.15,0.5154639,0.28666666,0.5154639,0.15,0.51804125,0.28666666,0.51804125,0.15,0.52061856,0.28666666,0.52061856,0.15,0.52319586,0.28333333,0.52319586,0.15333334,0.52577317,0.28333333,0.52577317,0.15333334,0.52835053,0.28,0.52835053,0.15333334,0.53092784,0.27666667,0.53092784,0.15333334,0.53350514,0.27333334,0.53350514,0.15333334,0.53608245,0.26666668,0.53608245,0.27,0.53608245,0.15333334,0.5386598,0.25666666,0.5386598,0.26,0.5386598,0.26333332,0.5386598,0.15666667,0.5412371,0.25,0.5412371,0.25333333,0.5412371,0.15666667,0.5438144,0.24333334,0.5438144,0.24666667,0.5438144,0.15666667,0.5463917,0.23333333,0.5463917,0.23666666,0.5463917,0.24,0.5463917,0.16,0.5489691,0.23,0.5489691,0.16333333,0.5515464,0.22333333,0.5515464,0.22666667,0.5515464,0.16666667,0.5541237,0.17,0.5541237,0.17333333,0.5541237,0.17666666,0.5541237,0.18,0.5541237,0.18333334,0.5541237,0.18666667,0.5541237,0.19,0.5541237,0.19333333,0.5541237,0.19666667,0.5541237,0.2,0.5541237,0.20333333,0.5541237,0.20666666,0.5541237,0.21,0.5541237,0.21333334,0.5541237,0.21666667,0.5541237,0.22,0.5541237]}]}}
		// const tmpData1 = {"result":{"text":[{"left":0.22833333909511566,"right":0.3166666626930237,"top":0.5590206384658813,"bottom":0.628608226776123,"score":0.8552894592285156,"content":"Aa"},{"left":0.6816666126251221,"right":0.7666666507720947,"top":0.42257729172706604,"bottom":0.49860823154449463,"score":0.8148108720779419,"content":"Aa"},{"left":0.6983333230018616,"right":0.7666666507720947,"top":0.5564433336257935,"bottom":0.628608226776123,"score":0.7532452344894409,"content":"Aa"}]}}
		// const tmpData1 = {"result":{"text":[{"left":0.09814612567424774,"right":0.4471101462841034,"top":0.006644518114626408,"bottom":0.15614618360996246,"score":1,"content":"CTrace,write,and say."},{"left":0.10796073824167252,"right":0.5049073100090027,"top":0.1827242523431778,"bottom":0.4518272280693054,"score":0.9702169299125671,"content":"AAAA"},{"left":0.5834242105484009,"right":0.659760057926178,"top":0.17607973515987396,"bottom":0.4485049843788147,"score":0.9523985981941223,"content":"A"},{"left":0.6706652045249939,"right":0.8298800587654114,"top":0.15614618360996246,"bottom":0.43853819370269775,"score":0.9089533090591431,"content":"A"},{"left":0.5866957306861877,"right":0.6521264910697937,"top":0.634551465511322,"bottom":0.8504983186721802,"score":0.8326067328453064,"content":"a"},{"left":0.7699018716812134,"right":0.8276990056037903,"top":0.6411960124969482,"bottom":0.8039867281913757,"score":0.8035371899604797,"content":"a"}]}}
		cb(tmpData1);
		return;
	// const tmpData = {"allText":"Look and Trace\nblackboard\nwindow","block":[{"line":[{"word":[{"content":"Look","cornerPoint":[{"x":87,"y":203},{"x":83,"y":166},{"x":93,"y":164},{"x":97,"y":201}],"location":{"bottom":97,"left":85,"right":124,"top":83},"recognizedLanguage":"und"},{"content":"and","cornerPoint":[{"x":85,"y":161},{"x":82,"y":138},{"x":90,"y":137},{"x":93,"y":160}],"location":{"bottom":93,"left":127,"right":151,"top":82},"recognizedLanguage":"und"},{"content":"Trace","cornerPoint":[{"x":81,"y":132},{"x":77,"y":96},{"x":86,"y":95},{"x":90,"y":131}],"location":{"bottom":90,"left":156,"right":193,"top":77},"recognizedLanguage":"und"}]}]},{"line":[{"word":[{"content":"blackboard","cornerPoint":[{"x":119,"y":129},{"x":116,"y":58},{"x":131,"y":57},{"x":134,"y":128}],"location":{"bottom":134,"left":159,"right":231,"top":116},"recognizedLanguage":"und"}]}]},{"line":[{"word":[{"content":"window","cornerPoint":[{"x":171,"y":123},{"x":166,"y":72},{"x":177,"y":70},{"x":182,"y":121}],"location":{"bottom":182,"left":165,"right":218,"top":166},"recognizedLanguage":"und"}]}]}]}
		// const tmpData = {"allText":"Trace ttre letters\nLook! She is Short\nShe is a\ngirl.\nShe is a\ngirl.\nShe is smiling. She is","block":[{"line":[{"word":[{"content":"Trace","cornerPoint":[{"x":460,"y":366},{"x":416,"y":366},{"x":416,"y":354},{"x":460,"y":354}],"location":{"bottom":126,"left":20,"right":64,"top":114},"recognizedLanguage":"und"},{"content":"ttre","cornerPoint":[{"x":412,"y":367},{"x":387,"y":367},{"x":387,"y":354},{"x":412,"y":354}],"location":{"bottom":126,"left":68,"right":93,"top":113},"recognizedLanguage":"und"},{"content":"letters","cornerPoint":[{"x":384,"y":367},{"x":334,"y":367},{"x":334,"y":354},{"x":384,"y":354}],"location":{"bottom":126,"left":96,"right":146,"top":113},"recognizedLanguage":"und"}]}]},{"line":[{"word":[{"content":"Look!","cornerPoint":[{"x":340,"y":316},{"x":300,"y":318},{"x":299,"y":305},{"x":339,"y":303}],"location":{"bottom":177,"left":140,"right":181,"top":162},"recognizedLanguage":"und"}]}]}]}
		// const tmpData = {"allText":"e-Tnace the lettEr5\nAa Aa\nAa\nB b Bb Bbb\nBb\nCc\nCc","block":[{"line":[{"word":[{"content":"e-Tnace","cornerPoint":[{"x":399,"y":393},{"x":317,"y":395},{"x":316,"y":379},{"x":398,"y":377}],"location":{"bottom":103,"left":81,"right":164,"top":85},"recognizedLanguage":"und"},{"content":"the","cornerPoint":[{"x":313,"y":396},{"x":282,"y":396},{"x":281,"y":380},{"x":312,"y":380}],"location":{"bottom":100,"left":167,"right":199,"top":84},"recognizedLanguage":"und"},{"content":"lettEr5","cornerPoint":[{"x":278,"y":397},{"x":217,"y":398},{"x":216,"y":382},{"x":277,"y":381}],"location":{"bottom":99,"left":202,"right":264,"top":82},"recognizedLanguage":"und"}]}]},{"line":[{"word":[{"content":"Aa","cornerPoint":[{"x":436,"y":362},{"x":349,"y":363},{"x":348,"y":322},{"x":435,"y":321}],"location":{"bottom":159,"left":44,"right":132,"top":117},"recognizedLanguage":"und"}]}]}]}

		cb(tmpData);
	},


	checkGameEnd( arr ) {

		console.log(' in checkGameEnd arr.length: ', arr.length);
		if (!arr) {
			arr = this.animaNodeArr;
		}
		const isEnd = arr.every(node => {
			return node.isShowEnd;
		})

		if (isEnd) {
			this.gameEnd();
		} else {


			// this.endTesting();

			// setTimeout(() => {
			// 	this.startTesting();
			// }, 8000);

		}
	},














	bigStarArr: null,
	initStar() {
		const gArr = this.data.groupArr;
		if (gArr.length <= 1) {
			return;
		}

		this.cleanStar();

		this.bigStarArr = [];

		let baseX = this.canvas.width / 2 - 80 * this._mapScaleMin;
		let baseY = this.canvas.height / 2 - 80 * this._mapScaleMin;
		let disH = 80 * this._mapScaleMin;
		let disScale = 1;
		if (gArr.length > 5) {
			disH = (400 / gArr.length) * this._mapScaleMin;
			disScale = 5 / gArr.length;
		}
		for (let i = 0; i < gArr.length; i++) {
			const starBg = getSprNode('star_bg');
			this.canvas.addChild(starBg, 10);
			starBg.x = baseX;
			starBg.y = baseY - i * disH;
			starBg.scale = disScale;

			const starTop = getSprNode('star');
			starBg.addChild(starTop);
			starTop.active = false;
			starBg.star = starTop;

			const starBig = getSprNode('icon_bigstar');
			starTop.addChild(starBig);
			starBig.angle = -90;
			starBg.starBig = starBig;

			this.bigStarArr.push(starBg);
		}

		console.log("bigStarArr: ", this.bigStarArr);
	},

	cleanStar() {
		if (this.bigStarArr && this.bigStarArr.length > 0) {
			for (let i=0; i<this.bigStarArr.length; i++) {
				this.bigStarArr[i].removeFromParent();
			}
		}
	},


	showBigStar() {
		if (!this.bigStarArr || this.bigStarArr.length <= 0) {
			this.checkGameEnd();
			return;
		}
		const bigStarBg = this.bigStarArr[this.curGroupIndex];

		const starBig = bigStarBg.starBig;
		starBig.scale = 1;
		const star = bigStarBg.star;
		star.active = true;
		star.scaleX = 0.7 / bigStarBg.scale;
		star.scaleY = 1 / bigStarBg.scale;
		star.angle = 90;
		const canvas = cc.find('Canvas');
		const startPos = exchangeNodePos(star.parent, canvas, cc.v2(0, -canvas.height / 2));
		const middlePos = exchangeNodePos(star.parent, canvas, cc.v2(0, -canvas.height / 4));
		star.x = startPos.x;
		star.y = startPos.y - starBig.height;

		console.log('middlePos = ' + JSON.stringify(middlePos));
		const time = 1;
		cc.tween(star)
			.to(0.3, { y: middlePos.y + 80 }, { easing: 'quadOut' })
			.to(0.1, { y: middlePos.y + 40, scaleX: 1.2 / bigStarBg.scale, scaleY: 0.8 / bigStarBg.scale }, { easing: 'quadOut' })
			.to(0.1, { y: middlePos.y, scaleX: 1 / bigStarBg.scale, scaleY: 1 / bigStarBg.scale }, { easing: 'quadOut' })
			.delay(0.1)
			.to(0.8, { angle: -720, scale: 1 })
			.start();

		cc.tween(star)
			.delay(0.6)
			.to(0.8, { x: 0 }, { easing: 'quadIn' })
			.start();
		cc.tween(star)
			.delay(0.6)
			.to(0.8, { y: 0 }, { easing: 'quadOut' })
			.start();

		cc.tween(starBig)
			.delay(0.6)
			.to(0.8, { scale: 0 }, { easing: 'quadOut' })
			.call(() => {
				this.checkGameEnd();
				playAudio(this.starCountClip);
			})
			.start();

		playAudio(this.bigStarClip);
	},

	// checkGameEnd() {
	
	// 	this.curGroupIndex ++;
	// 	this.setCurGroupAndQuestion();



	// 	if (!this.curQuestionData) {
	// 		// this.gameEnd();
	// 		return;
	// 	}

	// 	this.showChangeQuesAnim();
	// },

	


	

	refreshCheckBtn() {

		this.checkBtn.opacity = 0;

		const arr = this.curOptionArr;
		for (let i=0; i<arr.length; i++) {
			if (arr[i].light.opacity > 254) {
				this.checkBtn.opacity = 255;
				return;
			}
		}
	},

	tryagain: null,
	initIcon() {
		const icon = getSprNode("try_again");
		icon.opacity = 0;
		icon.scale = this._mapScaleMin;
		this.canvas.addChild(icon);

		this.tryagain = icon;
	},

	showTryAgain() {
		const time = 0.3;
		cc.tween(this.tryagain)
			.to(time, {opacity: 255}, {easing: "cubicOut"})
			.delay(0.3)
			.to(time, {opacity: 0}, {easing: "cubicIn"})
			.start();
	},


	initQuestion() {
		this.initPicQuestion();
		this.initTextQuestion();
		this.initVideoQuestion();
		this.initAudioQuestion();
	},

	quesPicBg: null,
	initPicQuestion() {
		const picBg = getSprNode("ques_pic_bg");
		this.canvas.addChild(picBg);
		picBg.scale = this._mapScaleMin;
		picBg.y = 130 * this._mapScaleMin
		this.quesPicBg = picBg;
		picBg.active = false;

		this.addQuesAudio(picBg)
	},

	quesTextBg: null,
	initTextQuestion() {
		const picBg = getSprNode("ques_pic_bg");
		this.canvas.addChild(picBg);
		picBg.scale = this._mapScaleMin;
		picBg.y = 130 * this._mapScaleMin
		this.quesTextBg = picBg;


		const labelNode = new cc.Node();
		labelNode.parent = picBg;
		const label = labelNode.addComponent(cc.RichText);
		const size = 80
		label.font = cc.find('Canvas/res/font/Berlin-Sans-FB').getComponent(cc.Label).font;
		// label.string = `<outline color=#a83c13 width=2><size=${size}><color=#ffffff>${this.data.title || " " }</color></size></outline>`
		// label.string = `<size=${size}><color=#751e00>${this.curGroup.title }</color></size>`
		label.lineHeight = size;
		label.horizontalAlign = cc.macro.TextAlignment.CENTER

		label.maxWidth = 648;
	
		picBg.label = label;

		picBg.active = false;
		this.addQuesAudio(picBg)
	},

	quesVideoBg: null,
	videoNode: null,
	initVideoQuestion() {
		const picBg = getSprNode("ques_pic_bg");
		this.canvas.addChild(picBg);
		picBg.scale = this._mapScaleMin;
		picBg.y = 130 * this._mapScaleMin
		this.quesVideoBg = picBg;

		const videoNode = new cc.Node();
		const vPlayer = videoNode.addComponent(cc.VideoPlayer);
		picBg.addChild(videoNode);

		videoNode.width = 678;
		videoNode.height = 396;
		this.videoNode = videoNode;

		picBg.video = vPlayer;


		const btnNode = new cc.Node();
		picBg.addChild(btnNode);
		btnNode.x = picBg.width / 2 + 50;

		const playBtn = getSprNode("video_play");
		btnNode.addChild(playBtn);

		const pauseBtn = getSprNode("video_pause");
		btnNode.addChild(pauseBtn);
		pauseBtn.active = false;


		videoNode.player = vPlayer;
		videoNode.playBtn = playBtn;
		videoNode.pauseBtn = pauseBtn;

		playBtn.on(cc.Node.EventType.TOUCH_START, () => {
			vPlayer.play();
			playBtn.active = false;
			pauseBtn.active = true;
		})

		pauseBtn.on(cc.Node.EventType.TOUCH_START, () => {
			vPlayer.pause();
			pauseBtn.active = false;
			playBtn.active = true;
		})

		videoNode.on('completed', () => {
			pauseBtn.active = false;
			playBtn.active = true;
		})


		picBg.active = false;
	},

	quesAudioBg: null,
	initAudioQuestion() {

		
		const audioNode = new cc.Node();
		audioNode.active = false;

		this.canvas.addChild(audioNode);
		audioNode.x = 440 * this._mapScaleMin;
		audioNode.y = -60 * this._mapScaleMin;
		this.quesAudioBg = audioNode;
		
		const audioAnimNode = cc.instantiate(cc.find("Canvas/res/anim/audio_big"));
		audioNode.addChild(audioAnimNode);

		const iconTop = getSprNode('audio_big')
		audioNode.addChild(iconTop);
		iconTop.opacity = 255;

		iconTop.addComponent(cc.BlockInputEvents);
		iconTop.on(cc.Node.EventType.TOUCH_START, () => {

			if (iconTop.opacity == 0) {
				return;
			}

			if (!audioNode.audioClip) {
				return;
			}
			const anim = audioAnimNode.getComponent(cc.Animation);
			anim.play('audio_big');
			iconTop.opacity = 0;
			audioAnimNode.opacity = 255;

			if (audioNode.audioClip) {
				playAudio(audioNode.audioClip, () => {
					iconTop.opacity = 255;
					audioAnimNode.opacity = 0;
					anim.stop();
				});
			}
		})

	},


	addQuesAudio(bg) {
		const audioNode = new cc.Node();
		bg.addChild(audioNode);
		audioNode.x = bg.width / 2 + 50;


		const audioAnimNode = cc.instantiate(cc.find("Canvas/res/anim/ques_audio"));
		audioNode.addChild(audioAnimNode);

		const iconTop = getSprNode('ques_audio')
		audioNode.addChild(iconTop);
		iconTop.opacity = 255;

		iconTop.addComponent(cc.BlockInputEvents);
		iconTop.on(cc.Node.EventType.TOUCH_START, () => {

			if (iconTop.opacity == 0) {
				return;
			}
			const anim = audioAnimNode.getComponent(cc.Animation);
			anim.play('ques_audio');
			iconTop.opacity = 0;
			audioAnimNode.opacity = 255;

			if (audioNode.audioClip) {
				playAudio(audioNode.audioClip, () => {
					iconTop.opacity = 255;
					audioAnimNode.opacity = 0;
					anim.stop();
				});
			}
		})

		bg.audioNode = audioNode;
	},

	initOption() {
		this.initPicOption();
		this.initAudioOption();
		this.initTextOption();

		this.initPicOptionBig();
		this.initAudioOptionBig();
		this.initTextOptionBig();
	},

	optionPicBgArr: null,
	initPicOption() {
		// console.log('this.data: ', this.data);
		this.optionPicBgArr = [];
		for (let i=0; i<4; i++) {
		
			const pic = this.getOnePicOption();
			this.canvas.addChild(pic);
			pic.scale = this._mapScaleMin;
			pic.y = -235 * this._mapScaleMin;
			this.optionPicBgArr.push(pic);

		} 
	},

	optionPicBgBigArr: null,
	initPicOptionBig() {
		this.optionPicBgBigArr = [];

		const baseX = -380 * this._mapScaleMin;
		const disW = 440 * this._mapScaleMin;
		let baseY = 170 * this._mapScaleMin;
		const disH = 350 * this._mapScaleMin;
		let count = 0;


		for (let i=0; i<4; i++) {
		
			if (i==2) {
				count = 0;
				baseY -= disH;
			}
			const pic = this.getOnePicOption(true);
			this.canvas.addChild(pic);
			pic.scale = this._mapScaleMin;
			pic.x = baseX + count * disW;
			pic.y = baseY;
			this.optionPicBgBigArr.push(pic);

			count ++;
		} 
	},

	getOnePicOption(isBig = false) {
		const picBgParent = new cc.Node();

		let lightResName = "option_pic_bg_l";
		let bgResName = "option_pic_bg";
		if (isBig) {
			lightResName = "op_pic_bg_big_l";
			bgResName = "op_pic_bg_big";
		}

		const light = getSprNode(lightResName);
		picBgParent.addChild(light);
		light.opacity = 0;
		picBgParent.light = light;

		const picBg = getSprNode(bgResName);
		picBgParent.addChild(picBg);
		picBgParent.picBg = picBg;

		picBgParent.width = picBg.width;
		picBgParent.height = picBg.height;


		const soundNode = new cc.Node();
		picBgParent.addChild(soundNode);
		picBgParent.soundIcon = soundNode;

		const soundIconAnim = cc.instantiate(cc.find("Canvas/res/anim/laba"))
		soundNode.addChild(soundIconAnim);
		soundIconAnim.opacity = 0;

		const soundIconTop = getSprNode('btn_laba')
		soundNode.addChild(soundIconTop);
		soundIconTop.opacity = 255;

		soundNode.x = picBgParent.width / 2 - soundIconTop.width / 2;
		soundNode.y = picBgParent.height / 2 //- soundIconTop.height / 2;
		soundNode.active = false;


		picBgParent.active = false;


		picBgParent.on(cc.Node.EventType.TOUCH_START, () => {
			if( light.opacity == 0 ) {
				light.opacity = 255;
				playAudio(this.selectClip);
			} else {
				light.opacity = 0;
			}

			this.refreshCheckBtn();
		})


		soundIconTop.addComponent(cc.BlockInputEvents);
		soundIconTop.on(cc.Node.EventType.TOUCH_START, () => {
			const anim = soundIconAnim.getComponent(cc.Animation);
			anim.play('laba');
			soundIconTop.opacity = 0;
			soundIconAnim.opacity = 255;

			if (soundNode.audioClip) {
				playAudio(soundNode.audioClip, () => {
					soundIconTop.opacity = 255;
					soundIconAnim.opacity = 0;
					anim.stop();
				});
			}
		})

		return picBgParent;
	},

	addIconRight(bg) {

		const px = bg.width / 2;
		const py = -bg.height / 2 ;
		const worldPos = bg.convertToWorldSpaceAR(cc.v2(px, py));
		const localPos = this.canvas.convertToNodeSpaceAR(worldPos);


		const iconRight = getSprNode('icon_right');
		iconRight.scale = this._mapScaleMin;
		this.canvas.addChild(iconRight, 1);
		iconRight.x = localPos.x;
		iconRight.y = localPos.y + 50 * this._mapScaleMin;

		bg.iconRight = iconRight;


		this.showOneFirework(cc.v2(0, -bg.height / 3), bg, cc.find('paperBase').children, 200, 300, 20, 1);
	},


	optionAudioBgArr: null,
	initAudioOption() {
		this.optionAudioBgArr = [];
		for (let i=0; i<4; i++) {
		
			const audio = this.getOneAudioOption();
			this.canvas.addChild(audio);
			audio.scale = this._mapScaleMin;
			audio.y = -235 * this._mapScaleMin;
			this.optionAudioBgArr.push(audio);
		} 
	},

	optionAudioBgBigArr: null,
	initAudioOptionBig() {

		this.optionAudioBgBigArr = [];

		const baseX = -380 * this._mapScaleMin;
		const disW = 440 * this._mapScaleMin;
		let baseY = 170 * this._mapScaleMin;
		const disH = 350 * this._mapScaleMin;
		let count = 0;

		for (let i=0; i<4; i++) {
		
			if (i==2) {
				count = 0;
				baseY -= disH;
			}

			const audio = this.getOneAudioOption(true);
			this.canvas.addChild(audio);
			audio.scale = this._mapScaleMin;
			audio.x = baseX + count * disW;
			audio.y = baseY;
			this.optionAudioBgBigArr.push(audio);

			count ++;
		} 
	},


	optionTextBgArr: null,
	initTextOption() {
		this.optionTextBgArr = [];
		for (let i=0; i<4; i++) {
		
			const textOption = this.getOneTextOption();
			this.canvas.addChild(textOption);
			textOption.scale = this._mapScaleMin;
			// textOption.y = -235 * this._mapScaleMin;
			this.optionTextBgArr.push(textOption);
		} 
	},

	optionTextBgBigArr: null,
	initTextOptionBig() {

		const baseX = -180 * this._mapScaleMin;
		const disW = 100 * this._mapScaleMin;
		let baseY = 220 * this._mapScaleMin;
		const disH = 150 * this._mapScaleMin;

		this.optionTextBgBigArr = [];
		for (let i=0; i<4; i++) {
		
			const textOption = this.getOneTextOption(true);
			this.canvas.addChild(textOption);
			textOption.scale = this._mapScaleMin;
			textOption.x = baseX;
			textOption.y = baseY - i * disH;
			this.optionTextBgBigArr.push(textOption);
		}
	},

	getOneAudioOption(isBig=false) {

		let lightResName = "option_pic_bg_l";
		let bgResName = "option_pic_bg";
		if (isBig) {
			lightResName = "op_pic_bg_big_l";
			bgResName = "op_pic_bg_big";
		}

		const audioBgNode = new cc.Node();

		const light = getSprNode(lightResName);
		audioBgNode.addChild(light);
		light.opacity = 0;
		audioBgNode.light = light;

		const picBg = getSprNode(bgResName);
		audioBgNode.addChild(picBg);
		audioBgNode.picBg = picBg;

		audioBgNode.width = picBg.width;
		audioBgNode.height = picBg.height;

		const animNode = cc.instantiate(cc.find("Canvas/res/anim/op_audio"))
		audioBgNode.addChild(animNode);
		animNode.anchorX = 0.6;


		const animTop = getSprNode('op_audio');
		audioBgNode.addChild(animTop);
		animTop.anchorX = 0.6;

		const anim = animNode.getComponent(cc.Animation);
		animNode.opacity = 0;

		audioBgNode.anim = anim;
		audioBgNode.animNode = animNode;
		audioBgNode.animTop = animTop;
		
		audioBgNode.showAnim = () => {
			this.playItemAnim(audioBgNode);
			cc.audioEngine.stop(audioBgNode.audioId);
		}
		audioBgNode.stopAnim = () => {
			cc.audioEngine.stop(audioBgNode.audioId);
			this.stopItemAnim(audioBgNode);
		}

		audioBgNode.on(cc.Node.EventType.TOUCH_START, () => {
			if( light.opacity == 0 ) {
				light.opacity = 255;
				playAudio(this.selectClip);
				
				audioBgNode.showAnim();
				if (audioBgNode.audioClip) {
					audioBgNode.audioId = playAudio(audioBgNode.audioClip, () => {
						this.stopItemAnim(audioBgNode);
					});
				}

			} else {
				light.opacity = 0;
				audioBgNode.stopAnim();
			}

			this.refreshCheckBtn();

		});

		audioBgNode.active = false;

		return audioBgNode;
	},

	getOneTextOption(isBig=false) {

		let lightResName = "option_text_bg_l";
		let bgResName = "option_text_bg";
		if (isBig) {
			lightResName = "op_text_bg_big_l";
			bgResName = "op_text_bg_big";
		}

		const textBgParent = new cc.Node();
		textBgParent.active = false;

		const light = getSprNode(lightResName);
		textBgParent.addChild(light);
		light.opacity = 0;
		textBgParent.light = light;

		const textBg = getSprNode(bgResName);
		textBgParent.addChild(textBg);
		textBgParent.textBg = textBg;

		textBgParent.width = textBg.width;
		textBgParent.height = textBg.height;

		const labelNode = new cc.Node();
		labelNode.parent = textBgParent;
		const label = labelNode.addComponent(cc.Label);

		label.fontSize = 56;
		label.lineHeight = 56;
		if (isBig) {
			label.fontSize = 64;
			label.lineHeight = 64;
		}

		label.font = cc.find('Canvas/res/font/Berlin-Sans-FB').getComponent(cc.Label).font;
		textBgParent.label = label;

		const color = new cc.Color();
		cc.Color.fromHEX(color, '#023659' );
		labelNode.color = color;


		const soundNode = new cc.Node();
		textBgParent.addChild(soundNode);
		textBgParent.soundIcon = soundNode;

		const soundIconAnim = cc.instantiate(cc.find("Canvas/res/anim/laba"))
		soundNode.addChild(soundIconAnim);
		soundIconAnim.opacity = 0;

		const soundIconTop = getSprNode('btn_laba')
		soundNode.addChild(soundIconTop);
		soundIconTop.opacity = 255;

		soundNode.x = textBgParent.width / 2 - 15; // - soundIconTop.width / 2;
		soundNode.y = textBgParent.height / 2 - 15; //- soundIconTop.height / 2;
		soundNode.active = false;


		textBgParent.on(cc.Node.EventType.TOUCH_START, () => {
			if( light.opacity == 0 ) {
				light.opacity = 255;
				playAudio(this.selectClip);
			} else {
				light.opacity = 0;
			}
			this.refreshCheckBtn();
		})


		soundIconTop.addComponent(cc.BlockInputEvents);
		soundIconTop.on(cc.Node.EventType.TOUCH_START, () => {
			const anim = soundIconAnim.getComponent(cc.Animation);
			anim.play('laba');
			soundIconTop.opacity = 0;
			soundIconAnim.opacity = 255;

			if (soundNode.audioClip) {
				playAudio(soundNode.audioClip, () => {
					soundIconTop.opacity = 255;
					soundIconAnim.opacity = 0;
					anim.stop();
				});
			}
		})

		return textBgParent;
	},

	playItemAnim(item) {
		item.anim.play();
		item.animNode.opacity = 255;
		item.animTop.opacity = 0;
	},

	stopItemAnim(item) {
		item.animNode.opacity = 0;
		item.animTop.opacity = 255;
	},

	setCurQuestion() {
		
		switch(this.curQuestionData.questionType) {
			case "pic":
				this.setQuestionPic();
				break;
			case "text":
				this.setQuestionText();
				break;
			case "video":
				this.setQuestionVideo();
				break;
			case "audio":
				this.setQuestionAudio();
				break;
		}

		this.refreshCheckBtnPos();
	},

	refreshCheckBtnPos() {
		if (this.curQuestionData.questionType == 'audio') {
			this.checkBtn.x = 440 * this._mapScaleMin;
			this.checkBtn.y = -240 * this._mapScaleMin;
		} else {
			this.checkBtn.x = this.checkBtn.baseX;
			this.checkBtn.y = this.checkBtn.baseY;
		}
	},

	curQuesBg: null,
	setQuestionPic() {

		this.curQuesBg = this.quesPicBg;
		this.curQuesBg.active = true;


		if (this.quesPicBg.pic) {
			this.quesPicBg.pic.removeFromParent();
			this.quesPicBg.pic = null;
		}
		if (this.curQuestionData.pic_url) {
			getSprNodeByUrl(this.curQuestionData.pic_url, (spr) => {
				const sprNode = spr.node;
				setSprNodeMaxLen(sprNode, 678, 396);
				this.quesPicBg.addChild(sprNode)
				this.quesPicBg.pic = sprNode;
			})
		}
	
		const audioNode = this.quesPicBg.audioNode;
		audioNode.active = false;
		audioNode.audioClip = null;
		if (this.curQuestionData.audio_url) {
			cc.assetManager.loadRemote(this.curQuestionData.audio_url, (err, audioClip) => {
				audioNode.audioClip = audioClip;
			});	
			audioNode.active = true;
		}
	},

	setQuestionText() {
		this.curQuesBg = this.quesTextBg;
		this.curQuesBg.active = true;

		
		const label = this.curQuesBg.label;
		const size = 80; 
		label.string = `<size=${size}><color=#fff4b6>${this.curQuestionData.text}</color></size>`

		const maxH = this.curQuesBg.height * 0.98;

		if (label.node.height > maxH) {
			label.node.scale = maxH / label.node.height
		} else {
			label.node.scale = 1;
		}


		const audioNode = this.curQuesBg.audioNode;
		audioNode.active = false;
		audioNode.audioClip = null;
		if (this.curQuestionData.audio_url) {
			cc.assetManager.loadRemote(this.curQuestionData.audio_url, (err, audioClip) => {
				audioNode.audioClip = audioClip;
			});	
			audioNode.active = true;
		}
	},

	setQuestionVideo() {
		this.curQuesBg = this.quesVideoBg;
		this.curQuesBg.active = true;
		this.videoNode.active = true;

		if (this.curQuestionData.video_url) {
			this.curQuesBg.video.remoteURL = this.curQuestionData.video_url;
		}
	},

	setQuestionAudio() {
		this.curQuesBg = this.quesAudioBg;
		this.curQuesBg.active = true;


		this.curQuesBg.audioClip = null;
		if (this.curQuestionData.audio_url) {
			cc.assetManager.loadRemote(this.curQuestionData.audio_url, (err, audioClip) => {
				this.curQuesBg.audioClip = audioClip;
			});
		}
	},



	setCurOption() {
		const arr = this.curQuestionData.answerArr;

		const isBig = this.curQuestionData.questionType == 'audio';

		switch(this.curQuestionData.answerType) {
			case "pic":
				this.setOptionPic(arr, isBig);
				break;
			case "audio":
				this.setOptionAudio(arr, isBig);
				break;
			case "text":
				this.setOptionText(arr, isBig);
				break;
		}
		
	},



	curOptionArr: null,
	setOptionPic(arr, isBig=false) {

		let opItemArr = this.optionPicBgArr;
		if (isBig) {
			opItemArr = this.optionPicBgBigArr;
		}
		this.curOptionArr = [];
		const disW = 158 * this._mapScaleMin;
		const baseX = -(arr.length - 1) * disW;
		for (let i=0; i<arr.length; i++) {
			
			opItemArr[i].active = true;
			if (!isBig) {
				opItemArr[i].x = baseX + i * disW * 2;
			}

			const picBg = opItemArr[i].picBg;
			picBg.removeAllChildren();
			
			const data = arr[i];
			if (data.pic_url) {
				getSprNodeByUrl, getSprNodeByUrl(data.pic_url, (spr) => {
					let maxW = 280;
					let maxH = 190;
					if (isBig) {
						maxW = 366;
						maxH = 248;
					}

					setSprNodeMaxLen(spr.node, maxW, maxH);
					console.log('spr: ', spr);
					picBg.addChild(spr.node);
				})
			}

			const soundIcon = opItemArr[i].soundIcon;
			soundIcon.active = false;
			soundIcon.audioClip = null;
			opItemArr[i].audioClip = null;
			if (data.audio_url) {
				cc.assetManager.loadRemote(data.audio_url, (err, audioClip) => {
					soundIcon.audioClip = audioClip;
					opItemArr[i].audioClip = audioClip;
				});
				
				soundIcon.active = true;
			}

			opItemArr[i].data = data;
			this.curOptionArr.push(opItemArr[i]);
		}
	},


	setOptionAudio(arr, isBig=false) {

		let opItemArr = this.optionAudioBgArr;
		if (isBig) {
			opItemArr = this.optionAudioBgBigArr;
		}

		this.curOptionArr = [];
		const disW = 158 * this._mapScaleMin;
		const baseX = -(arr.length - 1) * disW;
		for (let i=0; i<arr.length; i++) {
			
			opItemArr[i].active = true;
			if(!isBig) {
				opItemArr[i].x = baseX + i * disW * 2;
			}

			const data = arr[i];

			opItemArr[i].audioClip = null;
			if (data.audio_url) {
				cc.assetManager.loadRemote(data.audio_url, (err, audioClip) => {
					opItemArr[i].audioClip = audioClip;
				});
			}

			opItemArr[i].data = data;
			this.curOptionArr.push(opItemArr[i]);
		}
	},

	setOptionAudioBig(arr) {
		this.curOptionArr = [];
		for (let i=0; i<arr.length; i++) {
			
			this.optionAudioBgArr[i].active = true;

			const data = arr[i];

			this.optionAudioBgArr[i].audioClip = null;
			if (data.audio_url) {
				cc.assetManager.loadRemote(data.audio_url, (err, audioClip) => {
					this.optionAudioBgArr[i].audioClip = audioClip;
				});
			}

			this.optionAudioBgArr[i].data = data;
			this.curOptionArr.push(this.optionAudioBgArr[i]);
		}
	},


	setOptionText(options, isBig=false) {

		console.log(' in setOptionText, isBig: ', isBig);

		let opItemArr = this.optionTextBgArr;
		if (isBig) {
			opItemArr = this.optionTextBgBigArr
		}

		this.curOptionArr = [];
		const disW = 315 * this._mapScaleMin;
		const disH = 120 * this._mapScaleMin;
		const baseX = - disW ;
		let baseY = -235 * this._mapScaleMin;
		if (options.length > 2) {
			baseY = -170 * this._mapScaleMin;
		}
		let count = 0;
		for (let i=0; i<options.length; i++) {

			if ( i == 2 ) {
				baseY -= disH;
				count = 0;
			}
			
			opItemArr[i].active = true;
			if (!isBig) {
				opItemArr[i].x = baseX + count * disW * 2;
				opItemArr[i].y = baseY;
			}
		
			const data = options[i];

			opItemArr[i].label.string = data.text;
			opItemArr[i].label["_forceUpdateRenderData"](true);
			if (opItemArr[i].label.node.width > opItemArr[i].width * 0.9) {
				opItemArr[i].label.node.scale = opItemArr[i].width * 0.9 / opItemArr[i].label.node.width;
			} else {
				opItemArr[i].label.node.scale = 1;
			}
			

			const soundIcon = opItemArr[i].soundIcon;
			soundIcon.active = false;
			soundIcon.audioClip = null;
			opItemArr[i].audioClip = null;
			if (data.audio_url) {
				cc.assetManager.loadRemote(data.audio_url, (err, audioClip) => {
					soundIcon.audioClip = audioClip;
					opItemArr[i].audioClip = audioClip;
				});
				
				soundIcon.active = true;
			}

			opItemArr[i].data = data;
			this.curOptionArr.push(opItemArr[i]);

			count++;
		}
	},



	shakeArr: null,
	wrongArr: null,
	checkBtnClick() {

		this.shakeArr = [];
		this.wrongArr = [];
		this.checkItemWrong();

		if (this.wrongArr.length > 0) {
			//有选错的
			this.itemShake();
			this.hideLight();
			playAudio(this.wrongClip);
			return;
		}

		const isRightAll = this.checkItemRightCount();
		if (!isRightAll) {
			// 有漏选的
			this.itemShake();
			this.hideLight();
			playAudio(this.wrongClip);
			return;
		}

		this.showAllRight();
		this.showMask();

		playAudio(this.rightClip, () => {
			this.playAnswerAudio(0);
		})
		
	},

	playAnswerAudio(index) {
		const arr = this.curOptionArr;
		if (!arr[index]) {

			// delayCall(0.5, () => {
				this.changeNextQuestion();
			// })

		} else {
			if ( arr[index].light.opacity > 254 && arr[index].audioClip ) {
				playAudio(arr[index].audioClip, () => {
					this.playAnswerAudio(index + 1);
				})
			} else {
				this.playAnswerAudio(index + 1);
			}
		}
	},


	checkItemWrong() {
		const arr = this.curOptionArr;
		console.log('arr: ', arr);
		for (let i=0; i<arr.length; i++) {
			const itemBg = arr[i];
			if (itemBg.light.opacity >= 254) {
				this.shakeArr.push(itemBg);
				console.log('aaa', itemBg.data);;
				if (itemBg.data.answerRight == '0') {
					this.wrongArr.push(itemBg);
				}
			}
		}
	},

	checkItemRightCount() {
		let rightTotalCount = 0;
		const answerArr = this.curQuestionData.answerArr;
		for (let i=0; i<answerArr.length; i++) {
			if (answerArr[i].answerRight == '1') {
				rightTotalCount ++;
			}
		}

		let curRightCount = 0;
		const curOptionArr = this.curOptionArr;
		for (let i=0; i<curOptionArr.length; i++) {
			if (curOptionArr[i].light.opacity > 254) {
				curRightCount ++;
			}
		}

		return rightTotalCount == curRightCount;
	},

	itemShake() {
		let rate = 1;
		if (this.curQuestionData.answerType == 'text') {
			rate = 0.5;
		}

		const arr = this.shakeArr;
		for (let i=0; i<arr.length; i++) {
			this.rotateShake(arr[i], rate);
			if (arr[i].stopAnim) {
				arr[i].stopAnim();
			}
		}

		this.showTryAgain();
	},

	hideLight() {
		const arr = this.curOptionArr;
		for (let i=0; i<arr.length; i++) {
			arr[i].light.opacity = 0;
		}
		this.checkBtn.opacity = 0;
	},

	rotateShake(item, rate = 1) {

		const time = 0.9;
		cc.tween(item)
			.to(time / 6 / 2, {angle: -20 * rate}, {easing: 'sineInOut'})
			.to(time / 6, {angle: 12 * rate}, {easing: 'sineInOut'})
			.to(time / 6, {angle: -7 * rate}, {easing: 'sineInOut'})
			.to(time / 6, {angle: 4 * rate}, {easing: 'sineInOut'})
			.to(time / 6, {angle: -2 * rate}, {easing: 'sineInOut'})
			.to(time / 6, {angle: 1 * rate}, {easing: 'sineInOut'})
			.to(time / 6, {angle: 0 * rate}, {easing: 'sineInOut'})
			.start();

	},

	showAllRight() {
		const curOptionArr = this.curOptionArr;
		for (let i=0; i<curOptionArr.length; i++) {
			if (curOptionArr[i].light.opacity > 254) {
				this.addIconRight(curOptionArr[i]);
			}
		}
	},

	changeNextQuestion() {
		console.log(' in changeNextQuestion')

		this.curQuestionIndex ++ ;
		this.setCurQuestionData();

		if (!this.curQuestionData) {
			// this.gameEnd();
			return;
		}

		this.showChangeQuesAnim();
	
	},

	showChangeQuesAnim() {
		this.hideLight();

		this.hideCurOptionAnim(() => {
			this.setCurOption();
			this.showCurOptionAnim();
			this.hideMask();
		});

		this.hideCurQuestion(() => {
			this.setCurQuestion();
			this.showCurQuestionAnim();
		});
	},


	maskLayer: null,
	initMask() {
		const maskLayer = new cc.Node();
		maskLayer.width = this.canvas.width;
		maskLayer.height = this.canvas.height;
		this.canvas.addChild(maskLayer, 20);

		maskLayer.addComponent(cc.BlockInputEvents);
		this.maskLayer = maskLayer;
		this.maskLayer.active = false;
	},

	showMask() {
		this.maskLayer.active = true;
	},

	hideMask() {
		this.maskLayer.active = false;
	},

	hideCurOptionAnim(cb) {
		const arr = this.curOptionArr;
		const time = 0.5;
		for (let i=0; i<arr.length; i++) {
			if (arr[i].iconRight) {
				arr[i].iconRight.removeFromParent();
				arr[i].iconRight = null;
			}
			cc.tween(arr[i])
				.to(time, {opacity: 0}, {easing: "cubicOut"})
				.call(() => {
					arr[i].active = false;
				})
				.start();
		}
		delayCall(time, () => {
			cb();
		})
	},

	showCurOptionAnim(cb=null) {
		const arr = this.curOptionArr;
		const time = 0.5;
		for (let i=0; i<arr.length; i++) {
			arr[i].opacity = 0;
			cc.tween(arr[i])
				.to(time, {opacity: 255}, {easing: "cubicIn"})
				.start();
		}

		if (cb) {
			delayCall(time, () => {
				cb();
			})
		}
	
	},

	hideCurQuestion(cb) {
		const time = 0.5;
		cc.tween(this.curQuesBg)
			.to(time, {opacity: 0}, {easing: "cubicOut"})
			.call(() => {
				this.curQuesBg.active = false;
				cb();
			})
			.start();
	},

	showCurQuestionAnim() {

		this.curQuesBg.active = true;
		this.curQuesBg.opacity = 0;

		const time = 0.5;
		cc.tween(this.curQuesBg)
			.to(time, {opacity: 255}, {easing: "cubicIn"})
			.start();
	},


	changeStep() {

		this.typeArrIndex ++;
		
		if (!this.data.change_step_audio_url) {
			this.startTesting();
			return;
		}
		playAudioByUrl(this.data.change_step_audio_url, () => {
			this.startTesting();
		})

	},


	showAllWordSound() {
		console.log(' in showAllWordSound')
		for (let i=0; i<this.wordBgArr.length; i++) {
			const {wordSoundBtn} = this.wordBgArr[i];

			this.appearAnim(wordSoundBtn);
		}
	},

	gameEnd() {
		console.log('game end !')

		this.isGameEnd = true;

		this.showResultLayer();
		// this.endTesting();


		// playAudioByUrl(this.data.finish_right_audio_url, () => {
		// delayCall(0.5, () => {


		// 	// onHomeworkFinish({});
		// 	this.endTesting();
		// })
		return;
		


		if (this.typeArrIndex < this.typeArr.length - 1) {

			this.changeStep();

			return;
		}





		// this.showRestart();
		// this.showGoodjob();
		// this.showOneFirework(cc.v2(0, -this.canvas.height / 2), this.canvas, cc.find('paperBase').children, this.canvas.width / 2.5, this.canvas.height * 2, 100, 1);
		playAudio(this.finishClip);


		const camera = cc.find('Canvas/Main Camera');
		camera.zIndex = 100;

		showTrebleFirework(camera, cc.find('RibbonNodeBase').children);


		const endData = this.getEndData();
		delayCall(2,( ) => {
			onHomeworkFinish(endData);

			// const nextBtn = cc.find('middleLayer/BtnRight');
			// if (nextBtn) {
			// 	nextBtn.active = true;
			// }
		})

	},

	getEndData() {

		return {};

		const arr = this.picNodeArr;
		const customData = [];
		let stone = 0;
		const oneQuesStone = 10 / arr.length;
		arr.forEach(node => {
			customData.push({isRight: node.isRight})
			if (node.isRight) {
				stone += oneQuesStone;
			}
		})
		stone = Math.round(stone * 10) / 10;
		return {customData, stone};
	},

	showGoodjob() {

		const icon = getSprNode("goodjob");
		icon.scale = this._mapScaleMin;
		icon.baseS = icon.scale;
		this.canvas.addChild(icon, 20);


		const time = 1;
		icon.scale = 0;
		cc.tween(icon)
			.to(0.8,  {scale: icon.baseS}, {easing: "elasticOut"})
			.delay(1)
			.to(0.5, {scale: 0} , {easing: "cubicIn"})

			.start();



	},

	showRestart() {

		const btn = getSprNode("btn_restart");
		btn.scale = this._mapScaleMin;
		btn.baseS = btn.scale;
		this.canvas.addChild(btn, 21);

		btn.on(cc.Node.EventType.TOUCH_START, () => {
			// btn.removeFromParent();
			// this.initData();
			// this.initStar();
			// this.showChangeQuesAnim();
			// playAudio(this.btnClip);

			const middleLayer = cc.find('middleLayer');
			if (middleLayer) {
				middleLayer.getComponent('middleLayer').reloadBundle();
			}
		})

		const time = 0.9;
		btn.scale = 0;
		cc.tween(btn)
			.delay(2.5)
			.to(time,  {scale: btn.baseS}, {easing: "elasticOut"})
			.start();

	},



	async showOneFirework(pos, parentNode, nodeList, w, h, n, timeRate=1) {

		for (let i = 0; i < 3; i++) {
				this.showFirework(pos, parentNode, nodeList, w, h, n, timeRate);
				await asyncDelay(0.1);
		}
	},

	showFirework(pos, parentNode, nodeList, width = 200, height = 500, number = 30, timeRate=1) {
			const subTime = 1;
			for (let i = 0; i < number; i++) {
					const quad = this.createQuads(pos, parentNode, nodeList);
					const targetX = RandomInt(width / 2, -width / 2);
					const targetY = RandomInt(height);

					cc.tween(quad)
							.by(0.5 * timeRate, { x: targetX })
							.by((2 + subTime *  Math.random()) * timeRate, { x: targetX * 2 })
							.start();

					cc.tween(quad)
							.by(0.5 * timeRate, { y: targetY }, { easing: 'quadOut' })
							.to((3 + subTime * Math.random()) * timeRate, { y: -parentNode.height * 2 }, { easing: 'quadIn' })
							.removeSelf()
							.start();

					cc.tween(quad)
							.delay(1  * timeRate)
							.to((0.5 + subTime * Math.random()) * timeRate , { opacity: 0 })
							.start();
			}
	},

	createQuads(pos, parentNode, nodeList) {
			const quadBase = cc.instantiate(nodeList[RandomInt(nodeList.length)]);

			quadBase.x = pos.x;
			quadBase.y = pos.y;
			quadBase.z = pos.z;
			quadBase.angle = RandomInt(180);
			quadBase.parent = parentNode;

			const quad = quadBase.getChildByName('quad');
			quad.x = 0;
			quad.y = 0;
			quad.angle = RandomInt(180);

			const paper = quad.getChildByName('paper');
			paper.scaleX = Math.random() * 0.8 + 0.2;
			paper.scaleY = Math.random() * 0.8 + 0.2;

			quadBase.scaleX = Math.random();
			cc.tween(quadBase)
					.to((1 - quadBase.scaleX) * 0.3, { scaleX: 1 })
					.call(() => {
							const time = Math.random() * 0.2;
							cc.tween(quadBase)
									.to(0.1 + time, { scaleX: -1 })
									.to(0.1 + time, { scaleX: 1 })
									.union()
									.repeatForever()
									.start();
					})
					.start();


			return quadBase;
	},


















	restart() {
		
	},


	initTitle() {

		const offX = 96;
		const offY = 11;
		const title = getSprNode('title_bg');
		title.parent = this.canvas;
		title.scale = this._mapScaleMin;
		title.zIndex = 10;

		title.x = -this.canvas.width / 2 + title.width / 2 * title.scale + offX;
		title.y = this.canvas.height / 2 - title.height / 2 * title.scale - offY;

		// console.log('this.data: ', this.data);

		title.addComponent(cc.Button)
		title.on('click', () => {
			if (this.data.title_audio_url) {
				playAudioByUrl(this.data.title_audio_url);
			}
		})

		const labelNode = new cc.Node();
		labelNode.parent = title;
		const label = labelNode.addComponent(cc.RichText);
		const size = 42
		label.font = cc.find('Canvas/res/font/aharoni').getComponent(cc.Label).font;
		label.string = `<outline color=#a83c13 width=2><size=${size}><color=#ffffff>${this.data.title || " " }</color></size></outline>`
		// label.string = `<size=${size}><color=#751e00>${this.curGroup.title }</color></size>`
		label.lineHeight = size;
		label.horizontalAlign = cc.macro.TextAlignment.LEFT
		labelNode.anchorX = 0;
		labelNode.anchorY = 1
		labelNode.x = -title.width / 2 + 90;

		const maxLen = 305;
		if (labelNode.width > maxLen) {
			labelNode.scale = maxLen / labelNode.width;
		}

		labelNode.y = labelNode.height / 2 * labelNode.scale + 15;

	},


	

	initVerticalBg() {


		const bgY = getSprNode("bg_y_2");
		this.bgLayer.addChild(bgY);
		bgY.scale = this.getVerticalMaxScale(bgY);

		// const bgW = getSprNode("bg_w_2");
		// this.canvas.addChild(bgW);
		// bgW.scale = this.getVerticalMinScale(bgW) * 0.9; 

		// bgW.y = -30 * bgW.scale;


		const topRectSize = {
			width: 1080,
			height: 174
		}

		const tempS = this.canvas.width / topRectSize.width;
		this.topH = topRectSize.height * tempS;

		const backBtn = getSprNode("btn_back");
		this.bgLayer.addChild(backBtn);
		backBtn.scale = tempS;
		backBtn.x = -this.canvas.width / 2 + this.topH / 2;
		backBtn.y = this.canvas.height / 2 - this.topH / 2;
		backBtn.addComponent(cc.Button);
		backBtn.on("click", () => {
			const middleLayer = cc.find('middleLayer');
			if (middleLayer) {
				const middleLayerComponent = middleLayer.getComponent('middleLayer');
				middleLayerComponent.showMenuTemplate();
				
			} 
		});


		const changeDirBtn = getSprNode("btn_flip_v");
		this.bgLayer.addChild(changeDirBtn);
		changeDirBtn.scale = tempS;
		changeDirBtn.x = this.canvas.width / 2 - this.topH / 2;
		changeDirBtn.y = this.canvas.height / 2 - this.topH / 2;
		changeDirBtn.addComponent(cc.Button);
		changeDirBtn.on("click", () => {
			const middleLayer = cc.find('middleLayer');
			if (middleLayer) {
				const middleLayerComponent = middleLayer.getComponent('middleLayer');
				middleLayerComponent.setTemplateIsVertical("hw_dictation", !this.isVertical);
				middleLayerComponent.reloadBundle();
			} 
		});


		if (cc.sys.isNative && cc.sys.os == cc.sys.OS_IOS) {
			// changeDirBtn.active = false;
		}



		const itemW = 1035;
		const svBgNode = new cc.Node();
		svBgNode.width = itemW / 1080 * this.canvas.width;
		svBgNode.height = this.canvas.height - this.topH;
		svBgNode.y = - this.topH / 2;
		this.bgLayer.addChild(svBgNode);

		// const ctx = svBgNode.addComponent(cc.Graphics);
		// ctx.fillColor = cc.Color.RED;
		// ctx.rect(-svBgNode.width / 2, -svBgNode.height / 2, svBgNode.width, svBgNode.height);
		// ctx.fill();

		console.log('svBgNode: ', svBgNode.width);
		console.log('this.canvas: ', this.canvas.width);
		console.log('this.canvas: ', this.canvas.height);

		this.bg = svBgNode;
	},

	getVerticalMinScale(node) {
		const sx = this.canvas.width / node.width;
		const sy = this.canvas.height / node.height;
		return Math.min(sx,sy);
	},

	getVerticalMaxScale(node) {
		const sx = this.canvas.width / node.width;
		const sy = this.canvas.height / node.height;
		return Math.max(sx,sy);
	},


	initHotZone() {
		this.initHotZoneBg();
	},


	hotZoneBg: null,
	initHotZoneBg() {
		this.hotZoneBg = new cc.Node();

		this.hotZoneBg.name = 'hotZoneBg';
		this.hotZoneBg.parent = cc.find('Canvas');
		this.hotZoneBg.zIndex = 4;

		if (!this.data.bgItem) {
			return;
		}

		cc.loader.load({url: this.data.bgItem.url}, (err, img) => {

			// this.addMask(this.hotZoneBg);

			this.hotZoneBg.width = img.width;
			this.hotZoneBg.height = img.height;



			const sprNode = new cc.Node();
			sprNode.name = 'bgItemSpr'
			var sf = new cc.SpriteFrame(img);
			// const spr = this.hotZoneBg.addComponent(cc.Sprite);
			const spr = sprNode.addComponent(cc.Sprite);
			spr.spriteFrame = sf
			sprNode.width = this.hotZoneBg.width;
			sprNode.height = this.hotZoneBg.height;
			sprNode.parent = this.hotZoneBg;
			window['bg'] =sprNode 


			const sx = this.canvas.width / this.hotZoneBg.width;
			const sy = (this.canvas.height) / this.hotZoneBg.height;
			const s = Math.min(sx, sy);
			this.hotZoneBg.scale = s;

			// this.data.bgItem.isShowDebugLine = true;
			this.initHotZoneItem();
			// this.initFingerQuesData();
		
			this.initQuesArr();
			this.initCurQues();

			this.hzLoadEnd = true;
			// this.checkStart();


	
		});

	},

	initHotZoneItem() {

		this.picNodeArr = [];

		this.data.hotZoneItemArr.forEach((item) => {
			console.log('item.gIdx: ', item.gIdx);
			switch (item.gIdx) {

				case "0":
					this.setOneText(item);
					break;

				case "1":
					this.setOneWriteAnima(item);
					break;

				// case "2":
				// 	this.setOneCircleAnima(item);
				// 	break;

				// case "4":
				// 	this.setOneSignAnima(item);
				// 	break;

				// case "5":
				// 	this.setOneFingerAnima(item);
				// 	break;
				// case "0":
				// 	this.setOneHotZonePic(item);
				// 	break;
						
				default:
					break;
			}

		});

	},

	setOneLinkRect(data) {
		const rate = (this.hotZoneBg.scale * this.hotZoneBg.width) / this.data.bgItem.rect.width;

		const rectNode = new cc.Node();
		rectNode.name = 'rect' + data.index;
		this.hotZoneBg.addChild(rectNode);

		const ctx = rectNode.addComponent(cc.Graphics);
		// 红色矩形
		ctx.lineWidth = 4;
		ctx.strokeColor = cc.Color.BLACK;
		ctx.fillColor = cc.Color.WHITE.setA(100);

		const scale = rate / this.hotZoneBg.scaleY;

		rectNode.width = data.rect.width * scale;
		rectNode.height = data.rect.height * scale;
		rectNode.x = -this.hotZoneBg.width / 2 + data.rect.x * scale;
		rectNode.y = this.hotZoneBg.height / 2 - data.rect.height * scale - data.rect.y * scale;
		// rectNode.scale = 1 / data.mapScale;

		rectNode.anchorX = rectNode.anchorY = 0;


		if (this.data.isDebug) {
			ctx.rect(0, 0, rectNode.width, rectNode.height);
		}
		ctx.stroke();
		ctx.fill();

		rectNode.data = data;

		console.log(" data is ~~~ : ", data);

		this.rectNodeArr.push(rectNode)


		const debugItemId = data.pointItem;
		const debugItemData = this.data.hotZoneItemArr2[Number(debugItemId) - 1];
		rectNode.isRightPoint = debugItemData.checkbox.list[0].value == true;

		console.log('debugItemData.checkbox.list[0].value: ', debugItemData.checkbox.list[0].value);

	},


	addMask(node) {
		const mask = node.addComponent(cc.Mask);
		mask.type = cc.Mask.Type.RECT;
	},


	setOneDragAction(data) {

		const rate =  (this.hotZoneBg.scale * this.hotZoneBg.width) / this.data.bgItem.rect.width;
		const rectNode = new cc.Node();
		rectNode.name = 'rect' + data.index;
		this.hotZoneBg.addChild(rectNode);

		const ctx = rectNode.addComponent(cc.Graphics);
		// 红色矩形
		ctx.lineWidth = 4;
		ctx.strokeColor = cc.Color.BLACK;
		ctx.fillColor = cc.Color.WHITE.setA(100);

		const scale = rate / this.hotZoneBg.scaleY ;

		rectNode.width = data.rect.width * scale;
		rectNode.height = data.rect.height * scale;
		rectNode.x = -this.hotZoneBg.width / 2 + data.rect.x * scale;
		rectNode.y = this.hotZoneBg.height / 2 - data.rect.height * scale - data.rect.y * scale;
		const {x, y, width, height} = rectNode;
		// rectNode.anchorX = rectNode.anchorY = 0;

		if (this.data.bgItem.isShowDebugLine) {
			ctx.rect(-rectNode.width / 2, -rectNode.height / 2, rectNode.width, rectNode.height);
		}
		ctx.stroke();
		ctx.fill();
		rectNode.x += rectNode.width / 2;
		rectNode.y += rectNode.height / 2;

		rectNode.baseX = rectNode.x;
		rectNode.baseY = rectNode.y;
		rectNode.targetOff();

		rectNode.on(cc.Node.EventType.TOUCH_START, () => {

			if (rectNode.isDragEnd) {
				if (rectNode.audioClip) {
					cc.audioEngine.stopAllEffects();
					cc.audioEngine.playEffect(rectNode.audioClip, false, 0.8);
				}
				return;
			}
			this._curShowItem = rectNode;
		})
		

		const realRate = this.hotZoneBg.width / this.data.bgItem.rect.width;
		rectNode.targetPx = -this.hotZoneBg.width / 2 + ( data.dragDot.x - this.data.bgItem.rect.x ) * realRate;
		rectNode.targetPy = this.hotZoneBg.height / 2 - (data.dragDot.y - this.data.bgItem.rect.y) * realRate;


		if (data.audio_url) {
			cc.assetManager.loadRemote(data.audio_url, (err, audioClip) => {
				rectNode.audioClip = audioClip;
			});
		}



		console.log('setOneAction ~~ data: ', data)
		const actionData = data['actionData_' + data.gIdx];
		if (!actionData) {
			return;
		}
		if (actionData.type == 'text') {
			const label = this.setOneActionText(rectNode, actionData);
			label.node.scale = scale * data.fontScale;

			label.node.targetOff();
		
	

			// label.overflow = cc.Label.Overflow.NONE;
			// label.node.setContentSize(new cc.Size(0, lineHeight));
			label["_forceUpdateRenderData"](true);
		
			
		} else if (actionData.type == 'pic') {

			const pic = this.setOneActionPic(rectNode, actionData);

		} else if (actionData.type == 'anima') {

			const anima = this.setOneActionAnima(rectNode, actionData);
		}
	},



	setOneAction(data) {

		const rate =  (this.hotZoneBg.scale * this.hotZoneBg.width) / this.data.bgItem.rect.width;
		const rectNode = new cc.Node();
		rectNode.name = 'rect' + data.index;
		this.hotZoneBg.addChild(rectNode);

		const ctx = rectNode.addComponent(cc.Graphics);
		// 红色矩形
		ctx.lineWidth = 4;
		ctx.strokeColor = cc.Color.BLACK;
		ctx.fillColor = cc.Color.WHITE.setA(100);

		const scale = rate / this.hotZoneBg.scaleY ;

		rectNode.width = data.rect.width * scale;
		rectNode.height = data.rect.height * scale;
		rectNode.x = -this.hotZoneBg.width / 2 + data.rect.x * scale;
		rectNode.y = this.hotZoneBg.height / 2 - data.rect.height * scale - data.rect.y * scale;
		const {x, y, width, height} = rectNode;
		rectNode.anchorX = rectNode.anchorY = 0;

		if (this.data.bgItem.isShowDebugLine) {
			ctx.rect(0, 0, rectNode.width, rectNode.height);
		}
		ctx.stroke();
		ctx.fill();



		console.log('setOneAction ~~ data: ', data)
		const actionData = data['actionData_' + data.gIdx];
		if (!actionData) {
			return;
		}
		if (actionData.type == 'text') {
			const label = this.setOneActionText(rectNode, actionData);
			label.node.scale = scale * data.fontScale;

			// label.overflow = cc.Label.Overflow.NONE;
			// label.node.setContentSize(new cc.Size(0, lineHeight));
			label["_forceUpdateRenderData"](true);
		
			
		} else if (actionData.type == 'pic') {

			const pic = this.setOneActionPic(rectNode, actionData);

		} else if (actionData.type == 'anima') {

			const anima = this.setOneActionAnima(rectNode, actionData);
		}
	},

	setOneActionText(rectNode, actionData) {


		const labelNode = new cc.Node();
		labelNode.parent = rectNode;
		const label = labelNode.addComponent(cc.Label);

		label.font = cc.find('Canvas/res/font/ahronbd-1').getComponent(cc.Label).font;
		label.string = actionData.text;
		// label.string = `<size=${size}><color=#751e00>${this.curGroup.title }</color></size>`
		// label.lineHeight = size;
		// label.horizontalAlign = cc.macro.TextAlignment.LEFT
		// labelNode.anchorX = 0;
		// labelNode.anchorY = 1
		labelNode.color = cc.Color.BLACK;


		const opArr = actionData.changeOption
		// console.log('opArr', opArr);


		const tweenArr = [];

		for (let i = 0; i < opArr.length; i++ ) {

			const opData = opArr[i];
			console.log('opArr[0]', opArr[i])
			if (opData[0] == 'fontColor') {
				const color = new cc.Color();
				cc.Color.fromHEX(color, opData[1] );
				labelNode.color = color;

			} else if (opData[0] == 'opacity') {
				// console.log('opData: ', opData)
				labelNode.opacity = Number( opData[1] / 100 * 255 ) + 0.1;
				// console.log(labelNode.opacity);
				tweenArr.push({item: labelNode , option: `{"${opData[0]}" : ${opData[2] / 100 * 255}}`, optionName: opData[0]},)

			} else {
				label[opData[0]] = opData[1];
				tweenArr.push({item: label, option: `{"${opData[0]}" : ${opData[2]}}`, optionName: opData[0]})

			}
		}


		// if (actionData.audio_url) {
		// 	cc.assetManager.loadRemote(actionData.audio_url, (err, audioClip) => {
		// 		labelNode.audioClip = audioClip;
		// 	});
		// }


		label.lineHeight = label.fontSize;

		// labelNode.y += rectNode.height / 2;
		// labelNode.x += rectNode.width / 2;
		

		// rectNode.addComponent(cc.Button);
		// rectNode.on('click', () => {

		// 	if (labelNode.audioClip) {
		// 		cc.audioEngine.stopAllEffects();
		// 		cc.audioEngine.playEffect(labelNode.audioClip, false, 0.8);
		// 	}

		// 	if (labelNode.isClicked) {
		// 		// return;
		// 	}
		// 	labelNode.isClicked = true;

		// 	for (let i=0; i<tweenArr.length; i++) {
		// 		const tweenData = tweenArr[i];

		// 		if (tweenData.optionName == 'opacity') {
		// 			console.log('~~~ ',  tweenData.item[tweenData.optionName] );

		// 			cc.tween(tweenData.item)
		// 				.to(actionData.changeTime,  JSON.parse(tweenData.option) )
		// 				.start();
		// 		}
				

		// 	}

		// });


		return label;
	},

	setOneActionPic(rectNode, actionData) {

		console.log('setOneActionPic actionData: ', actionData)
		const picNode = new cc.Node();
		rectNode.addChild(picNode);

		cc.loader.load({url: actionData.pic_url}, (err, img) => {

			const spr = picNode.addComponent(cc.Sprite);
			spr.spriteFrame = new cc.SpriteFrame(img)

			picNode.y += rectNode.height / 2;
			picNode.x += rectNode.width / 2;

			picNode.scaleX = rectNode.width / picNode.width;
			picNode.scaleY = rectNode.height / picNode.height;

			const opArr = actionData.changeOption	
			const tweenArr = [];
	
			for (let i = 0; i < opArr.length; i++ ) {
	
				const opData = opArr[i];
				console.log('opData: ~~~ ', opData);

				if (opData[0] == 'opacity') {
					picNode.opacity = Number( opData[1] / 100 * 255 ) + 0.1;
					console.log(picNode.opacity);
					tweenArr.push({item: picNode , option: `{"${opData[0]}" : ${opData[2] / 100 * 255}}`, optionName: opData[0]},)
	
				}  else {
					// picNode[opData[0]] = Number(opData[1]);
					// tweenArr.push({item: picNode, option: `{"${opData[0]}" : ${opData[2]}}`, optionName: opData[0]})
				}

	
				if (actionData.audio_url) {
					cc.assetManager.loadRemote(actionData.audio_url, (err, audioClip) => {
						rectNode.audioClip = audioClip;
					});
				}
				

				rectNode.addComponent(cc.Button);
				rectNode.on('click', () => {

					if (rectNode.audioClip) {
						cc.audioEngine.stopAllEffects();
						cc.audioEngine.playEffect(rectNode.audioClip, false, 0.8);
					}
		
					if (rectNode.isClicked) {
						// return;
					}
					rectNode.isClicked = true;

					for (let i=0; i<tweenArr.length; i++) {
						const tweenData = tweenArr[i];
		
						if (tweenData.optionName == 'opacity') {
							cc.tween(tweenData.item)
								.to(actionData.changeTime,  JSON.parse(tweenData.option) )
								.start();
						}
					}
		
				});
			}

		});
	},

	setOneActionAnima(rectNode, actionData) {


		const animaNode = new cc.Node();
		rectNode.addChild(animaNode);

		if (actionData.audio_url) {
			cc.assetManager.loadRemote(actionData.audio_url, (err, audioClip) => {
				rectNode.audioClip = audioClip;
			});
		}

		const data = actionData;

		const dragonDisplay = animaNode.addComponent(dragonBones.ArmatureDisplay);
		if (!data.texPngData) {
			return
		}



		const image = data.texPngData.url//"http://staging-teach.cdn.ireadabc.com/5a0c5af3e952acd0ac83a6e5c6f03ff1.png";
		const ske = data.skeJsonData.url//"http://staging-teach.cdn.ireadabc.com/bd825dcceea298d1146be8067ae3d17f.json";
		const atlas = data.texJsonData.url//"http://staging-teach.cdn.ireadabc.com/246f8991b729fa3e5a7f4802de828efa.json";
		cc.loader.load(image, (error, texture) => {

			cc.loader.load({url: atlas, type: 'txt'}, (error, atlasJson) => {

				cc.loader.load({url: ske, type: 'txt'}, (error, dragonBonesJson) => {

					const atlas = new dragonBones.DragonBonesAtlasAsset();
					atlas.atlasJson = atlasJson;
					atlas.texture = texture;

					const asset = new dragonBones.DragonBonesAsset();
					asset.dragonBonesJson = dragonBonesJson;

					dragonDisplay.dragonAtlasAsset = atlas;
					dragonDisplay.dragonAsset = asset;


					let json = JSON.parse(asset.dragonBonesJson);
					let armatures = json["armature"];
					let armatureNames = [];
					for (let i = 0; i < armatures.length; i++) {
						armatureNames.push(armatures[i].name);
					}
					// console.log('armatureNames: ', armatureNames);

					let animationNames = [];

					if (armatureNames.length > 0) {
						let defaultArmatureName = armatureNames[0];
						dragonDisplay.armatureName = defaultArmatureName;
						// let animationNames = dragonDisplay.getAnimationNames(defaultArmatureName);
						let defaultArmature = armatures[0];
						let animations = defaultArmature.animation;
						for (let i = 0; i < animations.length; i++) {
							animationNames.push(animations[i].name);
						}

						// rectNode.addComponent(cc.Button);
						// rectNode.on('click', () => {
						// 	if (rectNode.isClicked) {
						// 		// return;
						// 	}
						// 	rectNode.isClicked = true;
						// 	console.log('clicked');

						// 	if (rectNode.audioClip) {
						// 		cc.audioEngine.stopAllEffects();
						// 		cc.director.emit('STOP_ALL_AUDIO')
						// 		cc.audioEngine.playEffect(rectNode.audioClip, false, 0.8);
						// 	}

						// 	if (animationNames.length > 0) {
						// 		dragonDisplay.playAnimation(animationNames[0], 1);
						// 	}
						// });
					}


					// animaNode.x = rectNode.x + rectNode.width / 2;
					// animaNode.y = rectNode.y + rectNode.height / 2;

					// const sx = rectNode.width / animaNode.width;
					// const sy = rectNode.height / animaNode.height;
					// const scale = Math.min(sx, sy);
					// animaNode.scale = scale;
					


			


					animaNode.y += rectNode.height / 2;
					animaNode.x += rectNode.width / 2;

					animaNode.scaleX = rectNode.width / animaNode.width;
					animaNode.scaleY = rectNode.height / animaNode.height;
		
					const opArr = actionData.changeOption	
					const tweenArr = [];
			
					for (let i = 0; i < opArr.length; i++ ) {
			
						const opData = opArr[i];
						console.log('opData: ~~~ ', opData);
		
						if (opData[0] == 'opacity') {
							animaNode.opacity = Number( opData[1] / 100 * 255 ) + 0.1;
							console.log(animaNode.opacity);
							tweenArr.push({item: animaNode , option: `{"${opData[0]}" : ${opData[2] / 100 * 255}}`, optionName: opData[2] == null ? '' : opData[0]},)
			
						}  else {
							// animaNode[opData[0]] = Number(opData[1]);
							// tweenArr.push({item: animaNode, option: `{"${opData[0]}" : ${opData[2]}}`, optionName: opData[2] == null ? '' : opData[0]})
						}
		
			
						if (actionData.audio_url) {
							cc.assetManager.loadRemote(actionData.audio_url, (err, audioClip) => {
								rectNode.audioClip = audioClip;
							});
						}
						
		
						rectNode.addComponent(cc.Button);
						rectNode.on('click', () => {
		
							if (rectNode.audioClip) {
								cc.audioEngine.stopAllEffects();
								cc.audioEngine.playEffect(rectNode.audioClip, false, 0.8);
							}
				
							if (rectNode.isClicked) {
								// return;
							}
							rectNode.isClicked = true;
		
							for (let j=0; j<tweenArr.length; j++) {
								const tweenData = tweenArr[j];
				
								console.log('tweenData: ', tweenData);

								if (tweenData.optionName) {

									cc.tween(tweenData.item)
										.to(actionData.changeTime,  JSON.parse(tweenData.option))
										.start();

								}

							}
						
							if (animationNames.length > 0) {
								dragonDisplay.playAnimation(animationNames[0], 1);
							}
				
						});
					}
		
					
				});
			});
		});

	},

	setOneText(data) {


		const rectNode = this.setOneNormalRect(data);

		const labelNode = new cc.Node();
		labelNode.parent = rectNode;
		const label = labelNode.addComponent(cc.Label);

		
		label.font = cc.find('Canvas/res/font/BiaoZhunShouxieTi').getComponent(cc.Label).font;
		label.string = data.text;
		label.fontSize = 50;
		// label.string = `<size=${size}><color=#751e00>${this.curGroup.title }</color></size>`
		// label.lineHeight = size;
		// label.horizontalAlign = cc.macro.TextAlignment.LEFT
		// labelNode.anchorX = 0;
		// labelNode.anchorY = 1
		labelNode.color = cc.Color.BLACK;
		label.lineHeight = label.fontSize;

		labelNode.opacity = 0.01;
		delayCall(0.01, () => {

			const sx = rectNode.width / labelNode.width;
			const sy = rectNode.height / labelNode.height;
			const s = Math.min(sx, sy);
			labelNode.scale = s;

			labelNode.x = rectNode.width/ 2;
			labelNode.y = rectNode.height / 2;

			labelNode.opacity = 0;
		})

		labelNode.data = data;
		this.quesNodeArr.push(labelNode);


	},
	

	setOneWriteAnima(data) {



		const rectNode = this.setOneNormalRect(data);

		const labelNode = new cc.Node();
		labelNode.parent = rectNode;
		const label = labelNode.addComponent(cc.Label);

		
		label.font = cc.find('Canvas/res/font/BiaoZhunShouxieTi').getComponent(cc.Label).font;
		label.string = data.labelText;
		label.fontSize = 100//;
	
		labelNode.color = cc.Color.BLACK;
		label.lineHeight = label.fontSize;

		labelNode.opacity = 0.01;
		delayCall(0.01, () => {
			const sx = rectNode.width / labelNode.width;
			const sy = rectNode.height / labelNode.height;
			const s = Math.min(sx, sy);
			labelNode.scale = sy //s;
			
			labelNode.x = rectNode.width/ 2;
			labelNode.y = rectNode.height / 2.2;

			labelNode.opacity = 0;
		})

		// labelNode.on("touchstart", () => {
		// 	this.showLetterLabel(labelNode);
		// })

		labelNode.data = data;
		this.animaNodeArr.push(labelNode);

	},


	setOneCircleAnima(data) {

		const animaNode = this.setOneAnimaSmall(data);
		this.circleAnimaNodeArr.push(animaNode);
	},

	setOneSignAnima(data) {
		const animaNode = this.setOneAnimaSmall(data);
		this.signAnimaNodeArr.push(animaNode);
	},

	setOneFingerAnima(data) {
		console.log(' in setOneFingerAnima: ', data );
		const animaNode = this.setOneAnimaSmall(data);

		if (this.data.page_id == '20' && this.data.book_id == "Oxford_Phonics_World_1_SB") {
			animaNode.scale = 0.5;
		}

		this.fingerAnimaNodeArr.push(animaNode);
	},


	setOneAnimaSmall(data) {


		const rate = (this.hotZoneBg.scale * this.hotZoneBg.width) / this.data.bgItem.rect.width;

		const rectNode = new cc.Node();
		rectNode.name = 'rect' + data.index;
		this.hotZoneBg.addChild(rectNode);


		const ctx = rectNode.addComponent(cc.Graphics);
		// 红色矩形
		ctx.lineWidth = 4;
		ctx.strokeColor = cc.Color.BLACK;
		ctx.fillColor = cc.Color.WHITE.setA(100);

		const scale = rate / this.hotZoneBg.scaleY;

		rectNode.width = data.rect.width * scale;
		rectNode.height = data.rect.height * scale;
		rectNode.x = -this.hotZoneBg.width / 2 + data.rect.x * scale;
		rectNode.y = this.hotZoneBg.height / 2 - data.rect.height * scale - data.rect.y * scale;

		rectNode.anchorX = rectNode.anchorY = 0;


		if (this.data.bgItem.isShowDebugLine) {
			ctx.rect(0, 0, rectNode.width, rectNode.height);
		}
		ctx.stroke();
		ctx.fill();




		const animaNode = new cc.Node();
		animaNode.name = 'anima_' + data.index;
		this.hotZoneBg.addChild(animaNode);

		animaNode.data = data;


		if (data.audio_url) {
			cc.assetManager.loadRemote(data.audio_url, (err, audioClip) => {
				animaNode.audioClip = audioClip;
			});
		}


		const dragonDisplay = animaNode.addComponent(dragonBones.ArmatureDisplay);
		if (!data.texPngData) {
			return
		}
		
		const image = data.texPngData.url//"http://staging-teach.cdn.ireadabc.com/5a0c5af3e952acd0ac83a6e5c6f03ff1.png";
		const ske = data.skeJsonData.url//"http://staging-teach.cdn.ireadabc.com/bd825dcceea298d1146be8067ae3d17f.json";
		const atlas = data.texJsonData.url//"http://staging-teach.cdn.ireadabc.com/246f8991b729fa3e5a7f4802de828efa.json";
		cc.loader.load(image, (error, texture) => {

			cc.loader.load({url: atlas, type: 'txt'}, (error, atlasJson) => {

				cc.loader.load({url: ske, type: 'txt'}, (error, dragonBonesJson) => {

					const atlas = new dragonBones.DragonBonesAtlasAsset();
					atlas.atlasJson = atlasJson;
					atlas.texture = texture;

					const asset = new dragonBones.DragonBonesAsset();
					asset.dragonBonesJson = dragonBonesJson;

					dragonDisplay.dragonAtlasAsset = atlas;
					dragonDisplay.dragonAsset = asset;

					

					let json = JSON.parse(asset.dragonBonesJson);
					let armatures = json["armature"];
					// console.log('armatures: ', armatures);
					let armatureNames = [];
					for (let i = 0; i < armatures.length; i++) {
						armatureNames.push(armatures[i].name);
					}
					// console.log('armatureNames: ', armatureNames);
					if (armatureNames.length > 0) {
						let defaultArmatureName = armatureNames[0];
						dragonDisplay.armatureName = defaultArmatureName;
						// let animationNames = dragonDisplay.getAnimationNames(defaultArmatureName);
						let defaultArmature = armatures[0];
						let animations = defaultArmature.animation;
						let animationNames = [];
						for (let i = 0; i < animations.length; i++) {
							animationNames.push(animations[i].name);
						}

						animaNode.animationNames = animationNames;

						rectNode.addComponent(cc.Button);
						rectNode.on('click', () => {

							return;
							if (rectNode.isClicked) {
								// return;
							}
							rectNode.isClicked = true;
							console.log('clicked');

							if (animaNode.audioClip) {
								cc.audioEngine.stopAllEffects();
								cc.director.emit('STOP_ALL_AUDIO')
								cc.audioEngine.playEffect(animaNode.audioClip, false, 0.8);
							}

							if (animationNames.length > 0) {
								dragonDisplay.playAnimation(animationNames[0], 1);
							}
						});

						// animaNode.playRightAnim = () => {
						// 	animaNode.active = true;
						// 	if (animationNames.length > 0) {
						// 		dragonDisplay.playAnimation(animationNames[0], 1);
						// 	}
						// }
						animaNode.dragonDisplay = dragonDisplay;
					}


					animaNode.x = rectNode.x + rectNode.width / 2;
					animaNode.y = rectNode.y + rectNode.height / 2;

					const sx = rectNode.width / animaNode.width;
					const sy = rectNode.height / animaNode.height;
					const scale = Math.min(sx, sy);
					// animaNode.scale = scale;

					// animaNode.active = false;
					animaNode.opacity = 0;
					animaNode.hitCount = 0;
					// animaNode.opacity = 20;
			
					
				});
			});
		});

		return animaNode;

	},
	playRightAnim(node) {

	},
	playCardRightAnim(card) {

		console.log('in playRightAnim ..')

		const animBase = cc.find("Canvas/res/anim/right");
		const animNode = cc.instantiate(animBase);
		animNode.x = card.x;
		animNode.y = card.y - 100*this._mapScaleMin;
		this.canvas.addChild(animNode, 5);

		const dragonDisplay = animNode.getComponent(dragonBones.ArmatureDisplay);
		dragonDisplay.playAnimation("newAnimation", 1);
	


		playAudio(this.rightClip, () => {
		
		})
	},

	setOneHotZonePic(data) {
		const rate = (this.hotZoneBg.scale * this.hotZoneBg.width) / this.data.bgItem.rect.width;

		const picNode = new cc.Node();
		picNode.name= 'pic' + data.index;
		picNode.data = data;
		this.hotZoneBg.addChild(picNode);

		this.picNodeArr.push(picNode);
		picNode.hitCount = 0;

		cc.loader.load({url: data.pic_url}, (err, img) => {

			const spr = picNode.addComponent(cc.Sprite);
			spr.spriteFrame = new cc.SpriteFrame(img)

			const scale = rate / this.hotZoneBg.scaleY;

			picNode.width = data.rect.width * scale;
			picNode.height = data.rect.height * scale;
			picNode.x = -this.hotZoneBg.width / 2 + data.rect.x * scale;
			picNode.y = this.hotZoneBg.height / 2 - data.rect.height * scale - data.rect.y * scale;

			picNode.x += picNode.width / 2 * picNode.scaleX;
			picNode.y += picNode.height / 2 * picNode.scaleX;


			getSprNodeByUrl(data.answer_pic_url, (spr) => {

				const sprNode = spr.node;
				sprNode.active = false;
				picNode.addChild(sprNode);
				picNode.answerPic = sprNode;

				picNode.isLoadEnd = true;
				// this.checkStart();
			})

			// picNode.anchorX = picNode.anchorY = 0;

			// if (data.audio_url) {
			// 	this.addPicAudio(picNode);
			// }

			// this.addDragPoint(picNode, data)

		});

	},

	addDragPoint(picNode, data) {


		picNode.baseX = picNode.x;
		picNode.baseY = picNode.y;

		const realRate = this.hotZoneBg.width / this.data.bgItem.rect.width;
		picNode.targetPx = -this.hotZoneBg.width / 2 + ( data.dragDot.x - this.data.bgItem.rect.x ) * realRate;
		picNode.targetPy = this.hotZoneBg.height / 2 - (data.dragDot.y - this.data.bgItem.rect.y) * realRate;


		if (data.audio_url) {
			cc.assetManager.loadRemote(data.audio_url, (err, audioClip) => {
				picNode.audioClip = audioClip;
			});
		}


		picNode.on(cc.Node.EventType.TOUCH_START, () => {
			if (picNode.isDragEnd) {
				if (picNode.audioClip) {
					cc.audioEngine.stopAllEffects();
					cc.audioEngine.playEffect(picNode.audioClip, false, 0.8);
				}
				return;
			}
			this._curShowItem = picNode;

			// picNode.x = -this.hotZoneBg.width / 2 + ( data.dragDot.x - this.data.bgItem.rect.x ) * realRate;
			// picNode.y = this.hotZoneBg.height / 2 - (data.dragDot.y - this.data.bgItem.rect.y) * realRate;

		})
	},


	setOnePic(data) {
		const rate = (this.hotZoneBg.scale * this.hotZoneBg.width) / this.data.bgItem.rect.width;

		const picNode = new cc.Node();
		picNode.name= 'pic' + data.index;
		picNode.data = data;
		this.hotZoneBg.addChild(picNode);

		getSprNodeByUrl(data.pic_url, (spr) => {

			const sprNode = spr.node;
			picNode.addChild(sprNode);

			const scale = rate / this.hotZoneBg.scaleY;

			picNode.width = sprNode.width = data.rect.width * scale;
			picNode.height = sprNode.height = data.rect.height * scale;
			picNode.x = -this.hotZoneBg.width / 2 + data.rect.x * scale;
			picNode.y = this.hotZoneBg.height / 2 - data.rect.height * scale - data.rect.y * scale;

			// sprNode.anchorX = sprNode.anchorY = 0;


		})


		// cc.loader.load({url: data.pic_url}, (err, img) => {

		// 	const spr = picNode.addComponent(cc.Sprite);
		// 	spr.spriteFrame = new cc.SpriteFrame(img)

		// 	const scale = rate / this.hotZoneBg.scaleY;

		// 	picNode.width = data.rect.width * scale;
		// 	picNode.height = data.rect.height * scale;
		// 	picNode.x = -this.hotZoneBg.width / 2 + data.rect.x * scale;
		// 	picNode.y = this.hotZoneBg.height / 2 - data.rect.height * scale - data.rect.y * scale;

		// 	picNode.anchorX = picNode.anchorY = 0;

		// 	// if (data.audio_url) {
		// 	// 	this.addPicAudio(picNode);
		// 	// }

		// });

		// picNode.on('touchstart', () => {
		// 	this.show
		// })

	},

	setOneNormalRect(data) {
		const rate = (this.hotZoneBg.scale * this.hotZoneBg.width) / this.data.bgItem.rect.width;

		const rectNode = new cc.Node();
		rectNode.name = 'rect' + data.index;
		this.hotZoneBg.addChild(rectNode);


		const ctx = rectNode.addComponent(cc.Graphics);
		// 红色矩形
		ctx.lineWidth = 4;
		ctx.strokeColor = cc.Color.BLACK;
		ctx.fillColor = cc.Color.WHITE.setA(100);

		const scale = rate / this.hotZoneBg.scaleY;
		// console.log('scale: ', scale);
		// console.log('scale2: ', scale / data.mapScale);


		rectNode.width = data.rect.width * scale;
		rectNode.height = data.rect.height * scale;
		rectNode.x = -this.hotZoneBg.width / 2 + data.rect.x * scale;
		rectNode.y = this.hotZoneBg.height / 2 - data.rect.height * scale - data.rect.y * scale;
		// rectNode.scale = 1 / data.mapScale;

		rectNode.anchorX = rectNode.anchorY = 0;

		if (this.data.bgItem.isShowDebugLine || this.data.isDebug) {
			ctx.rect(0, 0, rectNode.width, rectNode.height);
		}
		ctx.stroke();
		ctx.fill();

		return rectNode;
	},

	setOneRect(data) {
		const rate = (this.hotZoneBg.scale * this.hotZoneBg.width) / this.data.bgItem.rect.width;

		const rectNode = new cc.Node();
		rectNode.name = 'rect' + data.index;
		this.hotZoneBg.addChild(rectNode);


		const ctx = rectNode.addComponent(cc.Graphics);
		// 红色矩形
		ctx.lineWidth = 4;
		ctx.strokeColor = cc.Color.BLACK;
		ctx.fillColor = cc.Color.WHITE.setA(100);

		const scale = rate / this.hotZoneBg.scaleY;
		// console.log('scale: ', scale);
		// console.log('scale2: ', scale / data.mapScale);


		rectNode.width = data.rect.width * scale;
		rectNode.height = data.rect.height * scale;
		rectNode.x = -this.hotZoneBg.width / 2 + data.rect.x * scale;
		rectNode.y = this.hotZoneBg.height / 2 - data.rect.height * scale - data.rect.y * scale;
		// rectNode.scale = 1 / data.mapScale;

		rectNode.anchorX = rectNode.anchorY = 0;

		if (this.data.bgItem.isShowDebugLine || this.data.isDebug || true) {
			ctx.rect(0, 0, rectNode.width, rectNode.height);
		}
		ctx.stroke();
		ctx.fill();

		this.linkRectGroup.push(rectNode);

		// console.log('```data: ', data)

		// this.dragEndRectArr.push(rectNode);

		// if (data.audio_url) {
		// 	cc.assetManager.loadRemote(data.audio_url, (err, audioClip) => {
		// 		rectNode.audioClip = audioClip;
		// 	});
		// }



	},

	addPicAudio(picNode) {
		const data = picNode.data;
		
		cc.assetManager.loadRemote(data.audio_url, (err, audioClip) => {
			picNode.audioClip = audioClip;
		});

		picNode.addComponent(cc.Button);
		picNode.on('click', () => {
				if (picNode.audioClip) {
					cc.audioEngine.stopAllEffects();
					cc.audioEngine.playEffect(picNode.audioClip, false, 0.8);
				}
		});
	},


	initListener() {

		const canvas = cc.find('Canvas');
		
		let downFlag = false;

		const touchMove = (e) => {
			this.canvasTouchMove(e);
			if (canvas.hasEventListener(cc.Node.EventType.MOUSE_MOVE)) {
				canvas.off(cc.Node.EventType.MOUSE_MOVE, mouseMove)
			}
		}

		const mouseMove = (e) => {
			if (!downFlag) {
				return;
			}
			this.canvasTouchMove(e);
			if (canvas.hasEventListener(cc.Node.EventType.TOUCH_MOVE)) {
				canvas.off(cc.Node.EventType.TOUCH_MOVE, touchMove)
				this.removeHtmlCanvasListener('touchmove');
			}
		}

		const touchEnd = (e) => {
		
			downFlag = false;
			this.canvasTouchEnd(e);

			if (canvas.hasEventListener(cc.Node.EventType.MOUSE_UP)) {
				canvas.off(cc.Node.EventType.MOUSE_UP, mouseUp)
			}
			if (canvas.hasEventListener(cc.Node.EventType.MOUSE_LEAVE)) {
				canvas.off(cc.Node.EventType.MOUSE_LEAVE, mouseUp)
			}
			this.removeHtmlTouchEnd();
		}

		const mouseUp = (e) => {
	
			downFlag = false;

			this.canvasTouchEnd(e);

			if (canvas.hasEventListener(cc.Node.EventType.TOUCH_END)) {
				canvas.off(cc.Node.EventType.TOUCH_END, touchEnd)
			}
			if (canvas.hasEventListener(cc.Node.EventType.TOUCH_CANCEL)) {
				canvas.off(cc.Node.EventType.TOUCH_CANCEL, touchEnd)
			}
		}
		

		canvas.on(cc.Node.EventType.TOUCH_MOVE, touchMove)
		canvas.on(cc.Node.EventType.MOUSE_MOVE, mouseMove)

		canvas.on(cc.Node.EventType.TOUCH_END, touchEnd)
		canvas.on(cc.Node.EventType.TOUCH_CANCEL, touchEnd)
		canvas.on(cc.Node.EventType.MOUSE_UP, mouseUp)

	},

	removeHtmlCanvasListener(type) {
		const canvasHtml = document.querySelector('canvas');
		canvasHtml.addEventListener(type, (e) => {})
	},	
	removeHtmlTouchEnd() {
		const canvasHtml = document.querySelector('canvas');
		canvasHtml.removeEventListener('touchend', this.htmlCanvasTouchendFunc, this);
	},

	canvasTouchMove(e) {


		if (!this._curShowItem) {
			return;
		}

		// console.log(' in canvasTouchMove')


		let pos = e.getLocation();

		// console.log('pos.x: ', pos.x);
		// console.log('pos.y: ', pos.y);
		// pos.x += this.canvas.width / 2;
		// pos.y += this.canvas.height / 2;

		// const newPos = exchangeNodePos(this._curShowItem, this.canvas)



		this._curShowItem.x = pos.x - this.canvas.width / 2 //+ newPos.x // pos.x - e.currentTarget.width / 2;
		this._curShowItem.y = pos.y - this.canvas.height / 2; //+ newPos.y // pos.y - e.currentTarget.height / 2;

		// console.log('pos: ', pos.x);
	},

	canvasTouchEnd(e) {

		if (!this._curShowItem) {
			return;
		}
		this.checkOnDragEndRect();
		this._curShowItem = null;
	},



	checkOnDragEndRect() {

		// console.log('emptyGroupArr: ',  this.emptyGroupArr);
		for (let i = 0; i < this.letterBgArr.length; i++) {

			const worldRect = this.letterBgArr[i].rect;

			const worldPos = this._curShowItem.parent.convertToWorldSpaceAR(cc.v2(this._curShowItem.x, this._curShowItem.y));

			if (worldRect.contains(worldPos)) {
			
				// console.log('rect in ')
				this.checkIsDragEndTarget(this.letterBgArr[i]);

				return;
			}
			
		}

		this.itemBack();
	},

	itemBack() {

		// cc.audioEngine.playEffect(this.wrongClip, false, 0.8);

		const node = this._curShowItem;
		const worldPos = node.parent.convertToWorldSpaceAR(cc.v2(node.x, node.y));
		const localPos = node.baseParent.convertToNodeSpaceAR(worldPos);

		
		node.x = localPos.x;
		node.y = localPos.y;
		node.parent = node.baseParent;
		
		node.isMove = true;

		cc.tween(node)
			.to(0.5, {x: node.baseX, y: node.baseY}, {easing: "elasticOut"})
			.call(() => {
				node.isMove = false;
			})
			.start();

	},

	checkIsDragEndTarget(letterBg) {

		// const worldPos = this._curShowItem.parent.convertToWorldSpaceAR(cc.v2(this._curShowItem.targetPx, this._curShowItem.targetPy));
		// const worldRect = rect.getBoundingBoxToWorld();
		if (!letterBg.isRight && this._curShowItem.letterBg != letterBg) {
			// letterBg.isDragEnd = true;

			this._curShowItem.x = letterBg.x;
			this._curShowItem.y = letterBg.y + this._curShowItem.offY;
			this._curShowItem.parent = letterBg.parent;


			cc.audioEngine.playEffect(this.clickClip, false, 0.8);



			const moveLetter = letterBg.letter;
			const moveLetterBg = this._curShowItem.letterBg;
			this.letterMoveToRect(moveLetter, moveLetterBg);

			this._curShowItem.letterBg = letterBg;
			letterBg.letter = this._curShowItem;
			this._curShowItem.baseX = this._curShowItem.x;
			this._curShowItem.baseY = this._curShowItem.y;
			this.checkChangeLetterBg(	this._curShowItem, letterBg.index) 

			this.checkCurGroupEnd();

		} else {
			this.itemBack();
		}
	},

	checkCurGroupEnd() {
		for (let i=0; i<this.letterArr.length; i++) {
			if (!this.letterArr[i].isRight) {
				return;
			}
		}

		this.canTouch = false;


		this.delayCall(0.7, () => {
			cc.audioEngine.playEffect(this.rightClip, false, 0.8);
			// cc.audioEngine.playEffect(this.nextClip, false, 0.8);
		})
		this.delayCall(0.3, () => {
			this.enterNextGroup();
		})
	},

	enterNextGroup() {

		this.addScore();

		this.curDataIndex ++;
		this.initCurData();
		if (!this.curData) {
			this.gameEnd();
			return;
		}



		this.delayCall(0.3, () => {
			this.initCurWord();
		})



		
	},

	letterMoveToRect(letter, letterBg) {
		letter.zIndex = 1;
		letter.isMove = true;
		cc.tween(letter)
			.to(0.5, {x: letterBg.x, y: letterBg.y + letter.offY}, {easing: "elasticOut"})
			.call(() => {
				letter.isMove = false;
			})
			.start();

		
		letter.baseX = letterBg.x;
		letter.baseY = letterBg.y + letter.offY;

		letter.letterBg = letterBg;
		letterBg.letter = letter;


		this.checkChangeLetterBg(letter, letterBg.index) 
	},

	onDestroy() {
		this.isDestroy = true;
		if (this.isTesting) {
			this.endTesting();
		}
	},


});
