bump
Please do not bump your posts more than once in a 24 hour period.
Try something like this:
local onCollision = function(self,event) if event.phase == "began" then local hit = self.value local other = event.other.value if other == 1 then score = score-100 timer.performWithDelay(10, function() display.remove( circle[hit] ); end) circle[hit] = nil else score = score+100 timer.performWithDelay(10, function() display.remove( circle[hit] ); end) circle[hit] = nil end end scoreGraphic() end
You can’t modify physics objects while the collision is still happening. Putting it in a timer allows the collision to finish and then you can remove the object.
Rob
Nope, still getting exact same error… but i think im going to get this code and take it apart and put it slowly back together.
There’s nothing wrong with the code, it’s the way you are putting it into composer.
Hey QuizMaster(Guy who wrote the code for me) !!! well see what confuses me is that ive made multiple really simple games and ive learned the comopser setup pretty good… and thos little games ive made all worked perfect… Im not meaning to offend you by saying your code doesnt work… the code works perfect but somethings wrong on my side and i cant figure it out lol
Straight away I can see you are putting the code in the create scene function, I tried telling you this before.
Your main code should go in the "scene:show / phase == “did” part of composer.
I don’t use composer so I’m no expert.
and i did put it in the show part of the function… and in the create part i put the physics start and added my backgroud. but after i do that corona just crashes when i try to simulate the code…
and i do have a good laptop (8gig ram) (4th gen i5 item processor)
Actually that’s not correct. Most all object creation code should be in scene:create(). Normally I would defer starting the timers until the scene:show()'s “did” phase. Functions that need to be accessed in multiple functions need to be declared above the scene functions. Variables needed by all of those should be forward declared at the top.
Rob
does anyone have the time to get that code and try putting it in the functions and make it work?
I corrected my error in the last post, it was just a quick observation, like I said, I don’t use composer, yet, so I’ve not read the docs properly.
You’d be better off following Rob’s advice Sonic.
oh, well then rob can you spare the time to get that code set up? or you busy?
We can’t write your code for you. It’s why we provide tutorials and guides. Everything you need is there. You just have to be patient read what we’ve provided and build this yourself. I’ll provide you the core template with some additional annotations:
local composer = require( "composer" ) local scene = composer.newScene() local widget = require( "widget" ) -- -- pre declare variables that all scenes need to have access to here: -- local someVariable local params -- put your functions here that need to be seen by all scenes. local function someFunction() -- do stuff end -- -- Start the composer event handlers -- function scene:create( event ) local sceneGroup = self.view params = event.params -- -- setup a page background, really not that important though composer -- crashes out if there isn't a display object in the view. -- -- create all you display objects here and add to the scene's view group. -- If you spawn things later in the course of the game add them to the scene's view group which you can get to as: -- scene.view:insert(object) end function scene:show( event ) local sceneGroup = self.view params = event.params if event.phase == "did" then -- put things like timers, transitions, resuming physics here -- start audio for the scene here. end end function scene:hide( event ) local sceneGroup = self.view if event.phase == "will" then end end function scene:destroy( event ) local sceneGroup = self.view end --------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) return scene
Hope this helps
when i get the time ill look over this code… thanks
I found out what i was doing wrong!
local floor = display.newRect( \_W\*0.5, \_H-10, \_W, 20 ) floor:setFillColor( 1,0,0 ) --\>physics.addBody( floor, "static", {density=1, friction=1, bounce=0.3 } ) floor.value = 1 local leftWall = display.newRect( 10, \_H\*0.5, 20, \_H ) leftWall:setFillColor( 1,0,0 ) --\>physics.addBody( leftWall, "static", {density=1, friction=1, bounce=0.3 } ) leftWall.value = 2 local rightWall = display.newRect( \_W-10, \_H\*0.5, 20, \_H ) rightWall:setFillColor( 1,0,0 ) --\>physics.addBody( rightWall, "static", {density=1, friction=1, bounce=0.3 } ) rightWall.value = 3 return --\> all i needed was that return after like that and everything worked! \<--