I got the performWithDelay working, but still the simulator crashes as soon as I add a physics body. So back to the drawing board.
I have created the below script to reproduce the error, notice that I’m also using the director class:
[lua]module(…, package.seeall)
require “sprite”
local localGroup = display.newGroup()
local physics = require “physics”
local mRand = math.random
physics.start( true )
physics.setGravity( 0, 0 )
_H = display.contentHeight;
_W = display.contentWidth;
sheetData = require “sheet@2x”
data = sheetData.getSpriteSheetData()
sheet1 = sprite.newSpriteSheetFromData( “sheet@2x.png”, data )
local sprite1Set = sprite.newSpriteSet(sheet1, 3, 3)
sprite.add( sprite1Set, “sp1”, 1, 3, 2250, -2 )
local sprite2Set = sprite.newSpriteSet(sheet1, 7, 2)
sprite.add( sprite2Set, “sp2”, 1, 2, 1000, -2 )
local function sprite_collide()
local sp = sprite.newSprite(sprite2Set)
sp.x = mRand(80,400)
sp.y = mRand(20,300)
physics.addBody(sp, {density = 0.5 , friction = 0.0, bounce =1,radius = 16})
sp:applyForce(-10+mRand(0,25), -10+mRand(0,25), sp.x,sp.y)
end
local function create_sprites()
for i=1,10,1 do
local other = sprite.newSprite(sprite2Set)
other.x = mRand(80,400)
other.y = mRand(20,300)
physics.addBody(other, {density = 0.5 , friction = 0.0, bounce =1,radius = 16})
other:applyForce(-10+mRand(0,25), -10+mRand(0,25), other.x,other.y)
end
end
function new()
– create physics wall
local bottom_wall = display.newRect(0,0,_W,20)
bottom_wall.y = _H+10
bottom_wall.eName = “wall”
bottom_wall:setStrokeColor(0,0,0,255)
bottom_wall:setFillColor(0,0,0,255)
localGroup:insert(bottom_wall)
physics.addBody(bottom_wall,“static”, {friction = 0.0, bounce = 1})
local top_wall = display.newRect(0,0,_W,20)
top_wall.y = -10
top_wall.eName = “wall”
top_wall:setStrokeColor(0,0,0,255)
top_wall:setFillColor(0,0,0,255)
localGroup:insert(top_wall)
physics.addBody(top_wall,“static”, {friction = 0.0, bounce = 1})
local left_wall = display.newRect(0,0,20,_H)
left_wall.x = -10
left_wall.eName = “wall”
left_wall:setStrokeColor(0,0,0,255)
left_wall:setFillColor(0,0,0,255)
localGroup:insert(left_wall)
physics.addBody(left_wall,“static”, {friction = 0.0, bounce = 1})
local right_wall = display.newRect(0,0,20,_H)
right_wall.x = _W+10
right_wall.eName = “wall”
right_wall:setStrokeColor(0,0,0,255)
right_wall:setFillColor(0,0,0,255)
localGroup:insert(right_wall)
physics.addBody(right_wall,“static”, {friction = 0.0, bounce = 1})
create_sprites() – create 10 sprites
Runtime:addEventListener(“collision”,sprite_collide)
return localGroup
end[/lua] [import]uid: 6942 topic_id: 10338 reply_id: 37784[/import]