Please help

I have a shape where you can press up to 5 time and it gets bigger
everything work as expected.

The problem is that when i press reset button I remove shape then recreate in again, but after its being recreated the touch is not working anymore. Please help

I know i can just reset its position and xScale and yScale, but not in my case. so i do need to remove and then recreate it. Thanks

Here is sample code

This is main.lua sample

local director = require ("director")  
local physics = require("physics")  
local button = require("button")  
  
local mainGroup = display.newGroup()  
  
local function main()  
  
mainGroup:insert(director.directorView)  
print"ok"  
  
director:changeScene ("play")  
physics.setDrawMode("hybrid")  
  
return true  
end  
  
main()  
  

and this is play scene where touch is happening

  
module(...,package.seeall)  
  
local group  
local background  
local shapeGroup  
local shape  
local ground  
local i  
  
resetPressed = function(b)  
print"removed"  
 shapeGroup:removeSelf()  
  
 shapeGroup = display.newGroup()  
 shape = display.newImageRect("shape.png" , 40 , 40)  
 shapeGroup.x = 240  
 shapeGroup.y = 160  
 shapeGroup.name = "shape"  
 shapeGroup.rotation = 0  
 shapeGroup:insert(shape)  
 group:insert(shapeGroup)  
  
 physics.addBody(shapeGroup, {density = 3.0 , friction = 0.5, bounce = 0.3, shape} )  
  
end  
i = 1  
shapePressed = function ()  
 if i \> 5 then return end   
 physics.removeBody(shapeGroup)  
 local function addNewBody()  
 physics.addBody(shapeGroup, {density = 3.0 , friction = 0.5, bounce = 0.3} )  
 end  
 transition.to(shape, {time=10, xScale = shape.xScale + 0.3, yScale = shape.yScale + 0.3, onComplete=addNewBody })   
 i = i+1   
end  
function new()  
physics.start()  
 group = display.newGroup()  
  
 -- Add Background to the scene  
 background = display.newRect(0,0,480,320)  
 background.x=240  
 background.y=160  
 background.width=480  
 group:insert(background)  
   
 ground = display.newRect(0,0,480,20)  
 ground:setFillColor(34,255,255)  
 ground.x=240  
 ground.y=190  
 group:insert(ground)  
  
  
  
 -- Add squere shape to the scene  
 shapeGroup = display.newGroup()  
 shape = display.newImageRect("shape.png" , 40 , 40)  
 shapeGroup.x = 240  
 shapeGroup.y = 160  
 shapeGroup.name = "shape"  
 shapeGroup.rotation = 0  
 shapeGroup:insert(shape)  
 group:insert(shapeGroup)  
  
  
 shapeGroup:addEventListener("tap", shapePressed)  
  
  
 physics.addBody(ground, "static")  
 physics.addBody(shapeGroup, {density = 3.0 , friction = 0.5, bounce = 0.3} )  
  
  
  
 resetButton = button:create(group,1,{x=40,y=40,w=30,h=30,handler=resetPressed}, "replaybutton.png")  
  
  
 return group  
end  
  

Any ideas why after being removed and add it back again touch is not registering ?
Thanks [import]uid: 11559 topic_id: 22589 reply_id: 322589[/import]

If this is after the reset you aren’t adding the listener in the reset function when you recreate the group.

Is that it? :slight_smile: [import]uid: 52491 topic_id: 22589 reply_id: 90104[/import]

I tryed adding listener it doesn’t work at all. [import]uid: 11559 topic_id: 22589 reply_id: 90109[/import]

Did you move the function above where you were adding it in the code, or no? If not it wont work. You need to either move it above there in the code or use a forward declaration.

Also, please try to use descriptive thread titles. “Please help” is unclear, see; http://developer.anscamobile.com/forum/2011/05/05/forum-rules-and-guidelines [import]uid: 52491 topic_id: 22589 reply_id: 90145[/import]

Thank you very much. I will be more clear next time. I really appreciate all your help! [import]uid: 11559 topic_id: 22589 reply_id: 90316[/import]

Not a problem; just trying to keep a clean forum :wink: [import]uid: 52491 topic_id: 22589 reply_id: 90411[/import]

hi Peach,
what’s the best way to remove a shape array, e.g.,
ledgeShape = { -60,-45, -40,-45, 0,40, -20,40 }
physics.addBody(ledge, “static”, {bounce=0, shape=ledgeShape})

