@fire_spirit 写道:
一个爱消除游戏,开局通过for循环,掉落9×9一共81个块.
逻辑:
在for循环中计算出每个块的起始坐标,到达坐标,用node.runAction(cc.moveTo(...))方法,一切正常。
改进:
现在我想让块掉落到指定位置后,做一次缩放操作,显得活泼一些,所以在其他逻辑都不变的情况下,修改了一点点:
let scaleTime = 0.1;
let sacleSizeX = 0.7;
let sacleSizeY = 0.7;
let scaleSizeY1 = 0.8*sacleSizeY;
let scaleSizeY2 = 1.2*sacleSizeY;
let action1 = cc.scaleTo(scaleTime, sacleSizeX,scaleSizeY1);
let action2 = cc.scaleTo(scaleTime, sacleSizeX,scaleSizeY2);
let action3 = cc.scaleTo(scaleTime, sacleSizeX,sacleSizeY);let dropAct = cc.sequence(cc.moveTo(moveTime,endPosition),action1, action2, action3); candySprite.runAction(dropAct);
问题:
在块数量12个以内(比如3×4),以上逻辑都正常,但是当父节点内超过15个(5×5)的时候,我尝试在update()函数中打印了for循环中的第一个块的Y轴坐标getPositionY(),发现屏幕上块走到了指定的位置,可是getPositionY()中的出来的该块的Y轴却远远大于要掉落的位置。这直接导致了在后面的逻辑中,块的坐标不准确,无法判断到这个块在哪。问题提升:
同样的问题出现在删除块的时候,当3个或以上需要消除,直接销毁,是正常的,可是使用
candySpriteNode.runAction(cc.sequence(blinkAct,
cc.callFunc(function(){CSPool.put(candySpriteNode);},
this)));
同样使用的sequence,界面上补充掉落的块会随机消失(估计还是Y轴坐标的问题)结论:
感觉是因为同时执行了多个sequence,后面执行的影响到了前面的对象?但实际情况还是不明白。不知道是否有好的解决办法?
1、游戏初始化时,第一次全部掉落,直接采用moveTo,update打印出的第一个块的Y坐标(由于X坐标不需要移动,我打印出来看过,x是正常的):
2016-12-07T07:58:33.679Z - normal: Simulator: ------------------------------------------------2016-12-07T07:58:33.680Z - normal: Simulator: LOAD Js FILE: main.js
2016-12-07T07:58:33.681Z - normal: Simulator: ------------------------------------------------
2016-12-07T07:58:35.372Z - normal: Simulator: Cocos2d-JS v3.13
2016-12-07T07:58:35.764Z - normal: Simulator: iShow!
2016-12-07T07:58:36.415Z - normal: Simulator: 矩阵左下角点的坐标X:275 Y:375
2016-12-07T07:58:36.553Z - normal: Simulator: *块Y坐标:1335
2016-12-07T07:58:36.563Z - normal: Simulator: *块Y坐标:1335
2016-12-07T07:58:36.609Z - normal: Simulator: *块Y坐标:1268.724853515625
2016-12-07T07:58:36.613Z - normal: Simulator: *块Y坐标:1230.0660400390625
2016-12-07T07:58:36.614Z - normal: Simulator: *块Y坐标:1188.645751953125
2016-12-07T07:58:36.669Z - normal: Simulator: *块Y坐标:1147.2255859375
2016-12-07T07:58:36.671Z - normal: Simulator: *块Y坐标:1105.8052978515625
2016-12-07T07:58:36.677Z - normal: Simulator: *块Y坐标:1064.3851318359375
2016-12-07T07:58:36.694Z - normal: Simulator: *块Y坐标:1020.2034912109375
2016-12-07T07:58:36.696Z - normal: Simulator: *块Y坐标:973.2578125
2016-12-07T07:58:36.861Z - normal: Simulator: *块Y坐标:929.0762329101562
2016-12-07T07:58:36.868Z - normal: Simulator: *块Y坐标:694.3505859375
2016-12-07T07:58:36.870Z - normal: Simulator: *块Y坐标:636.3594970703125
2016-12-07T07:58:36.870Z - normal: Simulator: *块Y坐标:589.413818359375
2016-12-07T07:58:36.873Z - normal: Simulator: *块Y坐标:547.9935913085938
2016-12-07T07:58:36.880Z - normal: Simulator: *块Y坐标:512.0960693359375
2016-12-07T07:58:36.886Z - normal: Simulator: *块Y坐标:465.15313720703125
2016-12-07T07:58:36.898Z - normal: Simulator: *块Y坐标:420.9688720703125
2016-12-07T07:58:36.923Z - normal: Simulator: *块Y坐标:376.78729248046875
2016-12-07T07:58:36.925Z - normal: Simulator: *块Y坐标:375
2016-12-07T07:58:36.941Z - normal: Simulator: *块Y坐标:375
2016-12-07T07:58:36.982Z - normal: Simulator: *块Y坐标:375
2、当采用sequence来并行几十个块掉落并执行缩放的时候,他会掉落到固定位置,也会在到达目的地之后执行缩放,可是打印出来的getPositionY()值变成这样,走一小段就停了
2016-12-07T08:09:47.054Z - normal: Simulator: 矩阵左下角点的坐标X:275 Y:375
2016-12-07T08:09:47.090Z - normal: Simulator: *块Y坐标:1335
2016-12-07T08:09:47.108Z - normal: Simulator: *块Y坐标:1335
2016-12-07T08:09:47.112Z - normal: Simulator: *块Y坐标:1312.9091796875
2016-12-07T08:09:47.130Z - normal: Simulator: *块Y坐标:1282.534423828125
2016-12-07T08:09:47.148Z - normal: Simulator: *块Y坐标:1235.5887451171875
2016-12-07T08:09:47.170Z - normal: Simulator: *块Y坐标:1191.4071044921875
2016-12-07T08:09:47.180Z - normal: Simulator: *块Y坐标:1144.46142578125
2016-12-07T08:09:47.230Z - normal: Simulator: *块Y坐标:1097.5185546875
2016-12-07T08:09:47.231Z - normal: Simulator: *块Y坐标:1097.5185546875
2016-12-07T08:09:47.247Z - normal: Simulator: *块Y坐标:1097.5185546875
可以看到获取的Y轴坐标,并没有掉落到指定的矩阵要求的第一个位置,但实际上块已经掉落到那里了。
实在是调了2周,都没有办法解决这个问题,还请大家帮帮忙看看。
重点:
1、直接运行某一个动画(比如moveTo,NodePool.put()),游戏不会有任何问题,采用sequence运行一系列动画,会出现各种问题。
2、块的数量少,不容易出问题,块越多,问题越明显。到底是sequence不能这么用,不能同时大量对象并发,会互相影响,还是怎么回事?!!!
帖子: 7
参与者: 1