Commit 1cdcf8a7 authored by linzhiguo's avatar linzhiguo

# 命中组优化

parent 6e8cea61
......@@ -293,7 +293,10 @@ cc.Class({
return;
//this._moved = true;
this._touched = false;
if (selected.target){
selected.target.active = true;
selected.target = null;
}
selected.node.x = selected.cx;
selected.node.y = selected.cy;
}, this);
......@@ -304,23 +307,26 @@ cc.Class({
return;
let item, area, len = this._kind_group.node.childrenCount;
let i = 0;
for(i = 0; i < len; i++){
let dis = 99999999, idx = -1;
for(let i = 0; i < len; i++){
item = this._kind_group.node.children[i];
area = item.getChildByName('layout_area');
let rect = area.getBoundingBoxToWorld();
rect.width -= 20;
rect.x += 10;
if (cc.rect(rect).intersects(cc.rect(selected.node.getBoundingBoxToWorld()))){
// console.log(i);
// console.log(item.getBoundingBoxToWorld());
let kind = item.getComponent(cc.js.getClassByName('WordKind'));
if (kind.kind_id != selected.kind_id){
//this.playAudioByName('incorrect');
//break;
continue;
let _dis = cc.Vec2.squaredDistance(item.convertToWorldSpaceAR(cc.v2(0,0)), selected.node.convertToWorldSpaceAR(cc.v2(0,0)));
if (dis > _dis){
dis = _dis;
idx = i;
}
}
}
if (idx >= 0){
item = this._kind_group.node.children[idx];
let kind = item.getComponent(cc.js.getClassByName('WordKind'));
if (kind.kind_id == selected.kind_id){
this.playAudioByName('correct');
let node = cc.instantiate(cc.find('res/option_item'));
let ot = node.getComponent(cc.js.getClassByName('WordOption'));
......@@ -332,25 +338,15 @@ cc.Class({
if (this.tryFinish())
this.pageFinish();
});
// cc.tween(this)
// .delay(0.2)
// .call(()=>{
ot.playAudio();
// })
// .start();
//this._xs[i%2] += selected.target._w;
selected.target.active = false;
//selected.target.removeFromParent();
selected.target = null;
break;
}
}
if (i == len){
else{
this.playAudioByName('incorrect');
}
this._moved = true;
this._touched = false;
if (selected.target){
......
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