Consider that I have an PNG file for background sprite. I create two sprites with that image. And I put them next to each other like this:
Sprite * green_hills = Sprite::create("green_hills.png");
green_hills->setPosition(0,0);
green_hills->setAnchorPoint(Point(0.0,0.0));
Sprite * green_hills2 = Sprite::create("green_hills.png");
green_hills2->setPosition(green_hills2->getBoundingBox().size.width, 0);
green_hills2->setAnchorPoint(Point(0.0,0.0));
Sprite * green_hills_bg = Sprite::create();
green_hills_bg->addChild(green_hills, 1);
green_hills_bg->addChild(green_hills2, 1);
addChild(green_hills_bg);
This works fine!
The problem starts if I want to use batch node for reducing draw calls. First of all you have to create the green_hills_bg
sprite with an image which is present in the sprite sheet, otherwise when you do m_spritebatch->addChild(green_hills_bg);
, application crashes. Therefore I have added a one pixel sized dot into the sprite sheet and have done this:
SpriteBatchNode* m_spritebatch = SpriteBatchNode::create("imgs.png");
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("imgs.plist");
Sprite * green_hills = Sprite::createWithSpriteFrameName("green_hills.png");
green_hills->setPosition(0,0);
green_hills->setAnchorPoint(Point(0.0,0.0));
Sprite * green_hills2 = Sprite::createWithSpriteFrameName("green_hills.png");
green_hills2->setPosition(green_hills2->getBoundingBox().size.width, 0);
green_hills2->setAnchorPoint(Point(0.0,0.0));
Sprite * green_hills_bg = Sprite::createWithSpriteFrameName("blank_dot.png");
green_hills_bg->addChild(green_hills, 1);
green_hills_bg->addChild(green_hills2, 1);
m_spritebatch->addChild(green_hills_bg);
But in this case I see the boundary between green_hills
and green_hills2
sprites. Please see the first attached image below.
Another interesting thing is that this line disappears in some position of the container sprite and is some positions appears.
Also I have tried to overlap these sprites by one pixel, and I have another line between there two sprites (see the second attached image).
And this is not because of the scolling motions as far as I have captured images from the static states.
Capture.PNG (62.4 KB)
Capture.PNG (65.8 KB)