Commit f25e3953 authored by Chen Jiping's avatar Chen Jiping

feat:动画调试

parent e926774c
{
"ver": "1.1.2",
"uuid": "cbb03934-bf88-4ed8-b203-9f9561e48c4f",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
This diff is collapsed.
{
"ver": "1.0.1",
"uuid": "73029a30-648f-41d1-8646-8cdd486bfd27",
"subMetas": {}
}
\ No newline at end of file
{"name":"mao","imagePath":"mao_tex.png","SubTexture":[{"name":"猫01/影子","x":1,"height":66,"y":343,"width":337},{"name":"猫01/尾巴","x":1,"height":109,"y":188,"width":175},{"name":"猫01/右腿","x":178,"height":117,"y":188,"width":104},{"name":"猫01/左腿","x":1,"height":115,"y":569,"width":64},{"name":"猫01/右手","x":427,"height":122,"y":590,"width":69},{"name":"猫01/左手","x":301,"height":74,"y":590,"width":124},{"name":"猫01伸/左手伸直","x":299,"height":169,"y":1,"width":168},{"name":"猫01伸/右手伸直","x":299,"height":169,"y":172,"width":168},{"name":"猫01/身体","x":340,"height":180,"y":343,"width":122},{"name":"猫01/领带","x":1,"height":156,"y":411,"width":120},{"name":"猫01/右耳","x":155,"height":76,"y":602,"width":90},{"name":"猫01/左耳","x":67,"height":85,"y":602,"width":86},{"name":"猫01/组_1","x":1,"height":185,"y":1,"width":296},{"name":"猫01/右眼","x":247,"height":60,"y":666,"width":59},{"name":"猫01/右眉毛","x":67,"height":5,"y":595,"width":33},{"name":"猫01/左眼","x":1,"height":60,"y":686,"width":59},{"name":"猫01/左眉毛","x":247,"height":12,"y":602,"width":31},{"name":"猫01/眼镜","x":301,"height":63,"y":525,"width":170},{"name":"猫01/胡子","x":123,"height":85,"y":515,"width":176},{"name":"猫01/鼻子","x":67,"height":24,"y":569,"width":28},{"name":"猫01/嘴","x":1,"height":30,"y":299,"width":65},{"name":"猫01/帽子","x":123,"height":102,"y":411,"width":158}],"height":1024,"width":512}
\ No newline at end of file
{
"ver": "1.0.1",
"uuid": "6f8ba9a2-235e-4cf6-a066-504005631f4e",
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "0a4363c3-dd0a-4019-bfa9-bbf9f61be6f8",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 512,
"height": 1024,
"platformSettings": {},
"subMetas": {
"mao_tex": {
"ver": "1.0.4",
"uuid": "672de77e-64c5-46a7-82e7-91b83c5171d8",
"rawTextureUuid": "0a4363c3-dd0a-4019-bfa9-bbf9f61be6f8",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": -7.5,
"offsetY": 138.5,
"trimX": 1,
"trimY": 1,
"width": 495,
"height": 745,
"rawWidth": 512,
"rawHeight": 1024,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "1.1.0",
"uuid": "2e7b598b-8d8b-4ee7-a11c-94f3f04479c9",
"subMetas": {}
}
\ No newline at end of file
This diff is collapsed.
import { asyncDelay, onHomeworkFinish } from "../script/util";
import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent";
import { Cat } from "../script/Cat";
import { PicArea } from "../script/PicArea";
import { getLetterArr, Word, WordArea, WordArea2, WordGroup } from "../script/Entites";
const { ccclass, property } = cc._decorator;
@ccclass
export default class SceneComponent extends MyCocosSceneComponent {
/**
* 猫咪节点
*/
cat: Cat;
picArea: PicArea;
//单词区域1
wordArea: WordArea;
/**单词区域*/
wordArea2: WordArea2;
//次数
playTimes = 0;
//最大次数
readonly MAX_PLAY_TIMES = 2;
/**是否结束 */
_end = false;
addPreloadImage() {
// TODO 根据自己的配置预加载图片资源
//this._imageResList.push({ url: this.data.pic_url });
if (this.data.pic && this.data.pic.picUrl) {
this._imageResList.push({ url: this.data.pic.picUrl });
}
}
addPreloadAudio() {
// TODO 根据自己的配置预加载音频资源
//this._audioResList.push({ url: this.data.audio_url });
const add = (item, key) => {
if (!item) {
return;
}
item[key] && this._audioResList.push({ url: item[key] });
}
const addWord = (arr) => {
if (!arr) {
return;
}
for (let word of arr) {
add(word, 'audioUrl');
}
}
add(this.data, 'guideAudioUrl1');
add(this.data, 'guideAudioUrl2');
add(this.data, 'guideAudioUrl3');
if (this.data.exercises) {
let exercises = this.data.exercises;
addWord(exercises.wordArr);
addWord(exercises.wordArr2);
}
}
addPreloadAnima() {
......@@ -25,20 +81,106 @@ export default class SceneComponent extends MyCocosSceneComponent {
// TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考
this.initData();
this.initView();
this.initListener();
}
_cantouch = null;
initData() {
// 所有全局变量 默认都是null
this._cantouch = true;
this._cantouch = false;
}
initView() {
this.initBg();
this.initCat();
this.initPicArea();
this.initWordArea();
this.beginGame();
}
initBg() {
const bgNode = cc.find('Canvas/bg');
bgNode.scale = this._mapScaleMax;
const canvas = cc.find('Canvas');
bgNode.scale = Math.max((canvas.width / bgNode.width), (canvas.height / bgNode.height));
}
private initCat() {
this.cat = new Cat(this);
this.cat.data = this.data;
this.cat.init();
}
private initPicArea() {
//图片区域
this.picArea = new PicArea(this.cat);
this.picArea.data = this.data.pic;
this.picArea.node = cc.find("Canvas/center/pic_area");
this.picArea.init();
this.picArea.canTouch = true;
this.picArea.node.addComponent(cc.Button);
this.picArea.node.on('click', () => {
if (!this._cantouch) {
return;
}
//设置不可点击
this._cantouch = false;
this.picArea.click(() => {
//设置可点击
this._cantouch = true;
});
})
}
private initWordArea() {
const getWord = (val, color, audioUrl) => {
let word = new Word(this.cat);
let valArr = getLetterArr(val);
word.data = valArr;
word.audioUrl = audioUrl;
word.buildWordNode(color);
word.node.addComponent(cc.Button);
word.node.opacity = 0;
return word;
}
this.wordArea = new WordArea();
this.wordArea.node = cc.find("Canvas/center/row");
this.wordArea.data = this.data.exercises;
//单词数组
let wordArr = this.wordArea.data.wordArr;
const word1 = getWord(wordArr[0].val, wordArr[0].fontColor, wordArr[0].audioUrl);
this.wordArea.addWord(word1);
const word2 = getWord(wordArr[1].val, wordArr[1].fontColor, wordArr[1].audioUrl);
this.wordArea.addWord(word2);
const word3 = getWord(wordArr[0].val + wordArr[1].val, wordArr[2].fontColor, wordArr[2].audioUrl);
this.wordArea.addWord(word3);
this.wordArea2 = new WordArea2(this.cat, this.data.exercises.wordArr2);
this.wordArea2.init();
}
playLocalAudio(audioName, callback = null) {
const audio = cc.find(`Canvas/res/audio/${audioName}`).getComponent(cc.AudioSource);
......@@ -51,4 +193,173 @@ export default class SceneComponent extends MyCocosSceneComponent {
});
})
}
/**
* 开始游戏
*/
beginGame() {
const play = () => {
this.cat.playAni('normal', 0);
this.cat.canTouch = true;
//依次播放卡片
this.play(this.wordArea, 0);
}
if (this.data.guideAudioUrl1) {
//播放开始动画
this.cat.playAni('begin', 0);
//播放引导音频1
this.playAudioByUrl(this.data.guideAudioUrl1, () => {
play();
});
}
else {
play();
}
}
/**
* 播放卡片
* @param wordArea
* @param index
*/
play(wordArea: WordArea, index = 0) {
let word = wordArea.wordArr[index];
if (index == 0) {
wordArea.show();
cc.tween(wordArea.wordArr[0].node).to(0.1, { opacity: 255 }).start();
cc.tween(wordArea.wordArr[1].node).to(0.1, { opacity: 255 }).start();
}
if (index == 2) {
wordArea.equalNode.active = true;
cc.tween(wordArea.wordArr[index].node).to(0.1, { opacity: 255 }).start();
}
word.click(() => {
if (index == 2) {
this.playTimes++;
if (this.playTimes == 1) {
this.play(this.wordArea, 0);
}
else if (this.playTimes >= this.MAX_PLAY_TIMES) {
//显示下一行
this.wordArea2.show(()=>{
this.play2(0);
});
}
}
else {
this.play(wordArea, index + 1);
}
})
}
play2(index = 0) {
let wordArea = this.wordArea2;
let word = wordArea.wordArr[index];
word.show();
word.click(()=> {
if(index === this.wordArea2.wordArr.length - 1){
this.showEnd();
}
else{
word.hide();
this.play2(index + 1);
}
});
}
/**
* 显示结束画
*/
showEnd() {
console.log("play end...");
this._end = true;
if (this.data.guideAudioUrl3) {
//设置屏幕不可点击
this._cantouch = false;
const state = this.cat.playAni('begin', 0);
this.playAudioByUrl(this.data.guideAudioUrl3, () => {
//设置屏幕可点击
this._cantouch = true;
state.stop();
this.cat.playAni('normal', 0);
onHomeworkFinish();
})
} else {
onHomeworkFinish();
}
//设置所有卡片可点击
for (let i = 0; i < this.wordArea.wordArr.length; ++i) {
let word = this.wordArea.wordArr[i];
word.canTouch = true;
//移除点击事件
word.node.off('click');
//绑定新事件
word.node.on('click', () => {
if (!this._cantouch) {
return;
}
this._cantouch = false;
word.click(() => {
this._cantouch = true;
});
})
}
this.wordArea2.card.on('click', ()=>{
if (!this._cantouch) {
return;
}
this._cantouch = false;
this.wordArea2.click(()=>{
this._cantouch = true;
})
})
}
}
import SceneComponent from "../scene/OP71";
import { Item } from "./Item";
export class Cat extends Item {
private _animationState: dragonBones.AnimationState;
private _scene: SceneComponent;
/**
* 是否待机状态
*/
private _standby = false;
set standby(standby: boolean) {
this._standby = standby;
}
get standby() {
return this._standby;
}
constructor(scene: SceneComponent) {
super();
this._scene = scene;
this._node = cc.find('Canvas/cat');
}
playAni(name, times = 1, cb = null) {
if (this._animationState && this._animationState.name != name) {
this._animationState.stop();
}
const cat = this.node;
var dragonDisplay = cat.getComponent(dragonBones.ArmatureDisplay);
const state = dragonDisplay.playAnimation(name, times);
dragonDisplay.on(dragonBones.EventObject.COMPLETE, () => {
if (cb) {
cb();
}
})
this._animationState = state;
return state;
}
stopAni() {
if (!this._animationState) {
return;
}
this._animationState.stop();
this._animationState = null;
}
init() {
let btn = cc.find('click', this.node);
btn.on('click', () => {
if (!this.canTouch) {
return;
}
if (this.standby) {
return;
}
this.standby = true;
this._scene._cantouch = false;
let audoUrl = this.data.guideAudioUrl2;
//播放待机音频
if (audoUrl) {
//播放待机动画
this.playAni('begin', 0);
//播放完成,停止动画
this._scene.playAudioByUrl(audoUrl, () => {
this.playAni('normal', 0);
this.standby = false;
this._scene._cantouch = true;
});
}
else {
this.playAni('normal', 0);
this.standby = false;
this._scene._cantouch = true;
}
});
}
}
\ No newline at end of file
{
"ver": "1.0.8",
"uuid": "f591ab98-1a21-487f-aecc-b13e02e4acf8",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
This diff is collapsed.
{
"ver": "1.0.8",
"uuid": "1f1747e7-323b-412f-af13-29b226a9d4d5",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
export class Item{
/**
* 是否可以点击或者触摸
*/
protected _canTouch = true;
/**
* 节点包含数据
*/
protected _data;
/**
* cocos节点
*/
protected _node;
set canTouch(canTouch : boolean){
this._canTouch = canTouch;
}
get canTouch(){
return this._canTouch;
}
set data(data){
this._data = data;
}
get data(){
return this._data;
}
set node(node){
this._node = node;
}
get node(){
return this._node;
}
}
\ No newline at end of file
{
"ver": "1.0.8",
"uuid": "97c29579-212e-4693-8a4f-029757b94001",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
import { Cat } from "./Cat";
import { Item } from "./Item";
import { delayCall, getSprNodeByUrl, playAudio } from "./util";
/**
* 图片区域对象
*/
export class PicArea extends Item {
private _picUrl: string;
private _audioUrl: string;
//晃动最大次数
readonly MAX_TIMES = 2;
private _audioClip: cc.AudioClip;
private _cat : Cat;
set picUrl(picUrl: string) {
this._picUrl = picUrl;
}
get picUrl() {
return this._picUrl;
}
set audioUrl(value: string) {
this._audioUrl = value;
//音频地址存在,则加载音频
if (this._audioUrl && this._audioUrl != "") {
cc.assetManager.loadRemote(this._audioUrl, (err, audioClip) => {
if(audioClip.duration === undefined) {
const audioId = cc.audioEngine.play(audioClip, false, 0.1);
setTimeout(() => {
audioClip.duration = cc.audioEngine.getDuration(audioId)
cc.audioEngine.pause(audioId)
}, 50);
}
this._audioClip = audioClip;
});
}
}
get audioUrl() {
return this._audioUrl;
}
constructor(cat: Cat){
super();
this._cat = cat;
}
/**
* 初始化
*/
init(){
this.picUrl = this.data.picUrl;
this.audioUrl = this.data.audioUrl;
getSprNodeByUrl(this.picUrl, (sprNode) => {
let pic = this.node;
const picNode = sprNode;
let scale = Math.min(pic.width / picNode.width, pic.height / picNode.height);
//如果图片需要放大,则不处理
if(scale > 1){
scale = 1;
}
picNode.scale = scale;
picNode.x = 0;
picNode.y = 0;
pic.addChild(picNode);
});
}
/**
* 图片点击事件
* @param callback
*/
click(callback = null) {
if (!this._canTouch) {
return;
}
this._canTouch = false;
//动画时长
let tweenDuration = 0.4;
let rotation = this._node.angle;
let times = 1;
const rota = () => {
cc.tween(this._node)
.to(tweenDuration / 4, { angle: rotation - 15 })
.to(tweenDuration / 4, { angle: rotation })
.to(tweenDuration / 4, { angle: rotation + 15 })
.to(tweenDuration / 4, { angle: rotation })
.call(() => {
if (times > this.MAX_TIMES) {
this._canTouch = true;
return;
}
times += 1;
rota();
})
.start();
}
//晃动图片
rota();
//播放音频
if (this._audioClip) {
this._cat.playAni('begin', 0);
playAudio(this._audioClip, () => {
this._cat.playAni('normal', 0);
});
}
if (callback) {
//获取音频时长
let duration = this._audioClip == null ? 0 : this._audioClip.duration;
//回调延迟时间
let timeout = tweenDuration;
//如果音频时长大于动画时长,则等音频播放完成后,再执行回待函数
if (duration > tweenDuration) {
timeout = duration;
}
delayCall(timeout, callback)
}
}
}
\ No newline at end of file
{
"ver": "1.0.8",
"uuid": "97ab62a3-5963-493b-9c18-b3c462cb2e6f",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
......@@ -156,7 +156,7 @@ export function getSprNodeByUrl(url, cb) {
getSpriteFrimeByUrl(url, (sf) => {
spr.spriteFrame = sf;
if (cb) {
cb(spr);
cb(node);
}
})
}
......@@ -464,3 +464,19 @@ export function callMiddleLayerFunction(apiName: string, data: any, callback: Fu
}
}
/**
* 延时操作
* @param time
* @param cb
* @returns
*/
export function delayCall(time, cb) {
return cc.tween({})
.delay(time)
.call(() => {
if (cb) {
cb();
}
})
.start();
}
\ No newline at end of file
assets/OP71/textures/card_1.png

3.34 KB | W: | H:

assets/OP71/textures/card_1.png

1.98 KB | W: | H:

assets/OP71/textures/card_1.png
assets/OP71/textures/card_1.png
assets/OP71/textures/card_1.png
assets/OP71/textures/card_1.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -7,8 +7,8 @@
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 247,
"height": 247,
"width": 124,
"height": 124,
"platformSettings": {},
"subMetas": {
"card_1": {
......@@ -22,10 +22,10 @@
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 247,
"height": 247,
"rawWidth": 247,
"rawHeight": 247,
"width": 124,
"height": 124,
"rawWidth": 124,
"rawHeight": 124,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
......
assets/OP71/textures/card_2.png

3.59 KB | W: | H:

assets/OP71/textures/card_2.png

2.08 KB | W: | H:

assets/OP71/textures/card_2.png
assets/OP71/textures/card_2.png
assets/OP71/textures/card_2.png
assets/OP71/textures/card_2.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -7,8 +7,8 @@
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 439,
"height": 247,
"width": 220,
"height": 124,
"platformSettings": {},
"subMetas": {
"card_2": {
......@@ -22,10 +22,10 @@
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 439,
"height": 247,
"rawWidth": 439,
"rawHeight": 247,
"width": 220,
"height": 124,
"rawWidth": 220,
"rawHeight": 124,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
......
assets/OP71/textures/card_3.png

4.12 KB | W: | H:

assets/OP71/textures/card_3.png

2.15 KB | W: | H:

assets/OP71/textures/card_3.png
assets/OP71/textures/card_3.png
assets/OP71/textures/card_3.png
assets/OP71/textures/card_3.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -7,8 +7,8 @@
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 885,
"height": 247,
"width": 317,
"height": 124,
"platformSettings": {},
"subMetas": {
"card_3": {
......@@ -22,10 +22,10 @@
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 885,
"height": 247,
"rawWidth": 885,
"rawHeight": 247,
"width": 317,
"height": 124,
"rawWidth": 317,
"rawHeight": 124,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
......
{
"ver": "2.3.5",
"uuid": "570b176d-eff0-4ef7-804f-3ef284db9cfa",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 443,
"height": 124,
"platformSettings": {},
"subMetas": {
"card_4": {
"ver": "1.0.4",
"uuid": "e613b588-b607-4250-9acb-dedf026fc117",
"rawTextureUuid": "570b176d-eff0-4ef7-804f-3ef284db9cfa",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 443,
"height": 124,
"rawWidth": 443,
"rawHeight": 124,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
assets/OP71/textures/equal.png

972 Bytes | W: | H:

assets/OP71/textures/equal.png

974 Bytes | W: | H:

assets/OP71/textures/equal.png
assets/OP71/textures/equal.png
assets/OP71/textures/equal.png
assets/OP71/textures/equal.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -7,8 +7,8 @@
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 42,
"height": 36,
"width": 22,
"height": 19,
"platformSettings": {},
"subMetas": {
"equal": {
......@@ -22,10 +22,10 @@
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 42,
"height": 36,
"rawWidth": 42,
"rawHeight": 36,
"width": 22,
"height": 19,
"rawWidth": 22,
"rawHeight": 19,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
......
......@@ -7,8 +7,8 @@
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 2371,
"height": 1109,
"width": 1186,
"height": 556,
"platformSettings": {},
"subMetas": {
"orange_plate": {
......@@ -22,10 +22,10 @@
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 2371,
"height": 1109,
"rawWidth": 2371,
"rawHeight": 1109,
"width": 1186,
"height": 556,
"rawWidth": 1186,
"rawHeight": 556,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
......
assets/OP71/textures/plus.png

1000 Bytes | W: | H:

assets/OP71/textures/plus.png

1006 Bytes | W: | H:

assets/OP71/textures/plus.png
assets/OP71/textures/plus.png
assets/OP71/textures/plus.png
assets/OP71/textures/plus.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -7,8 +7,8 @@
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 49,
"height": 49,
"width": 25,
"height": 25,
"platformSettings": {},
"subMetas": {
"plus": {
......@@ -22,10 +22,10 @@
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 49,
"height": 49,
"rawWidth": 49,
"rawHeight": 49,
"width": 25,
"height": 25,
"rawWidth": 25,
"rawHeight": 25,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
......
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