function MovIELayer:update(dt) local posY1 = self.m_bg1:getpositionY() local posY2 = self.m_bg2:getpositionY() local speed = 3 posY1 = posY1 + speed posY2 = posY2 + speed local height = winSize.height if posY1 > height * 1.5 then posY2 = height * 0.5 posY1 = -height * 0.5 end if posY2 > height * 1.5 then posY1 = height * 0.5 posY2 = -height * 0.5 end self.m_bg1:setpositionY(posY1) self.m_bg2:setpositionY(posY2)end
function MovIELayer:init() local m_bg1 = cc.Sprite:create("game_bg1.png") m_bg1:setposition(cc.p(winSize.wIDth/2,winSize.height/2)) self:addChild(m_bg1) self.m_bg1 = m_bg1 local m_bg2 = cc.Sprite:create("game_bg1.png") m_bg2:setposition(cc.p(winSize.wIDth/2,-winSize.height/2)) self:addChild(m_bg2) self.m_bg2 = m_bg2 local function updateFunc(dt) self:update(dt) end if self.updateHandler == nil then self.updateHandler = scheduler:scheduleScriptFunc(updateFunc,false) endend总结
以上是内存溢出为你收集整理的Cocos2dx_背景层循环滚动全部内容,希望文章能够帮你解决Cocos2dx_背景层循环滚动所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)