前端之家收集整理的这篇文章主要介绍了
Cocos2dx_背景层循环滚动,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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)
end
end
原文链接:https://www.f2er.com/cocos2dx/341751.html