how can I make an object go where I tap?!?!

how can I make the object go where I tap instead of the same place every time? here is my code.

tapTothrow = function (event)

    if event.phase == “began” then

        moneyBag = display.newImageRect(gameGroup,“play.png”,80,80)

        moneyBag.x = player.x + 50

        moneyBag.y = player.y 

        physics.addBody(moneyBag,{radius=35})

        moneyBag:setLinearVelocity(400, 0)

    end

end

Runtime:addEventListener(“touch”,tapTothrow)

The event record that’s passed in to the tapToThrow function has some useful properties – including the x and y coordinates of the tap.

So,

moneyBag.x = event.x moneyBag.y = event.y

…will probably get close to what you want.

You have the new object set to the same location as the player object, but you can’t do both. Either moneyBag can be set to the player x/y or to the event x/y.

 Jay

To add to J’s comment.

If you want the object to start at the players position but then move from there to where you touched… you could apply a transition after setting the objects coordinates to the player, on the next line add a transition that moves the object to event.x/.y

That should accomplish what you are after.

Hope this helps.

The event record that’s passed in to the tapToThrow function has some useful properties – including the x and y coordinates of the tap.

So,

moneyBag.x = event.x moneyBag.y = event.y

…will probably get close to what you want.

You have the new object set to the same location as the player object, but you can’t do both. Either moneyBag can be set to the player x/y or to the event x/y.

 Jay

To add to J’s comment.

If you want the object to start at the players position but then move from there to where you touched… you could apply a transition after setting the objects coordinates to the player, on the next line add a transition that moves the object to event.x/.y

That should accomplish what you are after.

Hope this helps.