Hey guys. I’ve been working on a sort of tile game of late and I’ve come to a roadblock…I need to draw numbers on a square tile (45x45), centered. Currently I’m drawing a mesh for the square, then just a text(“#”, x,x)… You get the idea.
Is there a way that I can commit letters onto a mesh? A real simple way? Thanks a bunch guys.
--in setup
letters={}
table.insert(letters, AddLetter("a"))
table.insert(letters, AddLetter("b"))
--etc
--in draw
translate(200,200)
char="b"
letters[char]:draw() --draws letter b
--put your own values where I've put @ below
function AddLetter(a)
s=20 --size of tile
local img=image(s,s) --try 20?
setContext(img) --draw to image
background(@) --background tile colour
fill(@) --text colour
fontSize(@) --choose to fit tile size
text(a,s/2,s/2)
setContext()
m=mesh()
m:addRect(0,0,s,s) --set width,height
m.texture=img
return m
end
@invad3rZIM Here’s @Ignatz code, modified to show a larger range of the character set. Slide your finger up or down the screen to change the view.
displayMode(FULLSCREEN)
function setup()
dy=0
letters={}
for z=33,126 do
table.insert(letters, AddLetter(string.char(z)))
end
end
function draw()
background(0)
for z=1,#letters do
pushMatrix()
translate(WIDTH/2,HEIGHT-z*50+dy)
letters[z]:draw()
popMatrix()
end
end
function AddLetter(a)
s=45 --size of tile
local img=image(s,s)
setContext(img) --draw to image
background(0, 185, 255, 255) --background tile colour
fill(234, 32, 32, 255) --text colour
fontSize(40) --choose to fit tile size
text(a,s/2,s/2)
setContext()
m=mesh()
m:addRect(0,0,s,s) --set width,height
m.texture=img
return m
end
function touched(t)
if t.state==MOVING then
dy=dy+t.deltaY
end
end