Here’s an example of the idea I had, i just whipped it up real fast so obviously there’s room for improvement, but, here you go! See if you like it or could see it being good with minor changes (and if it’s almost there but not quite just tell me what I could do to improve it and I’d be happy to do my best).
--# Main
function setup()
--[[ the variables in the persistent drawer's init function
(isSprite,isEllipse,isRect,isMesh,
width,height,spritename,meshverts,
fillcol,strokecol,strokewid,x,y)]]--
--sprite("Planet Cute:Character Boy",,,): for finding sprite names
--(just uncomment it to use the file searcher)
--set up the master for the persistent draws (the first instance of Persist will
--always be the master, this one is simply used to handle draws. the first argument is the background color
--the second argument, if true, enables smoothing. if false it disables smoothing.
m = Persist(color(255,255,255),false)
--make a new persistent object named "p". you can also access this object from the global table "q" created by the master. the first persistent object (past te master) is indexed as q[1], the next as q[2], etc.
p = Persist(true,false,false,false,30,60,"Planet Cute:Character Boy",nil,nil,nil,nil,37,92)
--p2 or q[2]
p2 = Persist(false,true,false,false,30,60,nil,nil,nil,nil,nil,37,300)
p3 = Persist(false,false,true,false,60,30,nil,nil,nil,nil,nil,WIDTH/2,HEIGHT/2)
end
function touched(t)
--different functions in the Persistent class
local a = true
if a then
p:setLoc(t.x,t.y)
elseif b then
p:move(t.deltaX,t.deltaY)
elseif c then
p:resize(t.deltaX,t.deltaY,true)
elseif d then
if t.state == BEGAN then
p:togglevis()
end
end
end
function draw()
--all that needs placed in the draw step :)
--this draws all of the objects by accessing the "draw all objects" function of the master
m:drawall()
end
--[[ if you are interested in this method of things staying until you move them then, by all means, tell me and id love to improve upon this class for you, adding more and more features and the likes :) --]]
--# persist
Persist = class()
function Persist:init(isSprite,isEllipse,isRect,isMesh,width,height,spritename,meshverts,fillcol,strokecol,strokewid,x,y)
if not q then
q={}
self.master = true
self.bgcol = isSprite
self.smoothing = true
end
self.s = isSprite or false
self.e = isEllipse or false
self.r = isRect or false
self.m = isMesh or false
if self.s then
self.spritename = (spritename) or ("Planet Cute:Character Boy")
end
if self.m then
self.mesh = mesh()
self.verts = meshverts
self.mesh.vertices = self.verts
else
self.wid = width or 30
self.hei = height or width or 30
self.strokewid = strokewid or 0
self.strokecol = strokecol or color(0,0,0)
self.x =x or WIDTH/2
self.y =y or HEIGHT/2
self.loc = vec2(self.x,self.y)
end
self.fillcol = fillcol or color(0,0,0)
if self.m then
self.mesh.setColors(fillcol)
end
if not self.master then
table.insert(q,self)
end
self.invis = false
end
function Persist:draw()
if not self.invis then
if self.s then
spriteMode(CENTER)
sprite(self.spritename,self.x,self.y,self.wid,self.hei)
elseif self.e then
ellipseMode(CENTER)
fill(self.fillcol)
strokeWidth(self.strokewid)
stroke(self.strokecol)
ellipse(self.x,self.y,self.wid,self.hei)
elseif self.r then
rectMode(CENTER)
fill(self.fillcol)
strokeWidth(self.strokewid)
stroke(self.strokecol)
rect(self.x,self.y,self.wid,self.hei)
elseif self.m then
self.mesh:draw()
end
end
end
function Persist:move(xoffs,yoffs)
if not self.m then
self.x = self.x + xoffs
self.y = self.y + yoffs
self.loc = vec2(self.x,self.y)
end
end
function Persist:setLoc(x,y)
if not self.m then
self.x = x
self.y = y
self.loc = vec2(self.x,self.y)
end
end
function Persist:moveByAngle(mag,angleDeg)
if not self.m then
self.x = self.x + (mag*math.cos(math.deg(angleDeg)))
self.y = self.y + (mag*math.sin(math.deg(angleDeg)))
self.loc = vec2(self.x,self.y)
end
end
function Persist:resize(w,h,Additive)
if Additive then
self.wid = self.wid + w
self.hei = self.hei + h
else
self.wid = w
self.hei = h
end
end
function Persist:togglesmooth()
if self.master then
self.smoothing = not self.smoothing
end
end
function Persist:togglevis()
self.invis = not self.invis
end
function Persist:drawall()
background(self.bgcol)
if self.smoothing then
smooth()
else
noSmooth()
end
for i=1,#q do
q[i]:draw()
end
end