Commit 34343ce8 authored by liujiangnan's avatar liujiangnan

feat: 初始项目

parent 9f5f5457
import { asyncDelay, onHomeworkFinish } from "../script/util";
import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent";
const { ccclass, property } = cc._decorator;
@ccclass
export default class SceneComponent extends MyCocosSceneComponent {
addPreloadImage() {
// TODO 根据自己的配置预加载图片资源
}
addPreloadAudio() {
// TODO 根据自己的配置预加载音频资源
}
addPreloadAnima() {
}
onLoadEnd() {
// TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考
this.initData();
this.initView();
this.initListener();
}
_cantouch = null;
initData() {
// 所有全局变量 默认都是null
this._cantouch = true;
}
initView() {
this.initBg();
this.initBtn();
}
initBg() {
}
initBtn() {
}
currentIndex = 0;
leftMove() {
const node = cc.find(`Canvas/bg/L${this.currentIndex+1}`);
const nextNode = cc.find(`Canvas/bg/L${this.currentIndex+2}`);
this._cantouch = false;
cc.tween(node)
.to(.3, { x: -4000 }, { easing: 'cubicInOut' })
.call(() => {
cc.tween(nextNode)
.to(.3, { x: 0 }, { easing: 'cubicInOut' })
.call(() => {
this.currentIndex ++;
cc.find(`Canvas/bg/right`).active = this.currentIndex<4;
cc.find(`Canvas/bg/left`).active = this.currentIndex>0;
this._cantouch = true;
})
.start();
})
.start();
}
rightMove() {
const node = cc.find(`Canvas/bg/L${this.currentIndex+1}`);
const beforeNode = cc.find(`Canvas/bg/L${this.currentIndex}`);
this._cantouch = false;
cc.tween(node)
.to(.3, { x: 4000 }, { easing: 'cubicInOut' })
.call(() => {
cc.tween(beforeNode)
.to(.3, { x: 0 }, { easing: 'cubicInOut' })
.call(() => {
this.currentIndex --;
cc.find(`Canvas/bg/right`).active = this.currentIndex<4;
cc.find(`Canvas/bg/left`).active = this.currentIndex>0;
this._cantouch = true;
})
.start();
})
.start();
}
// update (dt) {},
initListener() {
this.node.on('touchstart', this.onEventStart, this);
this.node.on('touchend', this.onEventEnd, this);
}
touchX;
onEventStart(event) {
const worldPoint = event.getLocation();
this.touchX = worldPoint.x;
}
onEventEnd(event) {
const worldPoint = event.getLocation();
const x = worldPoint.x;
if (x > this.touchX + 100) {
if (this.currentIndex<=0) {
// 已经是第一个了
return;
}
console.log("======向右滑动=======");
this.rightMove();
}
if (x < this.touchX - 100) {
if (this.currentIndex>=4) {
// 已经是最后一个了
return;
}
console.log("======向左滑动=======");
this.leftMove()
}
}
playLocalAudio(audioName) {
const audio = cc.find(`Canvas/res/audio/${audioName}`).getComponent(cc.AudioSource);
return new Promise((resolve, reject) => {
const id = cc.audioEngine.playEffect(audio.clip, false);
cc.audioEngine.setFinishCallback(id, () => {
resolve(id);
});
})
}
}
{
"ver": "2.3.5",
"uuid": "9a79969a-0506-48d4-bc98-3c05d109b027",
"uuid": "9df40926-be62-47be-a750-e209f78947c0",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 61,
"height": 67,
"width": 758,
"height": 658,
"platformSettings": {},
"subMetas": {
"btn_left": {
"L1": {
"ver": "1.0.4",
"uuid": "ce19457d-e8f3-4c38-ae3e-d4b99208ddb5",
"rawTextureUuid": "9a79969a-0506-48d4-bc98-3c05d109b027",
"uuid": "73ee82cc-cc95-4a87-aaeb-1b23510cd553",
"rawTextureUuid": "9df40926-be62-47be-a750-e209f78947c0",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
......@@ -22,10 +22,10 @@
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 61,
"height": 67,
"rawWidth": 61,
"rawHeight": 67,
"width": 758,
"height": 658,
"rawWidth": 758,
"rawHeight": 658,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
......
{
"ver": "2.3.5",
"uuid": "d582359e-924e-4ee9-9964-1fc4bb417e71",
"uuid": "d230e42b-c737-4231-a7ae-073885a0ae63",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 61,
"height": 67,
"width": 758,
"height": 654,
"platformSettings": {},
"subMetas": {
"btn_right": {
"L2": {
"ver": "1.0.4",
"uuid": "e5a2dbaa-a677-4a32-90d7-a1b057d7fb59",
"rawTextureUuid": "d582359e-924e-4ee9-9964-1fc4bb417e71",
"uuid": "c05bf4f2-9a22-42bb-b96a-2c42af2bff94",
"rawTextureUuid": "d230e42b-c737-4231-a7ae-073885a0ae63",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": -0.5,
"offsetY": 0.5,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 60,
"height": 66,
"rawWidth": 61,
"rawHeight": 67,
"width": 758,
"height": 654,
"rawWidth": 758,
"rawHeight": 654,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
......
{
"ver": "2.3.5",
"uuid": "b133c27e-5317-437c-82f6-2d9cdd3c11c6",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 758,
"height": 663,
"platformSettings": {},
"subMetas": {
"L3": {
"ver": "1.0.4",
"uuid": "c7f0e5e8-9863-4a07-bc17-728bc32aa3aa",
"rawTextureUuid": "b133c27e-5317-437c-82f6-2d9cdd3c11c6",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 758,
"height": 663,
"rawWidth": 758,
"rawHeight": 663,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "12cf0f42-2b29-4cda-96a4-15a86335a179",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 758,
"height": 652,
"platformSettings": {},
"subMetas": {
"L4": {
"ver": "1.0.4",
"uuid": "6151ff0a-a839-42c0-a350-799d435d48e1",
"rawTextureUuid": "12cf0f42-2b29-4cda-96a4-15a86335a179",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 758,
"height": 652,
"rawWidth": 758,
"rawHeight": 652,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "efa5fa09-a4dd-4bfc-ab7e-17c19f85408f",
"uuid": "45a3d188-f98d-46cc-84b5-af7ff11a9e38",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 366,
"height": 336,
"width": 758,
"height": 652,
"platformSettings": {},
"subMetas": {
"1orange": {
"L5": {
"ver": "1.0.4",
"uuid": "43d1e79d-6de8-4dcb-b8ce-d767df7913aa",
"rawTextureUuid": "efa5fa09-a4dd-4bfc-ab7e-17c19f85408f",
"uuid": "6784fe91-2825-4714-93a4-17fdf3136770",
"rawTextureUuid": "45a3d188-f98d-46cc-84b5-af7ff11a9e38",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
......@@ -22,10 +22,10 @@
"offsetY": -0.5,
"trimX": 0,
"trimY": 1,
"width": 366,
"height": 335,
"rawWidth": 366,
"rawHeight": 336,
"width": 758,
"height": 651,
"rawWidth": 758,
"rawHeight": 652,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
......
{
"ver": "2.3.5",
"uuid": "e1b4d971-9876-4832-803a-5a321964a78b",
"uuid": "80a4149e-47cd-4fd6-8bec-787cfcb609e9",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
......@@ -13,8 +13,8 @@
"subMetas": {
"bg": {
"ver": "1.0.4",
"uuid": "8288e3d4-4c75-4b27-8f01-f7014417f4dd",
"rawTextureUuid": "e1b4d971-9876-4832-803a-5a321964a78b",
"uuid": "8c9ac73a-70de-4fdf-a921-c6860553d77c",
"rawTextureUuid": "80a4149e-47cd-4fd6-8bec-787cfcb609e9",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
......
{
"ver": "2.3.5",
"uuid": "18d07592-51a9-421e-8972-0f67b68d29e1",
"uuid": "1d0314fb-3ff8-4f1e-b151-86a4c3ac00a2",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 144,
"height": 144,
"width": 222,
"height": 178,
"platformSettings": {},
"subMetas": {
"icon": {
"left": {
"ver": "1.0.4",
"uuid": "6fbc30a8-3c49-44ae-8ba4-7f56f385b78a",
"rawTextureUuid": "18d07592-51a9-421e-8972-0f67b68d29e1",
"uuid": "b54dc5ad-f87a-4546-902a-7489f01aefab",
"rawTextureUuid": "1d0314fb-3ff8-4f1e-b151-86a4c3ac00a2",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetX": -4.5,
"offsetY": -0.5,
"trimX": 3,
"trimY": 2,
"width": 138,
"height": 141,
"rawWidth": 144,
"rawHeight": 144,
"trimX": 58,
"trimY": 48,
"width": 97,
"height": 83,
"rawWidth": 222,
"rawHeight": 178,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
......
{
"ver": "2.3.5",
"uuid": "fa0d1106-f300-4760-bd44-cae8963f3997",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 222,
"height": 178,
"platformSettings": {},
"subMetas": {
"right": {
"ver": "1.0.4",
"uuid": "a0e0bf64-61fd-4600-8e32-40232e778401",
"rawTextureUuid": "fa0d1106-f300-4760-bd44-cae8963f3997",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": -5,
"offsetY": 0,
"trimX": 57,
"trimY": 47,
"width": 98,
"height": 84,
"rawWidth": 222,
"rawHeight": 178,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
import { asyncDelay, onHomeworkFinish } from "../script/util";
import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent";
const { ccclass, property } = cc._decorator;
@ccclass
export default class SceneComponent extends MyCocosSceneComponent {
addPreloadImage() {
// TODO 根据自己的配置预加载图片资源
this._imageResList.push({ url: this.data.pic_url });
this._imageResList.push({ url: this.data.pic_url_2 });
}
addPreloadAudio() {
// TODO 根据自己的配置预加载音频资源
this._audioResList.push({ url: this.data.audio_url });
}
addPreloadAnima() {
}
onLoadEnd() {
// TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考
this.initData();
this.initView();
this.initListener();
}
_cantouch = null;
initData() {
// 所有全局变量 默认都是null
this._cantouch = true;
}
initView() {
this.initBg();
this.initPic();
this.initBtn();
this.initIcon();
}
initBg() {
const bgNode = cc.find('Canvas/bg');
bgNode.scale = this._mapScaleMax;
}
pic1 = null;
pic2 = null;
initPic() {
const canvas = cc.find('Canvas');
const maxW = canvas.width * 0.7;
this.getSprNodeByUrl(this.data.pic_url, (sprNode) => {
const picNode1 = sprNode;
picNode1.scale = maxW / picNode1.width;
picNode1.baseX = picNode1.x;
canvas.addChild(picNode1);
this.pic1 = picNode1;
const labelNode = new cc.Node();
labelNode.color = cc.Color.YELLOW;
const label = labelNode.addComponent(cc.Label);
label.string = this.data.text;
label.fontSize = 60;
label.lineHeight = 60;
label.font = cc.find('Canvas/res/font/BRLNSDB').getComponent('cc.Label').font;
picNode1.addChild(labelNode);
});
this.getSprNodeByUrl(this.data.pic_url_2, (sprNode) => {
const picNode2 = sprNode;
picNode2.scale = maxW / picNode2.width;
canvas.addChild(picNode2);
picNode2.x = canvas.width;
picNode2.baseX = picNode2.x;
this.pic2 = picNode2;
const labelNode = new cc.Node();
const label = labelNode.addComponent(cc.RichText);
const size = 60
label.font = cc.find('Canvas/res/font/BRLNSDB').getComponent(cc.Label).font;
label.string = `<outline color=#751e00 width=4><size=${size}><color=#ffffff>${this.data.text}</color></size></outline>`
label.lineHeight = size;
picNode2.addChild(labelNode);
});
}
initIcon() {
const iconNode = this.getSprNode('icon');
iconNode.zIndex = 5;
iconNode.anchorX = 1;
iconNode.anchorY = 1;
iconNode.parent = cc.find('Canvas');
iconNode.x = iconNode.parent.width / 2 - 10;
iconNode.y = iconNode.parent.height / 2 - 10;
iconNode.on(cc.Node.EventType.TOUCH_START, () => {
this.playAudioByUrl(this.data.audio_url);
})
}
curPage = null;
initBtn() {
this.curPage = 0;
const bottomPart = cc.find('Canvas/bottomPart');
bottomPart.zIndex = 5; // 提高层级
bottomPart.x = bottomPart.parent.width / 2;
bottomPart.y = -bottomPart.parent.height / 2;
const leftBtnNode = bottomPart.getChildByName('btn_left');
//节点中添加了button组件 则可以添加click事件监听
leftBtnNode.on('click', () => {
if (!this._cantouch) {
return;
}
if (this.curPage == 0) {
return;
}
this.curPage = 0
this.leftMove();
this.playLocalAudio('btn');
})
const rightBtnNode = bottomPart.getChildByName('btn_right');
//节点中添加了button组件 则可以添加click事件监听
rightBtnNode.on('click', () => {
if (!this._cantouch) {
return;
}
if (this.curPage == 1) {
return;
}
this.curPage = 1
this.rightMove();
// 游戏结束时需要调用这个方法通知系统作业完成
onHomeworkFinish();
this.playLocalAudio('btn');
})
}
leftMove() {
this._cantouch = false;
const len = this.pic1.parent.width;
cc.tween(this.pic1)
.to(1, { x: this.pic1.baseX }, { easing: 'cubicInOut' })
.start();
cc.tween(this.pic2)
.to(1, { x: this.pic2.baseX }, { easing: 'cubicInOut' })
.call(() => {
this._cantouch = true;
})
.start();
}
rightMove() {
this._cantouch = false;
const len = this.pic1.parent.width;
cc.tween(this.pic1)
.to(1, { x: this.pic1.baseX - len }, { easing: 'cubicInOut' })
.start();
cc.tween(this.pic2)
.to(1, { x: this.pic2.baseX - len }, { easing: 'cubicInOut' })
.call(() => {
this._cantouch = true;
})
.start();
}
// update (dt) {},
initListener() {
}
playLocalAudio(audioName) {
const audio = cc.find(`Canvas/res/audio/${audioName}`).getComponent(cc.AudioSource);
return new Promise((resolve, reject) => {
const id = cc.audioEngine.playEffect(audio.clip, false);
cc.audioEngine.setFinishCallback(id, () => {
resolve(id);
});
})
}
}
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