加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Cocos2dx_背景层循环滚动

发布时间:2020-12-14 16:25:04 所属栏目:百科 来源:网络整理
导读:function MovieLayer:update(dt)local posY1 = self.m_bg1:getPositionY()local posY2 = self.m_bg2:getPositionY()local speed = 3posY1 = posY1 + speedposY2 = posY2 + speedlocal height = winSize.heightif posY1 height * 1.5 thenposY2 = height * 0.
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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读