Commit a0fd46f2 authored by Lwd's avatar Lwd

aaaa

parent 8acdd228
This diff is collapsed.
......@@ -2,139 +2,142 @@
* 适配
*/
cc.Class({
extends: cc.Component,
extends: cc.Component,
properties: {
UIMax: {
default: [],
type: cc.Node,
displayName: "等比放大"
},
topUI: {
default: [],
type: cc.Widget,
},
canvasView: {
default: null,
type: cc.Canvas,
displayName: "根节点"
},
isCanvas: {
default: false,
}
},
properties: {
UIMax: {
default: [],
type: cc.Node,
displayName: "等比放大"
},
topUI: {
default: [],
type: cc.Widget,
},
onLoad: function () { //开启适配
this.widgetList = [];
this.scheduleOnce(function () {
if (!this.isCanvas) {
this.init();
} else {
var canvaSize = this.findCanvas();
var w = (canvaSize.width) / 720;
var h = (canvaSize.height) / 1280;
this.MaxSize = w / h > 1 ? w / h : h / w;
this.setUIMax(this.MaxSize);
this.settopUI(this.MaxSize);
var scene = cc.director.getScene();
canvasView: {
default: null,
type: cc.Canvas,
displayName: "根节点"
},
isCanvas: {
default: false,
}
},
var list = scene.getComponentsInChildren(cc.Widget)
for (var i in list) {
list[i].updateAlignment();
}
}
}, 0);
this.MaxSize = 1;
onLoad: function () { //开启适配
this.widgetList = [];
this.scheduleOnce(function () {
if (!this.isCanvas) {
this.init();
} else {
var canvaSize = this.findCanvas();
var w = (canvaSize.width) / 720;
var h = (canvaSize.height) / 1280;
this.MaxSize = w / h > 1 ? w / h : h / w;
// if (window.addEventListener) {
// window.addEventListener('resize', scaleEventCallBack, false)
// } else if (window.attachEvent) {
// window.attachEvent('resize', scaleEventCallBack, false)
// };
this.setUIMax(this.MaxSize);
this.settopUI(this.MaxSize);
var scene = cc.director.getScene();
// g.event_mgr.reg("adjustUI", () => {
// this.init();
// });
},
init: function () {
var canvaSize = this.findCanvas();
var diff = canvaSize.width / canvaSize.height;
var bili = 750 / 1334;
if (diff > bili) {
this.canvasView.fitWidth = false;
this.canvasView.fitHeight = true;
} else if (diff < bili) {
this.canvasView.fitWidth = true;
this.canvasView.fitHeight = false;
} else {
this.canvasView.fitWidth = true;
this.canvasView.fitHeight = true;
}
var w = (canvaSize.width) / 750;
var h = (canvaSize.height) / 1334;
this.MaxSize = w / h > 1 ? w / h : h / w;
g.data_mgr.MaxSize = this.MaxSize;
this.setUIMax(this.MaxSize);
this.settopUI(this.MaxSize);
var scene = cc.director.getScene();
var list = scene.getComponentsInChildren(cc.Widget)
for (var i in list) {
list[i].updateAlignment();
}
},
var list = scene.getComponentsInChildren(cc.Widget)
for (var i in list) {
list[i].updateAlignment();
}
}
}, 0);
this.MaxSize = 1;
// if (window.addEventListener) {
// window.addEventListener('resize', scaleEventCallBack, false)
// } else if (window.attachEvent) {
// window.attachEvent('resize', scaleEventCallBack, false)
// };
// //屏幕缩放事件
// scaleEventCallBack: function () {
// //setTimeout(function () {
// g.log("屏幕缩放");
// g.event_mgr.send("adjustUI");
// //}, 500); //延迟0.5秒
// },
// g.event_mgr.reg("adjustUI", () => {
// this.init();
// });
},
init: function () {
var canvaSize = this.findCanvas();
var diff = canvaSize.width / canvaSize.height;
var bili = 750 / 1334;
if (diff > bili) {
this.canvasView.fitWidth = false;
this.canvasView.fitHeight = true;
} else if (diff < bili) {
this.canvasView.fitWidth = true;
this.canvasView.fitHeight = false;
} else {
this.canvasView.fitWidth = true;
this.canvasView.fitHeight = true;
}
var w = (canvaSize.width) / 750;
var h = (canvaSize.height) / 1334;
this.MaxSize = w / h > 1 ? w / h : h / w;
onDestroy: function () {
g.data_mgr.MaxSize = this.MaxSize;
this.setUIMax(this.MaxSize);
this.settopUI(this.MaxSize);
var scene = cc.director.getScene();
var list = scene.getComponentsInChildren(cc.Widget)
for (var i in list) {
list[i].updateAlignment();
}
},
},
settopUI: function (s) {
if (!g.data_mgr.phoneInfo) {
return;
}
var top = g.data_mgr.phoneInfo;
top = top * s;
for (var i in this.topUI) {
if (this.topUI[i].perTop == undefined) {
this.topUI[i].perTop = this.topUI[i].top;
} else {
this.topUI[i].top = this.topUI[i].perTop;
}
this.topUI[i].top += top;
console.log(this.topUI[i].top);
}
},
setUIMax: function (size) {
for (var i in this.UIMax) {
if (this.UIMax[i].perScale == undefined) {
this.UIMax[i].perScale = this.UIMax[i].scaleX;
// //屏幕缩放事件
// scaleEventCallBack: function () {
// //setTimeout(function () {
// g.log("屏幕缩放");
// g.event_mgr.send("adjustUI");
// //}, 500); //延迟0.5秒
// },
} else {
this.UIMax[i].scaleX = this.UIMax[i].perScale;
this.UIMax[i].scaleY = this.UIMax[i].perScale;
}
this.UIMax[i].scaleX *= size;
this.UIMax[i].scaleY *= size;
}
},
findCanvas: function () {
if (cc.sys.isNative) {
return {
width: cc.view.getFrameSize().width,
height: cc.view.getFrameSize().height
};
} else {
return {
width: cc.game.canvas.clientWidth,
height: cc.game.canvas.clientHeight
};
}
}
onDestroy: function () {
},
settopUI: function (s) {
if (!g.data_mgr.phoneInfo) {
return;
}
var top = g.data_mgr.phoneInfo;
top = top * s;
for (var i in this.topUI) {
if (this.topUI[i].perTop == undefined) {
this.topUI[i].perTop = this.topUI[i].top;
} else {
this.topUI[i].top = this.topUI[i].perTop;
}
this.topUI[i].top += top;
console.log(this.topUI[i].top);
}
},
setUIMax: function (size) {
for (var i in this.UIMax) {
if (this.UIMax[i].perScale == undefined) {
this.UIMax[i].perScale = this.UIMax[i].scaleX;
} else {
this.UIMax[i].scaleX = this.UIMax[i].perScale;
this.UIMax[i].scaleY = this.UIMax[i].perScale;
}
this.UIMax[i].scaleX *= size;
this.UIMax[i].scaleY *= size;
}
},
findCanvas: function () {
if (cc.sys.isNative) {
return {
width: cc.view.getFrameSize().width,
height: cc.view.getFrameSize().height
};
} else {
return {
width: cc.game.canvas.clientWidth,
height: cc.game.canvas.clientHeight
};
}
}
});
......@@ -84,7 +84,6 @@ var game = cc.Class({
console.log("游戏开始:" + g.data_mgr);
//播放一个上面的音乐
this.setAudioInfo(1);
this.PlayAudio();
},
//获得随机播放的音乐并播放
......@@ -95,6 +94,7 @@ var game = cc.Class({
//设置播放信息
g.data_mgr.playId = num;
g.data_mgr.playType = type;
this.PlayAudio();
},
//重新播放音乐
......@@ -121,6 +121,8 @@ var game = cc.Class({
g.data_mgr.addPreloadAudio();
g.data_mgr.addPreloadAnima();
g.result.inst.End = true;
//初始化界面
this.UpdataUi();
......@@ -130,8 +132,6 @@ var game = cc.Class({
//游戏开始
g.game.inst.gameStart();
//清除线
this.clearLine();
},
......
/**
* result
*/
const Color_texts = ['#BE1AC1', '#24C11A', '#1A1DC1', '#9F5307'];
const Color_texts = ['#BE1AC1', '#2E6EEE', '#1A1DC1', '#770060'];
var result = cc.Class({
extends: cc.Component,
......@@ -86,7 +86,37 @@ var result = cc.Class({
// 初始化文本
initRichText(text) {
this.lb_tips.string = text;
//this.lb_tips.string = text;
// text = 'I am flying';
this.layoutText.removeAllChildren();
if (!text) {
return;
}
text = text.replace(/ /g, " |");
let arr = text.split('|');
if (arr.length <= 0) {
return;
}
this.layoutText.active = true;
this.lb_tips.string = arr[0];
this.lb_tips._forceUpdateRenderData(true)
for (let i = 0; i < arr.length; i++) {
if (arr[i + 1] == ' ') {
continue;
}
let node = cc.instantiate(this.lb_tips.node);
let label = node.getComponent(cc.Label);
label.string = arr[i];
node.parent = this.layoutText;
label._forceUpdateRenderData(true);
}
this.layoutText.getComponent(cc.Layout).updateLayout();
let width = this.layoutText.width;
if (width > 1000) {
let scale = 1000 / width;
this.layoutText.scale = scale;
}
},
//设置图片
......@@ -113,7 +143,9 @@ var result = cc.Class({
},
playAudio() {
cc.assetManager.loadRemote(this.itemInfo.group_audio_url, null, (err, clip) => {
// this.itemInfo.group_audio_url
var test = "http://staging-teach.cdn.ireadabc.com/495324991838775e49e3ca6593d432c9.mp3"
cc.assetManager.loadRemote(test, null, (err, clip) => {
this.audioID = cc.audioEngine.play(clip, false, 1);
this.audioDuration = cc.audioEngine.getDuration(this.audioID);
this.textDuration = this.audioDuration / this.layoutText.childrenCount;
......@@ -125,7 +157,7 @@ var result = cc.Class({
cc.audioEngine.stop(this.audioID);
this.unschedule(this.chengeTextColor);
this.isPlaying = false;
this.stopSpine();
// this.stopSpine();
},
chengeTextColor() {
......@@ -139,17 +171,27 @@ var result = cc.Class({
},
clearTextColor() {
for (let i = 0; i < this.layoutText.children.length; i++) {
this.layoutText.children[i].color = new cc.Color().fromHEX(Color_texts[3]);
this.layoutText.children[i].color = new cc.Color().fromHEX(Color_texts[1]);
}
},
onBtnText() {
this.clearTextColor();
this.stopAudio();
this.playAudio();
},
//点击关闭
onBtnClose: function () {
this.node.active = false;
//如果播放列表少于1则显示
if (this.End == false) {
return;
}
if (g.data_mgr.temPlayAudio.length < 1) {
//显示结算撒花
g.game.inst.showResult();
this.End = false;
} else {
//重新随机一组数据
g.game.inst.setAudioInfo(1);
......
{
"ver": "2.3.5",
"uuid": "b1526667-de09-4475-a793-de7e9b63c68d",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 852,
"height": 516,
"platformSettings": {},
"subMetas": {
"frame_dragon": {
"ver": "1.0.4",
"uuid": "8c658fc0-c1e4-4993-bce4-b5cce324b69b",
"rawTextureUuid": "b1526667-de09-4475-a793-de7e9b63c68d",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 852,
"height": 516,
"rawWidth": 852,
"rawHeight": 516,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment