Hello everyone, i saw in the forum some people that create post and had the same doubt but not equivalent on all aspects with my doubt, i am trying to make a icon that when i touch him is created a block, my for loop is only 1 to 3, but the blocks was created all three at the same time, and i need one to one.
and the other doubt is when the object collides with remover object i need to make like feed me oil, example:
- i have 3 blocks on the remover icon, and i touch on the remover icon and it will create a block, and the remover icon will have only 2 blocks because 1 was been created, and when the created block collides with remover icon, the block is removed and the remover icon will have 3 blocks again
I have all the code, only need the for loop to create only X objects and to when the object collides with remover icon, the remover icon stay with one more object.
algumas dicas ou ajudas para resolver este passo?
Thanks again corona community
[code]
–Objects bar
local spawner = display.newRect( 50, 5, 40, 40 )
spawner:setFillColor(150, 0, 0)
physics.addBody(spawner, “static”, {isSensor = true})
spawner:addEventListener(“collision”, spawner)
local spawner2 = display.newRect( 100, 5, 40, 40 )
spawner2:setFillColor(150, 0, 0)
physics.addBody(spawner2, “static”, {isSensor = true})
spawner2:addEventListener(“collision”, spawner)
–remove function
function spawner:collision (event)
event.other:removeSelf()
end
–Objects and Drag
local function spawnMyObject (event)
if event.phase == “began” then
–objects and physics
local block1 = {}
for j = 1,3 do
block1[j] = display.newImage(“block.png”, 250, 300)
physics.addBody(block1[j], “kinematic”, { density=2, friction=0, bounce=0, shape=barril })
block1[j].isFixedRotation = true
local function startDrag( event )
local t = event.target
local phase = event.phase
if “began” == phase then
display.getCurrentStage():setFocus( t )
t.isFocus = true
– Store initial position
t.x0 = event.x - t.x
t.y0 = event.y - t.y
– make the bodys dynamic without gravity
–physics.setGravity (0,0)
– Stop current motion, if any
event.target:setLinearVelocity( 0, 0 )
event.target.angularVelocity = 0
elseif t.isFocus then
if “moved” == phase then
t.x = event.x - t.x0
t.y = event.y - t.y0
event.target.bodyType = “dynamic”
elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
– Switch body type to kinematic, to avoid gravity
if ( not event.target.isPlatform ) then
event.target.bodyType = “kinematic”
end
end
end
–return true
end
block1[j]:addEventListener(“touch”, startDrag)
end
end
end
spawner:addEventListener(“touch”, spawnMyObject)
spawner2:addEventListener(“touch”, spawnMyObject)
[/code] [import]uid: 26056 topic_id: 15519 reply_id: 315519[/import]

