1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| local GameBackGround = class("GameBackGround", function() return display.newLayer("GameBackGround") end)
GameBackGround.bk_ = {} GameBackGround.bkSize_ = 0
function GameBackGround:ctor() self.bk_[0] = display.newSprite("main_bg_grass_left.jpg" , display.cx, display.cy) self.bk_[0]:setAnchorPoint(0,0) self.bk_[0]:setPosition(0,0) self:addChild(self.bk_[0]) self.bk_[1] = display.newSprite("main_bg_grass_right.jpg" , display.cx, display.cy) self.bk_[1]:setAnchorPoint(0,0) self.bk_[1]:setPosition(display.cx*2,0) self:addChild(self.bk_[1]) self.bkSize_ = 2 end
function GameBackGround:Update(nx) local tx = display.cx/2 if nx > tx then self:setPositionX(display.cx/2-nx) num = math.floor(nx/display.cx/2) xx = nx - num*display.cx*2 bk = {} for var=0, self.bkSize_ do bk[var] = self.bk_[math.mod(num + var, 2)] end if xx > tx then for var=0, self.bkSize_-1 do print("var", var) bk[var]:setPositionX((num+var)*display.cx*2) end end end end
return GameBackGround
|