Cocos2d-x_创建多个滚动层(每层速度不同)

Cocos2d-x_创建多个滚动层(每层速度不同),第1张

概述local scheduler = cc.Director:getInstance():getScheduler() local winSize = cc.Director:getInstance():getWinSize() --创建循环地图 local function createLoopMap(name, tag) local width = 1536 local m_b
	local scheduler = cc.Director:getInstance():getScheduler()	local winSize = cc.Director:getInstance():getWinSize()	--创建循环地图	local function createLoopMap(name,tag)		local wIDth = 1536		local m_bg1 = cc.Sprite:create(name)		m_bg1:setAnchorPoint(cc.p(0,0))		m_bg1:setposition(cc.p(0,0))		m_bg1:setTag(111)		local m_bg2 = cc.Sprite:create(name)		m_bg2:setAnchorPoint(cc.p(0,0))		m_bg2:setposition(cc.p(winSize.wIDth,0))		m_bg2:setTag(222)			local node = cc.Node:create()		node:addChild(m_bg1)		node:addChild(m_bg2)		node:setTag(tag)		return node	end		local m_bg1 = createLoopMap("bg1.jpg",1)    self.m_bg1 = m_bg1        local m_bg2 = createLoopMap("crop.png",2)      self.m_bg2 = m_bg2  		self.panel.layer:addChild(m_bg1)	self.panel.layer:addChild(m_bg2)	    local function updateFunc(dt)  		for	i = 1,2 do			local node = self.panel.layer:getChildByTag(i)			local bg1 = node:getChildByTag(111)			local bg2 = node:getChildByTag(222)						local posX1 = bg1:getpositionX()  			local posX2 = bg2:getpositionX()						local speed = 0			if i == 1 then				speed = 5.0			elseif i == 2 then				speed = 10.0			end						posX1 = posX1 - speed  			posX2 = posX2 - speed  			local wIDth = winSize.wIDth  		  			if posX1 < -wIDth then				posX2 = 0  				posX1 = wIDth  			end  		  			if posX2 < -wIDth then				posX1 = 0				posX2 = wIDth 			end  		  			bg1:setpositionX(posX1)  			bg2:setpositionX(posX2) 		end    end        if self.updateHandler == nil then          self.updateHandler = scheduler:scheduleScriptFunc(updateFunc,false)      end  
总结

以上是内存溢出为你收集整理的Cocos2d-x_创建多个滚动层(每层速度不同)全部内容,希望文章能够帮你解决Cocos2d-x_创建多个滚动层(每层速度不同)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1069120.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存