I need help, figure‘s X position loaded into the HTML is not accurate


(Hyjz Ref) #1

this is my design in Tiled:


**I want to load the image in black box, but the cocos actually loaded in the red box image.**This looks like the cocos when calculating the horizontal position to the right more added a grid position…
this is my image in html:
QQ截图20171023204628
I originally guess atlas is too large, tried many times to the size of the atlas decrease but the problem still exists.
have not found a similar situation in network, I will study the cocos source if cant find a solution
Engine: cocos2d - HTML 3.12
Tiled: v1.0.3

**我想加载黑色框中的图像,但是我实际加载出来的是红色框中的图像。**这看起来就像是cocos在计算水平位置时多往右加了一个格子的位置 …
我原本猜测是图集过大导致的,试过多次将图集的大小减小但是这个问题依然存在。
搜索了很多资料没有发现类似的情况,如果再找不到解决办法就只有去研究cocos源码了…
引擎:cocos2d-html 3.12
Tiled:v1.0.3


(Thorbjørn Lindeijer) #2

Since this is probably a bug in cocos2d-html5, it could be better to open an issue about it on their bug tracker: https://github.com/cocos2d/cocos2d-html5/issues

It seems indeed to be off by one, so it is likely some problem in their code. If you’re using a non-zero margin, this may be the problem:

Since the expression should only subtract the margin once and not twice (since it’s irrelevant whether the margin exists also at the bottom or the right side of the image).


(Thorbjørn Lindeijer) #3

I’ve opened the following pull request for this:

https://github.com/cocos2d/cocos2d-html5/pull/3537


(Hyjz Ref) #4

Thank you very much for your help. I have found the solution to the problem, and I have finally solved the BUG that has been bothering me for several nights.
Probably because of the different cocos version, the code snippet that you point to is not found in my engine file.But it led me to another place where the cocos team seems to know the Bug but it’s not fixed now:


I changed 0 to 1 and the problem was solved.
Very happy!
QQ截图20171026234134


(Thorbjørn Lindeijer) #5

Ah, this is a bug in handling external tilesets, where they need to load this firstgid attribute from the map file and not the tileset file. Your fix probably only works in case the map is only using a single tileset.

It seems like their commented code should fix the problem. I wonder why it is commented out.