For the life of me I can’t seem to figure out how to get access to the button itself within the onEvent method… I assumed there would be some sort of event.target but I must be missing it? [import]uid: 50570 topic_id: 8927 reply_id: 308927[/import]
Have you tried creating a forward reference to your button above the listener function and just referencing the button itself?
Example:
[blockcode]
local myButton
local onButtonTouch = function( event )
if event.phase == “release” then
local buttonX = myButton.x
local buttonY = myButton.y
print( "The position of the button is: " … buttonX … ", " … buttonY )
end
end
myButton = ui.newButon { …
[/blockcode]
Remember, when using forward references, you leave off the ‘local’ from the actual button declaration (as shown in the example above).
If that doesn’t help you, we’ll see what else we can do to enable you to reference your ui button from within your touch listener. [import]uid: 52430 topic_id: 8927 reply_id: 32606[/import]
Hey Jonathan, thanks for the timely response! 
I was actually spawning a group of cannons; 7 per side of the screen and couldn’t really forward reference it because the button was being created in the loop. Instead of using ui.lua I just used an imageRect and did :addEventListener and for some reason when you do it that way event.target is available from within your callback
Unfortunately I ran into another problem after solving that one… who would’ve thought?
I’m now trying to figure out how to determine which ‘side’ of my displayGroup was tapped. I want to rotate this thing left if the left side was tapped, and right if the right side was tapped. [import]uid: 50570 topic_id: 8927 reply_id: 32618[/import]
Did you try using event.x and event.y to determine where the user tapped? You can take that, along with the x/y coordinates of the actual object to determine if the user tapped a specific side (or more to one side than another, etc). [import]uid: 52430 topic_id: 8927 reply_id: 32625[/import]
Indeed! Once I figured out that I needed to insert my block into my group and then only set x relative to the reference point of the group… instead of relative to the screen… things started behaving a bit more like i expected during rotation.
The last bit of trouble I’m going to look into later today in regards to rotation is for a way to determine if there’s already a specific ‘type’ of transition running on an object… I’m having to make this rotation go extremely fast otherwise I can get more than one going at once and end up with my group at weird angles. I can’t just tm:cancelAll() because I have transitions going for my bullets as well as a y transition going on the group that moves it down the screen.
onBlocksTouch = function(event)
if event.phase == “ended” and gameIsActive then
local leftEdge = event.x - event.target.contentWidth * 0.5
local rightEdge = event.x + event.target.contentWidth * 0.5
local rotation = 90
if event.x >= leftEdge and event.x <= event.target.x then
rotation = -90
end
tm:add(event.target, { time=100, rotation=event.target.rotation + rotation })
end
end [import]uid: 50570 topic_id: 8927 reply_id: 32692[/import]