Hey, Thanks a lot for he reply!
His code example worked great! I am a bit of a novice to all this… so my first question… I was wondering how I can use this (code that you showed me). I want to make a invisible box:
local img2 = display.newRect(200, 100, 50, 50)
How can I make it invisible?
Now My 2nd object is a “ball” and I makes this in a different file:
local ball = require("ball")
How can I make it so that when “ball” makes contact with “img2” it changes scene (I will use director class). Would it look something like this? (I my be far off!!) :
function hitTestObjects(obj1, obj2)
local left = obj1.contentBounds.xMin \<= obj2.contentBounds.xMin and obj1.contentBounds.xMax \>= obj2.contentBounds.xMin
local right = obj1.contentBounds.xMin \>= obj2.contentBounds.xMin and obj1.contentBounds.xMin \<= obj2.contentBounds.xMax
local up = obj1.contentBounds.yMin \<= obj2.contentBounds.yMin and obj1.contentBounds.yMax \>= obj2.contentBounds.yMin
local down = obj1.contentBounds.yMin \>= obj2.contentBounds.yMin and obj1.contentBounds.yMin \<= obj2.contentBounds.yMax
return (left or right) and (up or down)
end
------------------------------------------------------------
local ball = require("ball")
local img2 = display.newRect(200, 100, 50, 50)
local function drag(event)
if event.phase == "moved" then
ball.x = event.x
ball.y = event.y
print(hitTestObjects(ball, img2))
end
end
ball:addEventListener( "enterFrame", movement )
I think this code is just a huge mess! So how can I do this? Also, (as you can see!) I am trying to use the Accelerometer… what should I put as the event listener?
Thanks again!
– [import]uid: 15281 topic_id: 7176 reply_id: 25325[/import]