Ok, so what’s happening is I have a few different objects setup in my app, some of them are set to collide with each other and preform certain things when this happens, all of those detections are working fine without problems.
The problem I’m having is that I have one Static and one Dynamic object that are set to preform functions when they collide with different objects but not each other. The problem is the Static object can be moved around the screen and when it collides with this one dynamic object, instead of doing nothing and just continuing like it should, its pushing the dynamic object out of its way. I can’t have it doing this because the object its pushing needs to stay where it is and not be able to be moved.
I have no idea how to fix this because no where in my code does it have anything to do with these colliding so I don’t know what I need to change so they can’t collide with each other and move the other one. They need to stay as Static and Dynamic objects for their other uses in the code so that can’t change.
Here is the part of coding that has to do with these two objects, my Block and Star…
function newStar( ) -- Create new stars
if ( gameState == "Play" ) then
local Star = display.newImage ("Star.png")
Star.x = math.random (140 , 470)
Star.y = 305
Star.itemName = "Star"
physics.addBody( Star, "dynamic")
Star:addEventListener( "collision", Star )
groupOne:insert( Star )
function Star:collision (event)
if event.other.itemName == "sprite" then
groupOne:remove( Star )
Star = nil
local StarSpawner = timer.performWithDelay( StarTime, newStar, 1 )
updatePoints("add")
end
end
end
end
local makeWallTime = 8000
local function onBlockCollision( self, event ) -- Delete block
if event.other.itemName == "rock" then
groupOne:remove( self )
self = nil
end
end
local function createWall( event )
if ( gameState == "Play" ) then
local block = display.newRect( math.random (40 , 75), math.random (130 , 220), 30, 4.5 )
block:setFillColor( math.random (20 , 255), math.random (20 , 255), math.random (20 , 255))
physics.addBody( block, "static" )
block.collision = onBlockCollision
block.itemName = "block"
block:addEventListener( "collision", block )
groupOne:insert( block )
local function onTouch( event )
local blockmoved = event.target
local phase = event.phase
if ( gameState == "Play" ) then
if "began" == phase then
-- Make target the top-most object
local parent = blockmoved.parent
parent:insert( blockmoved )
display.getCurrentStage():setFocus( blockmoved )
blockmoved.isFocus = true
-- Store initial position
blockmoved.x0 = event.x - blockmoved.x
blockmoved.y0 = event.y - blockmoved.y
elseif blockmoved.isFocus then
if "moved" == phase then
blockmoved.x = event.x - blockmoved.x0
blockmoved.y = event.y - blockmoved.y0
elseif "ended" == phase or "cancelled" == phase then
display.getCurrentStage():setFocus( nil )
blockmoved.isFocus = false
end
end
return true
else
block.isFocus = false
end
end
block:addEventListener( "touch", onTouch ) -- Let block be moved by touch
end
end
if ( gameState == "Play" ) then
local WallTime = timer.performWithDelay( makeWallTime, createWall, 100 )
end
(note, this is not the full code, only the that involves the two objects) [import]uid: 69700 topic_id: 11876 reply_id: 311876[/import]