--reset animations in 0ms to pos 0/0
ActiveAnimations["tunnel0"]:to(0, { VAnimationCurrentPosition = {x = 0, y = 0} })
ActiveAnimations["tunnel1"]:to(0, { VAnimationCurrentPosition = {x = 0, y = 0} })
ActiveAnimations["tunnel2"]:to(0, { VAnimationCurrentPosition = {x = 0, y = 0} })
--randomize a number between 0 and 2
local randomtunnel = math.random(0,2)
--move random tunnel animation to other side of the screen in 500ms (assuming x=2000 is outside the view)
ActiveAnimations["tunnel"..randomtunnel]:to(500, { VAnimationCurrentPosition = {x = 2000, y = 0} })
scUW = {}
scUW.tilewidth = 913 -- width of a tiles image
scUW.numtiles = math.ceil(game.WindowResolution.x / scUW.tilewidth)
scUW.tiles0 = {"tunnel0a","tunnel0b"} -- animations with image0
scUW.tiles1 = {"tunnel1a","tunnel1b"} -- animation with iamge1
scUW.tiles2 = {"tunnel2"} -- animations with image2
scUW.offset = 0
scUW.ordering = {"tunnel0a","tunnel0b","tunnel2"}
--[[ doesnt move, just for testing ]]--
scUW.setBackground = function(self)
local pos = 0
for _,t in ipairs(self.ordering) do
ActiveAnimations[t]:to(0, { VAnimationCurrentPosition =
{x = self.offset + self.tilewidth * pos, y = 0} })
pos = pos + 1
end
end
scUW.ordering = {"tunnel0a","tunnel1a","tunnel2"}
scUW.ordering = {"tunnel0a","tunnel1a","tunnel0b"}
local pos = 0
for _,t in ipairs(self.active) do
local ani = getObject("Animations["..t.."]")
startAnimation(ani)
ActiveAnimations[t]:to(0, { VAnimationCurrentPosition =
{x = self.offset + self.tilewidth * pos, y = 0} })
pos = pos + 1
end
ActiveAnimations[t].AnimationCurrentPosition = {…}?
ActiveAnimations[t]:to(0, { VAnimationCurrentPosition =
{x = self.tilewidth * pos, y = 0} })
ActiveAnimations[t]:to(self.tick, { VAnimationCurrentPosition =
{x = self.tilewidth * (pos - 1), y = 0} })
math.randomseed( os.time() )
-- unfuck luas base-1 bullshit
function iarray(a)
local n = 0
local s = #a
if a[0] ~= nil then
n = -1
end
return function()
n = n + 1
if n <= s then return n, a[n] end
return nil,nil
end
end
QP_createTiledBackground = function(tilewidth, tick, aBasetiles, aAlt1, aAlt2, chance2)
ret = {}
ret.scWidth = game.CurrentScene.Sprite:getSize().x
ret.numTiles = math.ceil(ret.scWidth / tilewidth)
ret.offset = 0
ret.tilewidth = tilewidth
ret.chance2 = chance2 * 100
ret.isInit = false
ret.tick = tick
ret.tiles = {}
ret.ordering = {}
local pos = 0
for _,t in iarray(aBasetiles) do
ret.tiles[pos] = t
pos = pos + 1
end
ret.numBases = pos
for _,t in iarray(aAlt1) do
ret.tiles[pos] = t
pos = pos + 1
end
ret.startAlt2 = pos
ret.numAlt1 = pos - ret.numBases
for _,t in iarray(aAlt2) do
ret.tiles[pos] = t
pos = pos + 1
end
ret.numAlt2 = pos - ret.numBases - ret.numAlt1
-- move all animation-tiles outsize the viewport
ret.initBackground = function(self)
if (self.isInit) then
return end
self.isInit = true
self.offset = 0
for _,t in iarray(self.tiles) do
local ani = getObject("Animations["..t.."]")
startAnimation(ani)
print (t)
ActiveAnimations[t]:to(0, { AnimationCurrentPosition =
{x = self.scWidth, y = 0} })
end
end
-- check if a tile is already used in the ordering, skipping it
ret.findTile = function(self, tile)
for _,t in iarray(self.ordering) do
if (t == tile) then return _ end
end
return -1
end
-- return an appropiate tile from given range or nil if none available
ret.getNextTile = function(self, start, stop)
local pos = start
while (pos = math.random(0,100)) then
self.ordering[pos] = self:getNextTile(self.startAlt2,#(self.tiles)+1)
else
self.ordering[pos] = self:getNextTile(self.numBases, self.startAlt2)
end
end
end
off = off + 1
if (self.ordering[pos] ~= nil) then
pos = pos + 1
end
if (off > 20) then break end -- reasonable way out if to few tiles given
end
end
ret.moveBackground = function(self)
self:initBackground()
self:orderBackground()
local pos = 0
for _,t in iarray(self.ordering) do
ActiveAnimations[t]:to(0, { VAnimationCurrentPosition =
{x = self.tilewidth * pos, y = 0} })
ActiveAnimations[t]:to(self.tick, { VAnimationCurrentPosition =
{x = self.tilewidth * (pos - 1), y = 0} })
pos = pos + 1
end
end
return ret
end
scUW = QP_createTiledBackground(913, 1500, {"tunnel0a","tunnel0b"}, {"tunnel1a","tunnel1b"}, {"tunnel2"}, 0.5)
That doesnt do anything. BTW, you misinterpreted the code, i dont move it pixelwise, a tick is 1500 ms and in that time all tiles should move one tilewidth. Its just that the zero-delay-commands sometimes seem to get ignored.ActiveAnimations[t].CurrentPosition = {x=something, y=something}