@John
Here is a demo of the issue with associated code
http://www.youtube.com/watch?v=T5qpFWbmcms
-- BackgroundTest
displayMode(FULLSCREEN)
-- Use this function to perform your initial setup
function setup()
touches={}
globalx=0
globaly=0
scroll=-1
vscroll=-1
cratesize=50
bgw=60
bgh=60
tilew=bgw
tileh=bgh
bg={}
bgimg={}
numMesh=30
numMeshVert=8
crater=image(50,50)
setContext(crater)
fill(0,0,0)
ellipse(25,25,50)
setContext()
for v=1,numMeshVert do
bg[v]={}
bgimg[v]={}
for i=1,numMesh do
bg[v][i]=mesh()
bgimg[v][i]=image(bgw,bgh)
bg[v][i].texture=bgimg[v][i]
setContext(bgimg[v][i])
background(0,0,0)
if (math.random(3)==1 or v<3 )and v~=numMeshVert then
sprite("Cargo Bot:Crate Yellow 2",tilew/2,tileh/2,tilew,tileh)
end
setContext()
end
end
end
function touched(touch)
if touch.state == ENDED then
touches[touch.id] = nil
else
touches[touch.id] = touch
end
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(0,0,0)
for v=1,numMeshVert do
for i=1,numMesh do
bg[v][i]:clear()
--only draw those that appear on the screen will speed it up
if i*tilew+globalx>0 and i*tilew+globalx<1024+tilew then
local bgid=bg[v][i]:addRect(globalx+((i-1)*tilew+tilew/2),((v-1)*tileh+tileh/2),tilew,tileh)
bg[v][i]:setRectTex(bgid,0,0,1,1)
bg[v][i]:draw()
end
-- text(i*tilew,600,600)
end
end
if tilew*numMesh>WIDTH then
globalx = globalx + scroll
if globalx>0 or globalx<-(numMesh)*tilew+WIDTH then
scroll=scroll*-1
end
end
for k,touch in pairs(touches) do
for v=1,numMeshVert do
for i=1,numMesh do
if touch.x<i*tilew+globalx and touch.x>=(i-1)*tilew+globalx and touch.y<v*tileh+globaly and touch.y>=(v-1)*tileh+globaly then
-- centre of the mesh
setContext(bgimg[v][i])
sprite(crater,(-1*(i-1)*tilew)+touch.x-globalx,(-1*(v-1)*tileh)+touch.y-globaly,cratesize,cratesize)
setContext()
end
if touch.x>i*tilew+globalx-cratesize/2 and touch.x<i*tilew+globalx and touch.y<v*tileh+globaly and touch.y>=(v-1)*tileh+globaly and i<numMesh then
--leaks into mesh to the right
setContext(bgimg[v][i+1])
sprite(crater,-i*tilew-globalx+touch.x,(-1*(v-1)*tileh)+touch.y-globaly,cratesize,cratesize)
setContext()
end
if touch.x>(i-1)*tilew+globalx and touch.x<(i-1)*tilew+globalx+cratesize/2 and touch.y<v*tileh+globaly and touch.y>=(v-1)*tileh+globaly and i>1 then
--leak into mesh to the left
setContext(bgimg[v][i-1])
sprite(crater,-(i-2)*tilew+touch.x-globalx,(-1*(v-1)*tileh)+touch.y-globaly,cratesize,cratesize)
setContext()
end
if touch.x<i*tilew+globalx and touch.x>=(i-1)*tilew+globalx and touch.y>(v-1)*tileh+globaly and touch.y<(v-1)*tileh+globaly+cratesize/2 and v>1 then
--leak into mesh below
setContext(bgimg[v-1][i])
sprite(crater,(-1*(i-1)*tilew)+touch.x-globalx,(-1*(v-2)*tileh)+touch.y-globaly,cratesize,cratesize)
setContext()
end
if touch.x<i*tilew+globalx and touch.x>=(i-1)*tilew+globalx and touch.y>v*tileh+globaly-cratesize/2 and touch.y<v*tileh+globaly and v<numMeshVert then
--leak into mesh above
setContext(bgimg[v+1][i])
sprite(crater,(-1*(i-1)*tilew)+touch.x-globalx,(-1*(v)*tileh)+touch.y-globaly,cratesize,cratesize)
setContext()
end
if touch.x>i*tilew+globalx-cratesize/2 and touch.x<i*tilew+globalx and touch.y>v*tileh+globaly-cratesize/2 and touch.y<v*tileh+globaly and i<numMesh and v<numMeshVert then
--leaks into mesh up and to the right
setContext(bgimg[v+1][i+1])
sprite(crater,-i*tilew-globalx+touch.x,(-1*(v)*tileh)+touch.y-globaly,cratesize,cratesize)
setContext()
end
if touch.x>i*tilew+globalx-cratesize/2 and touch.x<i*tilew+globalx and touch.y>(v-1)*tileh+globaly and touch.y<(v-1)*tileh+globaly+cratesize/2 and i<numMesh and v>1 then
--leaks into mesh below and to the right
setContext(bgimg[v-1][i+1])
sprite(crater,-i*tilew-globalx+touch.x,(-1*(v-2)*tileh)+touch.y-globaly,cratesize,cratesize)
setContext()
end
if touch.x>(i-1)*tilew+globalx and touch.x<(i-1)*tilew+globalx+cratesize/2 and touch.y>v*tileh+globaly-cratesize/2 and touch.y<v*tileh+globaly and i>1 and v<numMeshVert then
--leaks into mesh up and to the left
setContext(bgimg[v+1][i-1])
sprite(crater,-(i-2)*tilew-globalx+touch.x,(-1*(v)*tileh)+touch.y-globaly,cratesize,cratesize)
setContext()
end
if touch.x>(i-1)*tilew+globalx and touch.x<(i-1)*tilew+globalx+cratesize/2 and touch.y>(v-1)*tileh+globaly and touch.y<(v-1)*tileh+globaly+cratesize/2 and i>1 and v>1 then
--leaks into mesh down and to the left
setContext(bgimg[v-1][i-1])
sprite(crater,-(i-2)*tilew-globalx+touch.x,(-1*(v-2)*tileh)+touch.y-globaly,cratesize,cratesize)
setContext()
end
end
end
sprite("Cargo Bot:Star Filled",touch.x,touch.y,cratesize,cratesize)
end
end