37 lines
841 B
Lua
37 lines
841 B
Lua
gen = {}
|
|
|
|
function gen:new(game,sprite)
|
|
|
|
local Background = game.objects.base:new(game,0,0,game.WIDTH,game.HEIGHT)
|
|
Background.sprite = sprite
|
|
Background.spritewidth = sprite:getWidth()
|
|
Background.spriteheight = sprite:getHeight()
|
|
Background.nbwidth = game.WIDTH%sprite:getWidth()+2
|
|
Background.nbheight = game.HEIGHT%sprite:getHeight()+2
|
|
Background.speed = 30
|
|
Background.depth = -2
|
|
Background.offx = 0
|
|
Background.offy = 0
|
|
|
|
function Background:step(dt)
|
|
self.offx = (self.offx + dt*self.speed)%self.spritewidth
|
|
self.offy = (self.offy + dt*self.speed)%self.spriteheight
|
|
end
|
|
|
|
function Background:draw()
|
|
local i=0
|
|
local j=0
|
|
for i=-1,self.nbwidth-1 do
|
|
for j=-1,self.nbheight-1 do
|
|
lg.draw(self.sprite,i*self.spritewidth+self.offx,j*self.spritewidth+self.offy)
|
|
end
|
|
end
|
|
|
|
end
|
|
|
|
return Background
|
|
|
|
end
|
|
|
|
return gen
|