I know this is my fault. I just want to destroy the physics bodies when they reach a value, say x < -100. In the example I provide below, destruction is set for x < 200. Unfortunately when that occurs, I get booted to desktop.
I offer double the usual amount of free points, so 2 million free points to the kind soul that figures out how to destroy the physics bodies without crashing Codea.
The problem is on line 111.
-- displayMode(FULLSCREEN)
function setup()
--cliff variables
cliffWidth = WIDTH/8
scrollSpeed = -5
decayrate = .5
scrollSpeed = -5
timeBetweenCliffs = 90
cliffTimer = 80
nextCliff = 1
-- Physics variables
physics.gravity(0,0)
-- testCliff = CliffGroup()
touches = {}
end
function draw()
background(0, 178, 255, 255)
-- Timers and loops
cliffTimer = cliffTimer + 1
if cliff1~= nil then
cliff1:draw()
end
if cliff2~= nil then
cliff2:draw()
end
if cliff3~= nil then
cliff3:draw()
end
if cliffTimer == timeBetweenCliffs then
if nextCliff == 1 then
cliff1 = CliffGroup()
end
if nextCliff == 2 then
cliff2 = CliffGroup()
end
if nextCliff == 3 then
cliff3 = CliffGroup()
end
nextCliff = nextCliff + 1
if nextCliff == 4 then
nextCliff = 1
end
cliffTimer = 0
end
--handle touches
for k,touch in pairs(touches) do
SlappyTouched(touch)
HappyTouched(touch)
end
end
function touched(touch)
if touch.state == ENDED then
touches[touch.id] = nil
elseif touch.state == BEGAN then
touches[touch.id] = touch
end
end
function collide(contact)
if contact.state == BEGAN then
print("HIT!")
end
end
Cliff = class()
function Cliff:init(y,h)
local w = cliffWidth
self.x = WIDTH + cliffWidth
self.y = y
self.w = cliffWidth
self.h = h
self.cliffBody = physics.body(POLYGON, vec2(-w/2,h/2), vec2(-w/2,-h/2), vec2(w/2,-h/2), vec2(w/2,h/2))
self.cliffBody.x = self.x
self.cliffBody.y = self.y
-- debugPhysics:addBody(self.cliffBody)
end
function Cliff:draw()
self.cliffBody.x = self.cliffBody.x + scrollSpeed
sprite("Platformer Art:Block Brick",self.cliffBody.x,self.cliffBody.y,self.w,self.h)
-- debugPhysics:draw()
if self.cliffBody.x < 200 then
self.cliffBody.destroy()
end
end
CliffGroup = class()
function CliffGroup:init()
-- determine the type of cliff this will be
cliffType = 1 --math.random(1)
-- 1 is a cliff with the holes up top
-- if cliffType == 1 then
self.TopCliff1 = Cliff(HEIGHT-HEIGHT/20,HEIGHT/10)
self.TopCliff2 = Cliff(HEIGHT-HEIGHT/2.3,HEIGHT/10)
self.TopCliff3 = Cliff(HEIGHT/7,HEIGHT/4.5)
-- end
end
function CliffGroup:draw()
-- Codea does not automatically call this method
self.TopCliff1:draw()
self.TopCliff2:draw()
self.TopCliff3:draw()
end
function CliffGroup:touched(touch)
-- Codea does not automatically call this method
end