Commit 244f5e8e authored by 范雪寒's avatar 范雪寒

feat: 现在坑与胡萝卜都可以移动了

parent b46887f3
......@@ -28,6 +28,8 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
carrotImg: '',
carrotAudio: '',
holeImg: '',
carrotOffset: { x: 0, y: 0 },
holeOffset: { x: 0, y: 0 }
});
if (saveFlg) {
this.save();
......@@ -143,7 +145,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
(<any>window).courseware.setData(this.item, null, this.saveKey);
this.refresh();
this.previewCanvas.refresh(this.item);
}
/**
......
......@@ -7,29 +7,40 @@ export let defaultData = {
},
carrots: [{
carrotImg: 'carrot',
holeImg: 'hole',
carrotImg: 'carrot1',
carrotAudio: 'child',
carrotOffset: { x: 0, y: 0 },
holeImg: 'hole1',
holeOffset: { x: 0, y: 0 }
}, {
carrotImg: 'carrot',
holeImg: 'hole',
carrotImg: 'carrot1',
carrotAudio: 'knight',
carrotOffset: { x: 0, y: 0 },
holeImg: 'hole2',
holeOffset: { x: 0, y: 0 }
}, {
carrotImg: 'carrot',
holeImg: 'hole',
carrotImg: 'carrot2',
carrotAudio: 'children',
carrotOffset: { x: 0, y: 0 },
holeImg: 'hole3',
holeOffset: { x: 0, y: 0 }
}, {
carrotImg: 'carrot',
holeImg: 'hole',
carrotImg: 'carrot1',
carrotAudio: 'ddbbbbcccc',
carrotOffset: { x: 0, y: 0 },
holeImg: 'hole4',
holeOffset: { x: 0, y: 0 }
}, {
carrotImg: 'carrot',
holeImg: 'hole',
}, {
carrotImg: 'carrot',
holeImg: 'hole',
}, {
carrotImg: 'carrot',
holeImg: 'hole',
}, {
carrotImg: 'carrot',
holeImg: 'hole',
carrotImg: 'carrot2',
carrotAudio: 'eeebbbbcccc',
carrotOffset: { x: 0, y: 0 },
holeImg: 'hole5',
holeOffset: { x: 0, y: 0 }
}],
targets: []
targets: [{
x: -530,
y: -270,
targetImg: 'target',
targetAudio: 'kn'
}]
};
\ No newline at end of file
......@@ -195,12 +195,47 @@ export class MyGame extends Game {
this.data.carrots.forEach((carrot, idx) => {
let carrotSp = new TouchSprite();
carrotSp.init(this.images.get(carrot.carrotImg));
carrotSp.setPositionX(this.bg.width / length * (idx - (length - 1) / 2));
carrotSp.setPositionY(-550);
carrotSp.setPositionX(this.data.carrots[idx].carrotOffset.x + this.bg.width / length * (idx - (length - 1) / 2));
carrotSp.setPositionY(this.data.carrots[idx].carrotOffset.y - 550);
this.bg.addChild(carrotSp);
carrotSp.addTouchBeganListener((pos) => {
this.onCarrotSpTouchBengan(pos, carrotSp, idx);
});
carrotSp.addTouchMoveListener((pos) => {
this.onCarrotSpTouchMoved(pos, carrotSp, idx);
});
carrotSp.addTouchEndListener(() => {
this.onCarrotSpTouchEnded();
});
});
}
onCarrotSpTouchBengan({ x, y }, carrotSp, idx) {
carrotSp.set('touchStartPos', { x, y });
carrotSp.set('startPos', { x: carrotSp.x, y: carrotSp.y });
carrotSp.set('startOffset', {
x: this.data.carrots[idx].carrotOffset.x,
y: this.data.carrots[idx].carrotOffset.y,
});
}
onCarrotSpTouchMoved({ x, y }, carrotSp, idx) {
if (this._editMode) {
let spritePosX = carrotSp.get('startPos').x + (x - carrotSp.get('touchStartPos').x) / this._parent.mapScale;
let spritePosY = carrotSp.get('startPos').y + (y - carrotSp.get('touchStartPos').y) / this._parent.mapScale;
carrotSp.setPositionX(spritePosX);
carrotSp.setPositionY(spritePosY);
this.data.carrots[idx].carrotOffset.x = spritePosX - carrotSp.get('startPos').x + carrotSp.get('startOffset').x;
this.data.carrots[idx].carrotOffset.y = spritePosY - carrotSp.get('startPos').y + carrotSp.get('startOffset').y;
}
}
onCarrotSpTouchEnded() {
if (this._editMode) {
this._save();
}
}
createHoles() {
let screenSize = this.getScreenSize();
let defaultSize = this.getDefaultScreenSize();
......@@ -210,12 +245,49 @@ export class MyGame extends Game {
hole.init(this.images.get(carrot.holeImg));
hole.anchorX = 0.5;
hole.anchorY = 0;
hole.setPositionX(this.bg.width / length * (idx - (length - 1) / 2));
hole.setPositionY(-520);
hole.setPositionX(this.data.carrots[idx].holeOffset.x + this.bg.width / length * (idx - (length - 1) / 2));
hole.setPositionY(this.data.carrots[idx].holeOffset.y - 520);
this.bg.addChild(hole);
hole.addTouchBeganListener((pos) => {
this.onHoleTouchBengan(pos, hole, idx);
});
hole.addTouchMoveListener((pos) => {
this.onHoleTouchMoved(pos, hole, idx);
});
hole.addTouchEndListener(() => {
this.onHoleTouchEnded();
});
});
}
onHoleTouchBengan({ x, y }, hole, idx) {
hole.set('touchStartPos', { x, y });
hole.set('startPos', { x: hole.x, y: hole.y });
hole.set('startOffset', {
x: this.data.carrots[idx].holeOffset.x,
y: this.data.carrots[idx].holeOffset.y,
});
}
onHoleTouchMoved({ x, y }, hole, idx) {
if (this._editMode) {
let spritePosX = hole.get('startPos').x + (x - hole.get('touchStartPos').x) / this._parent.mapScale;
let spritePosY = hole.get('startPos').y + (y - hole.get('touchStartPos').y) / this._parent.mapScale;
hole.setPositionX(spritePosX);
hole.setPositionY(spritePosY);
this.data.carrots[idx].holeOffset.x = spritePosX - hole.get('startPos').x + hole.get('startOffset').x;;
this.data.carrots[idx].holeOffset.y = spritePosY - hole.get('startPos').y + hole.get('startOffset').y;;
}
}
onHoleTouchEnded() {
if (this._editMode) {
this._save();
}
}
createWords() {
let screenSize = this.getScreenSize();
let defaultSize = this.getDefaultScreenSize();
......@@ -226,14 +298,13 @@ export class MyGame extends Game {
targetSp.setPositionX(targetData.x);
targetSp.setPositionY(targetData.y);
targetSp.addTouchBeganListener(({ x, y }) => {
this.onTargetSpTouchBengan({ x, y }, targetSp, idx);
targetSp.addTouchBeganListener((pos) => {
this.onTargetSpTouchBengan(pos, targetSp, idx);
});
targetSp.addTouchMoveListener(({ x, y }) => {
this.onTargetSpTouchMoved({ x, y }, targetSp, idx);
targetSp.addTouchMoveListener((pos) => {
this.onTargetSpTouchMoved(pos, targetSp, idx);
});
targetSp.addTouchEndListener(()=>{
targetSp.addTouchEndListener(() => {
this.onTargetSpTouchEnded();
});
......@@ -248,9 +319,6 @@ export class MyGame extends Game {
onTargetSpTouchMoved({ x, y }, targetSp, idx) {
if (this._editMode) {
let screenSize = this.getScreenSize();
let defaultSize = this.getDefaultScreenSize();
let spritePosX = targetSp.get('startPos').x + (x - targetSp.get('touchStartPos').x) / this._parent.mapScale;
let spritePosY = targetSp.get('startPos').y + (y - targetSp.get('touchStartPos').y) / this._parent.mapScale;
targetSp.setPositionX(spritePosX);
......
......@@ -9,23 +9,33 @@ export let defaultData = {
carrots: [{
carrotImg: 'carrot1',
carrotAudio: 'child',
carrotOffset: { x: 0, y: 0 },
holeImg: 'hole1',
holeOffset: { x: 0, y: 0 }
}, {
carrotImg: 'carrot1',
carrotAudio: 'knight',
carrotOffset: { x: 0, y: 0 },
holeImg: 'hole2',
holeOffset: { x: 0, y: 0 }
}, {
carrotImg: 'carrot2',
carrotAudio: 'children',
carrotOffset: { x: 0, y: 0 },
holeImg: 'hole3',
holeOffset: { x: 0, y: 0 }
}, {
carrotImg: 'carrot1',
carrotAudio: 'ddbbbbcccc',
carrotOffset: { x: 0, y: 0 },
holeImg: 'hole4',
holeOffset: { x: 0, y: 0 }
}, {
carrotImg: 'carrot2',
carrotAudio: 'eeebbbbcccc',
carrotOffset: { x: 0, y: 0 },
holeImg: 'hole5',
holeOffset: { x: 0, y: 0 }
}],
targets: [{
x: -530,
......
......@@ -64,7 +64,7 @@ export class MyGame extends Game {
preLoadData(imgUrlList, audioUrlList) {
imgUrlList.forEach((data) => {
this._parent.addUrlToImages(data)
this._parent.addUrlToImages(data);
});
audioUrlList.forEach((data) => {
this._parent.addUrlToAudioObj(data);
......@@ -109,7 +109,7 @@ export class MyGame extends Game {
// 背景
let bg = new TouchSprite();
bg.init(this.images.get('Img_bg2'))
bg.init(this.images.get('Img_bg2'));
bg.setScaleXY(this._parent.mapScale);
bg.alpha = 0;
bg.anchorX = 0.5;
......@@ -201,8 +201,8 @@ export class MyGame extends Game {
this.data.carrots.forEach((carrot, idx) => {
let carrotSp = new TouchSprite();
carrotSp.init(this.images.get(carrot.carrotImg));
carrotSp.setPositionX(this.bg.width / length * (idx - (length - 1) / 2));
carrotSp.setPositionY(-550);
carrotSp.setPositionX(this.data.carrots[idx].carrotOffset.x + this.bg.width / length * (idx - (length - 1) / 2));
carrotSp.setPositionY(this.data.carrots[idx].carrotOffset.y - 550);
this.bg.addChild(carrotSp);
carrotSp.addTouchBeganListener(() => {
......@@ -224,8 +224,8 @@ export class MyGame extends Game {
hole.init(this.images.get(carrot.holeImg));
hole.anchorX = 0.5;
hole.anchorY = 0;
hole.setPositionX(this.bg.width / length * (idx - (length - 1) / 2));
hole.setPositionY(-520);
hole.setPositionX(this.data.carrots[idx].holeOffset.x + this.bg.width / length * (idx - (length - 1) / 2));
hole.setPositionY(this.data.carrots[idx].holeOffset.y - 520);
this.bg.addChild(hole);
});
}
......
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