ledgeShape:removeSelf()
ledgeShape=nil
returns: attempt to call method ‘removeSelf’ (a nil value)

physics.removeBody(ledgeShape)
returns: bad argument #-1 to ‘removeBody’ (Proxy expected, got nil)

I’m trying to flip the ledge shape and put it on the other side of the screen as part of a moveable catcher. changing the coordinates in the array produces no effect so I figured I had to kill the shape and start with a new one.

thanks!!! [import]uid: 124116 topic_id: 22589 reply_id: 123161[/import]

I finally saw that I was trying to remove ledgeShape instead of ledge. yikes!

a follow-up question though: I changed the coordinates to:
ledgeShape2={ 0,40, 20,40, 60,-45, 40,-45 }
physics.addBody(ledge, “static”, {bounce=0, shape=ledgeShape2})

that flipped it fine, but it no longer has physics properties; I can see it in hybrid mode, but it doesn’t deflect or contain other physics objects anymore. is it no longer convex?

thanks again, Peach and company…

addendum: I went ahead and created a png rectangle, rotated it in Corona, and added the physics body to it. a lot simpler, only a few more bits, no worries about convexity or plotting coordinates. I think the level editor that’s coming will make all this even simpler… [import]uid: 124116 topic_id: 22589 reply_id: 123162[/import]

Hey - you were defining the points counter-clockwise so yeah, no good. Clockwise only :wink:

Glad you figured the first part, sorry took a little to reply, taking some weekends off while I’m traveling.

Peach :slight_smile: [import]uid: 52491 topic_id: 22589 reply_id: 123358[/import]

Peach, you deserve as many breaks as it takes… [import]uid: 124116 topic_id: 22589 reply_id: 123555[/import]

Since Corona Levels isn’t out currently, could you try out my library, Physics B? I just created it, and I want to know how people like it.

quinc [import]uid: 147322 topic_id: 22589 reply_id: 123602[/import]

I’ll be happy to… thanks! [import]uid: 124116 topic_id: 22589 reply_id: 123623[/import]

hi Peach,
what’s the best way to remove a shape array, e.g.,
ledgeShape = { -60,-45, -40,-45, 0,40, -20,40 }
physics.addBody(ledge, “static”, {bounce=0, shape=ledgeShape})

ledgeShape:removeSelf()
ledgeShape=nil
returns: attempt to call method ‘removeSelf’ (a nil value)

physics.removeBody(ledgeShape)
returns: bad argument #-1 to ‘removeBody’ (Proxy expected, got nil)

I’m trying to flip the ledge shape and put it on the other side of the screen as part of a moveable catcher. changing the coordinates in the array produces no effect so I figured I had to kill the shape and start with a new one.

thanks!!! [import]uid: 124116 topic_id: 22589 reply_id: 123161[/import]

I finally saw that I was trying to remove ledgeShape instead of ledge. yikes!

a follow-up question though: I changed the coordinates to:
ledgeShape2={ 0,40, 20,40, 60,-45, 40,-45 }
physics.addBody(ledge, “static”, {bounce=0, shape=ledgeShape2})

that flipped it fine, but it no longer has physics properties; I can see it in hybrid mode, but it doesn’t deflect or contain other physics objects anymore. is it no longer convex?

thanks again, Peach and company…

addendum: I went ahead and created a png rectangle, rotated it in Corona, and added the physics body to it. a lot simpler, only a few more bits, no worries about convexity or plotting coordinates. I think the level editor that’s coming will make all this even simpler… [import]uid: 124116 topic_id: 22589 reply_id: 123162[/import]

Hey - you were defining the points counter-clockwise so yeah, no good. Clockwise only :wink:

Glad you figured the first part, sorry took a little to reply, taking some weekends off while I’m traveling.

Peach :slight_smile: [import]uid: 52491 topic_id: 22589 reply_id: 123358[/import]

Peach, you deserve as many breaks as it takes… [import]uid: 124116 topic_id: 22589 reply_id: 123555[/import]

Since Corona Levels isn’t out currently, could you try out my library, Physics B? I just created it, and I want to know how people like it.

quinc [import]uid: 147322 topic_id: 22589 reply_id: 123602[/import]

I’ll be happy to… thanks! [import]uid: 124116 topic_id: 22589 reply_id: 123623[/import]