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]
[import]uid: 52491 topic_id: 22589 reply_id: 90104[/import]
[import]uid: 52491 topic_id: 22589 reply_id: 90411[/import]