Needing help with Alert Messages.

hello,

I am trying to get an alert message to appear in my game when you roll the triangle over top of the word finish. I have looked at the ghosts vs. monsters code, but it doesn’t seem to work. If you guys know how bubble ball has it when you make the ball hit the flag there is an alert message, how do i get my word finish to do something like that? any help would be greatly appreciated! Thanks in advance! [import]uid: 19836 topic_id: 8087 reply_id: 308087[/import]

You can just use a listener for when your object hits x and y coordinate of your word finished. [import]uid: 11809 topic_id: 8087 reply_id: 28834[/import]

Okay that sounds simple enough. So would i add the listener to what i have right here?

local F = display.newImage( "F.png", 120, 15 )  
localGroup:insert(F)  

Also, what listener would i add? [import]uid: 19836 topic_id: 8087 reply_id: 28839[/import]

Oops, sorry about my accident, I posted two times. My internet connection was not working right for a second. Disregard this post and follow the one below this. [import]uid: 19836 topic_id: 8087 reply_id: 28838[/import]

I don’t know which listener to use. Does anyone know the listener and can tell me please? [import]uid: 19836 topic_id: 8087 reply_id: 29079[/import]

Use a runtime like this:

local checkFinish = function(event)
–code here to check for finish
end

Runtime:addEventListener(“enterFrame”, checkFinish) [import]uid: 11809 topic_id: 8087 reply_id: 29086[/import]

okay thanks.
[import]uid: 19836 topic_id: 8087 reply_id: 29235[/import]

Where can i find the code to check for finish? I can’t seem to find it in the resources. [import]uid: 19836 topic_id: 8087 reply_id: 29237[/import]

Does this get you started?

[code]
local function hitTestObjects(obj1, obj2)
– added tollerance because collision was happening before touching
local tollerance = -1
local left = (obj1.contentBounds.xMin + tollerance) <= obj2.contentBounds.xMin and obj1.contentBounds.xMax >= (obj2.contentBounds.xMin + tollerance)
local right = obj1.contentBounds.xMin >= (obj2.contentBounds.xMin + tollerance) and (obj1.contentBounds.xMin + tollerance) <= obj2.contentBounds.xMax
local up = (obj1.contentBounds.yMin + tollerance) <= obj2.contentBounds.yMin and obj1.contentBounds.yMax >= (obj2.contentBounds.yMin + tollerance)
local down = obj1.contentBounds.yMin >= (obj2.contentBounds.yMin + tollerance) and (obj1.contentBounds.yMin + tollerance) <= obj2.contentBounds.yMax
return (left or right) and (up or down)
end – hitTestObjects

local img1 = display.newRect(0, 0, 50, 50)
img1.x = 50 ; img1.y = 50

local function drag(event)
if event.phase == “moved” then
img1.x = event.x
img1.y = event.y
end
end
img1:addEventListener(“touch”, drag)

local myText = display.newText(“drag the square over me to win”, 50,200, “Helvetica”, 16)

local function onComplete( event )
if “clicked” == event.action then
local i = event.index
if 1 == i then
print(“replay”)
elseif 2 == i then
print (“next level”)
end
end
end – onComplete

local function listenForWin(event)
if hitTestObjects(myText, img1) then
Runtime:removeEventListener(“enterFrame”, listenForWin)
local alert = native.showAlert( “You Win!”, “Congratulations”,
{ “replay”, “Next level” }, onComplete )
end
end – listenForWin
Runtime:addEventListener(“enterFrame”, listenForWin)
[/code] [import]uid: 12635 topic_id: 8087 reply_id: 29242[/import]

So i need to put that much in there? I guess i will try it. [import]uid: 19836 topic_id: 8087 reply_id: 29257[/import]

I have a video of what i want to accomplish because its easier to explain it that way.
http://www.youtube.com/watch?v=g79HV4IN_z4 [import]uid: 19836 topic_id: 8087 reply_id: 29263[/import]

should i just change a little bit in the above code to get what i want, or is there a different way of doing that for what i need as seen in the video i made. [import]uid: 19836 topic_id: 8087 reply_id: 29391[/import]

should i just use the square and all for my code? [import]uid: 19836 topic_id: 8087 reply_id: 29585[/import]

i have no clue what to do. [import]uid: 19836 topic_id: 8087 reply_id: 29740[/import]

Please explain your question, not just “I don’t know what to do.” For example, what have you tried and what happened? Post some code for us to react to.

Where can i find the code to check for finish? I can’t seem to find it in the resources.

Here’s one example, although it sounds like you are using physics in your game so you would probably want to use collision sensors:
http://developer.anscamobile.com/code/flashs-hittestobject-emulated-using-contentbounds [import]uid: 12108 topic_id: 8087 reply_id: 29828[/import]

oh okay sorry im still learning a lot since im a 14 y/o. anyway, heres the code i tried to use but it doesn’t seem to be transitioning to the next level when im touching the triangle with the F. also, im trying to get it so that i can add it to my local group.

  
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 img1 = display.newImage("triangle.png")  
local img2 = display.newImage("F.png")  
local function drag(event)  
 if event.phase == "moved" then  
 img1.x = event.x  
 img1.y = event.y  
 print(hitTestObjects(img1, img2))  
 end  
end  
img1:addEventListener("touch", drag)  
physics.addBody( img1, "dynamic", { bounce = 0 , density = 2, friction=0.7, isSensor=true} )--  
physics.addBody( img2, "dynamic", { bounce = 0 , density = 2, friction=0.7} )--  
local function collide(event)  
 if event.phase == "began" then  
 print ("COLLIDING")  
 end  
end  
img1:addEventListener("collision", collide)  
localGroup:insert(F)  
localGroup:insert(triangle)  

[import]uid: 19836 topic_id: 8087 reply_id: 29907[/import]

oh wait am i supposed to add something before the collision code? [import]uid: 19836 topic_id: 8087 reply_id: 30223[/import]