无限循环背景ParallaxNode

无限循环背景

void  ParallaxNode::incrementoffset(Point offset, Node*  node)
{
	for (unsigned int i = 0; i < _parallaxArray->num; ++i)
	{
		PointObject*  point = (PointObject*)_parallaxArray->arr[i];
		Node*  curNode = point->getChild();
		if (curNode == node)
		{
			point->setOffset(point->getOffset()+ offset);
		}
	}
}
每移动一完就incrementoffset
function InfiniteBg:update(dt)
	for k,bg in pairs(self.bgs) do
		local p = cc.p(bg:getPosition())
		local width = bg:getContentSize().width;
		p = self:convertToWorldSpace(p)
		if (p.x < -width) then 
			print("[InfiniteBg] : repeat bg")
			self:incrementoffset(cc.p(width,0),bg);
		end
	end
end




你可能感兴趣的:(cocos2d-x)