removeTileAt() Works but buggy?


#1

Can someone confirm this works perfect?

During play…if i remove 3 or 4 tiles from a layer…it randomly removes others…and jumps about…


#2

Hi, elgan

Can you post some screen shot and code? Normally, there is no bug for removeTileAt

Huabin


#3

http://postimg.org/image/vxq0bwqhf/


#4

sometimes a crash with

“Start offset is negative”


#5

So i changed test4 of samples to just loop and remove, sometimes at two points it gets it wrong. There is something wrong with it…picking the wrong index or updating the wrong indexes…

please ignore ugly quick code.

var TMXOrthoTest4 = TileDemo.extend({

    x:0,
    y:0,

    ctor:function () {


        this._super();
        var map = cc.TMXTiledMap.create(s_resprefix + "TileMaps/orthogonal-test4.tmx");
        this.addChild(map, 0, TAG_TILE_MAP);

        map.setAnchorPoint(0, 0);

        var layer = map.getLayer("Layer 0");
        var s = layer.getLayerSize();

        this.x = s.width - 1;
        this.y = s.height - 1;

        var sprite;
        sprite = layer.getTileAt(cc.p(0, 0));
        sprite.setScale(2);

        sprite = layer.getTileAt(cc.p(s.width - 1, 0));
        sprite.setScale(2);

        sprite = layer.getTileAt(cc.p(0, s.height - 1));
        sprite.setScale(2);

        sprite = layer.getTileAt(cc.p(s.width - 1, s.height - 1));
        sprite.setScale(2);

        this.schedule(this.onRemoveSprite, 0.1);

    },
    onRemoveSprite:function (dt) {
        var map = this.getChildByTag(TAG_TILE_MAP);

        var layer = map.getLayer("Layer 0");
        var layerSize = layer.getLayerSize();


        if(this.y == 0 && this.x == 0)
        {
            return;
        }
        this.x--;
        if(this.x < 0)
        {
            if(this.y > 0)
            {
                this.x = layerSize.width - 1;
            }
            else
            {
                this.x = 0;
            }

            this.y--;

        }
        console.log(" x " + this.x + " y " + this.y );

        var sprite = layer.getTileAt(cc.p(this.x, this.y));

        layer.removeChild(sprite, true);

    },
    title:function () {
        return "TMX width/height test";
    },

#6

Hi, Elgan

We confirmed that it’s a bug which happens only on WEBGL render mode, we will try to fix it. You can temporarily switch to canvas render mode, there shouldn’t be any problem.
Thanks

Huabin


#7

wow…i love you…works perfect now as far as initial testing goes.


#8

:slight_smile:


#9

貌似这个问题还没解决?
我也碰到了这个问题,renderMode 改为 1 就正常了。
我的例子是这样:版本 cocos2d-js 3.0 rc0

    var map = cc.TMXTiledMap.create("res/map/test-object-layer.tmx");
    this.addChild(map);

    var tiles = [];
    var layer = map.getLayer("Layer 0");

    for(var i=0; i<4; i++){
	    var tile = layer.getTileAt(cc.p(i, 0));
	    tiles.push(tile);
    }

    for(var i=0; i<4; i++){
	    var tile = tiles[i];
	    layer.removeChild(tile, true);
    }

#10

查了我一下午 T_T,原来这个问题早就有了


#11

renderMode 改为1后,又发现了另一个bug,这个bug在renderMode为0时不存在!到底还能不能愉快的玩耍了!!!不给活路啊 亲!!!!