Many thanks to those who helped me onto the first rung…@dave1707,@Ignatz,@Thwapp, @Stevon8tor , @Jordan and others whose comments have been invaluable…
I have managed to write this one from scratch without having to ask for help…PROGRESS!!!(?) [though those who have assisted in the past will no doubt recognise their presense in the code]
Substitute 2 of your own sprites in
--# GetSpritesFunction
function getsprites()
tile1=readImage("Documents:cobblestone")
tile2=readImage("Documents:shader")
end
--# Main
displayMode(FULLSCREEN)
supportedOrientations(LANDSCAPE_ANY)
function setup()
Border=30
dx,dy=0,0
makemesh()
getsprites()
TileSelected=tile1
end
function draw()
background(40, 40, 50)
fill(255, 255, 255, 255)
-- this section deals with available tiles
textMode(CORNER)
text("Select a tile...and double tap to place",600,730)
if TileSelected == tile1 then
rect(595,595,100,100)
else
rect(705,595,100,100)
end
spriteMode(CORNER)
sprite(tile1,600,600,90,90)
sprite(tile2,710,600,90,90)
-- this section deals with the l.h.s. selection window
clip(Border,Border,480,720)
for x=1,m do
for y=1,n do
prebasetab1[x][y]:draw()
end
end
clip()
-- this section deals with the lower r.h.s. overview
translate(600,Border)
scale(scl,scl)
for x=1,m do
for y=1,n do
prebasetab2[x][y]:draw()
end
end
rectMode(CORNER)
fill(108, 81, 81, 73)
rect(0-dx,0-dy,480,720)
end
--# MeshFunction
function makemesh()
m,n,sl,scl = 30,30,60,0.2
prebasetab1={}
for x=1,m do
prebasetab1[x]={}
for y=1,n do
cell=mesh()
prebasetab1[x][y]=0
cell:addRect(30+(x*sl)-sl/2,30+(y*sl)-sl/2,sl,sl)
cell:setRectColor(1,x*y*255/(m*n),255-(x*y*255/(m*n)),x*y*255/(m*n))
prebasetab1[x][y]=cell
end
end
prebasetab2={}
for x=1,m do
prebasetab2[x]={}
for y=1,n do
cell=mesh()
prebasetab2[x][y]=0
cell:addRect((x*sl)-sl/2,(y*sl)-sl/2,sl,sl)
cell:setRectColor(1,x*y*255/(m*n),255-(x*y*255/(m*n)),x*y*255/(m*n))
prebasetab2[x][y]=cell
end
end
end
--# MoveMeshFunction
function movemesh(dx,dy)
for x=1,m do
for y=1,n do
prebasetab1[x][y]:setRect(1,30+((x*sl)-sl/2)+dx,30+((y*sl)-sl/2)+dy,sl,sl)
end
end
end
--# TouchFunction
function touched(t)
-- this deals with the r.h.s. selection window swipe action
if t.x>=Border and t.x<=510 then
if t.y>=Border and t.y<=750 then
if t.state==MOVING then
dx=dx+(t.deltaX*2)
dy=dy+(t.deltaY*2)
if dx>=0 then
dx=0
end
if dx<=-(m*sl)+480 then
dx=-(m*sl)+480
end
if dy>=0 then
dy=0
end
if dy<=-(n*sl)+720 then
dy=-n*sl+720
end
movemesh(dx,dy)
end
-- this deals with the r.h.s tile placement double tap
if t.state==BEGAN and t.tapCount==2 then
xsel=math.floor((30+t.x-dx)/sl)
ysel=math.floor((30+t.y-dy)/sl)
prebasetab1[xsel][ysel]:setColors(255,255,255,255)
prebasetab1[xsel][ysel].texture = TileSelected
prebasetab2[xsel][ysel]:setColors(255,255,255,255)
prebasetab2[xsel][ysel].texture = TileSelected
end
end
end
-- this deals with the tile selection
if t.x>=600 and t.x<=690 then
if t.y>=600 and t.y<=690 then
TileSelected=tile1
end
end
if t.x>=710 and t.x<=800 then
if t.y>=600 and t.y<=690 then
TileSelected=tile2
end
end
end
Next steps
additional scrollable images for more choice,
choice of background colour mesh via mixer so it can be converted into a sprite drawing program,
file saving…
Haven’t felt this happy in ages!
Comments regarding elegance and alternate ways of coding are always welcomed and much appreciated…