I just want to report a bug in hope of a fix in the next update.
Codea will always crash after a few seconds with the following code.
Specs:
Codea Version 2.5 (90)
iOS: 11.0.1 also in 11.1 beta 2
Device: iPad Pro ML0NF2D/A (the first iPad Pro)
Create a new project an paste the folowing code into it.
In my case. I splitted the classes into separated files.
Code:
--# Main
displayMode(FULLSCREEN)
function setup()
physics.gravity(0, -1000)
boxes = {}
grounds = {}
time = 0
table.insert(grounds, Ground(-WIDTH / 2, 50, WIDTH / 2))
table.insert(grounds, Ground(WIDTH / 2, 50, WIDTH / 2))
textMode(CORNER)
end
function draw()
background(40, 40, 50)
if ElapsedTime - time > 0.2 then
table.insert(boxes, Box(200 + math.random(200), HEIGHT + 200, 50))
time = ElapsedTime
end
for i, box in pairs(boxes) do
if box.body.y < 0 then
box = nil
table.remove(boxes, i)
end
end
for i, box in pairs(boxes) do
box:draw()
end
for i, ground in pairs(grounds) do
ground.body.linearVelocity = vec2(100, 0)
if ground.body.x > WIDTH + WIDTH/2 then
ground.body.x = - WIDTH / 2
end
ground:draw()
end
text(#boxes, 50, HEIGHT - 20)
text(ElapsedTime, 50, HEIGHT - 40)
end
function touched(touch)
if touch.state == BEGAN then
table.insert(boxes, Box(touch.x, touch.y, 50))
end
end
--# Box
Box = class()
function Box:init(x, y, size)
self.body = physics.body(POLYGON, vec2(-size, -size), vec2(size, -size), vec2(size, size), vec2(-size, size))
self.body.interpolate = true
self.body.x = x
self.body.y = y
self.body.angle = math.random() * 360
self.body.friction = 0.5
self.mesh = mesh()
self.mesh.vertices = triangulate(self.body.points)
self.mesh:setColors(255,0,0, 255)
self.sprites = {
"Cargo Bot:Title Large Crate 1",
"Cargo Bot:Title Large Crate 2",
"Cargo Bot:Title Large Crate 3"
}
self.spriteIndex = math.random(1, #self.sprites)
end
function Box:draw()
--self.body.linearVelocity = vec2(50, 0)
pushMatrix()
translate(self.body.x, self.body.y)
rotate(self.body.angle)
--self.mesh.draw(self.mesh)
sprite(self.sprites[self.spriteIndex], 0, 0, 100, 100)
popMatrix()
end
function Box:touched(touch)
end
--# Ground
Ground = class()
function Ground:init(x, y, size)
self.body = physics.body(POLYGON, vec2(-size, -10), vec2(size, -10), vec2(size, 10), vec2(-size, 10))
self.body.type = KINEMATIC
self.body.interpolate = true
self.body.x = x
self.body.y = y
self.body.friction = 0.5
self.mesh = mesh()
self.mesh.vertices = triangulate(self.body.points)
self.mesh:setColors(255,255,0,255)
end
function Ground:draw()
pushMatrix()
translate(self.body.x, self.body.y)
rotate(self.body.angle)
--self.mesh.draw(self.mesh)
sprite("Cargo Bot:Game Area Floor", 0, 0, WIDTH, 20)
popMatrix()
end
function Ground:touched(touch)
end