I’m working on a drawing app where you’re able to resize the canvas, and I did this by rerunning the init
function for the class that handles the editor. While doing some testing, I noticed that resizing it a lot slowed down my fps and eventually crashed Codea. Is this an issue with Codea, or with my iPad? I’m running just a regular iPad Mini.
I’ve posted some sample code below:
function setup()
editor = Editor(32,32)
parameter.watch("1/DeltaTime")
end
function draw()
background(150)
editor:draw()
end
function touched(touch)
editor:touched(touch)
end
Editor = class()
function Editor:init(w,h)
if w > h then
self.width = WIDTH*2/3-100
self.height = self.width*h/w
self.gridHor = 16
self.gridVer = 16*h/w
else
self.height = HEIGHT - 200
self.width = self.height*w/h
self.gridVer = 16
self.gridHor = 16*w/h
end
self.x = (WIDTH*2/3-self.width)/2
self.y = (HEIGHT-100-self.height)/2
self.pixel = self.width/self.gridHor
self.grid = image(self.width,self.height)
setContext(self.grid)
noStroke()
for i = 1,self.gridHor+1 do
for j = 1,self.gridVer+1 do
if (i+j)%2 == 1 then
fill(110, 110, 120, 255)
else
fill(180, 180, 190, 255)
end
rect((i-1)*self.pixel,(j-1)*self.pixel,self.pixel,self.pixel)
end
end
end
function Editor:draw()
pushMatrix()
fill(70,70,80)
noStroke()
translate(WIDTH/3,50)
-- rect(0,0,WIDTH*2/3+1,HEIGHT-100)
translate(Gravity.x*10,Gravity.y*10)
fill(200)
translate(self.x,self.y)
translate(self.width/2,self.height/2)
sprite(self.grid,0,0)
popMatrix()
end
function Editor:touched(touch)
if touch.state == BEGAN then editor:init(8,16)
elseif touch.state == ENDED then editor:init(16,16)
end
end
Thanks for the help!