Howdy! I just found Corona last week and I’m amazed to find that I’m already doing stuff with it. I still have to wrap my head around a few Lua concepts, but it’s going remarkably well so far.
I figured out how to use math.deg and atan2 to get the heading from one point to another, but here’s one that has me stymied. (My last trig class was around the time Aliens was showing in theaters – the original, not the digitally remastered version.)
I have an icon, 32x32, that contains a vertical line 32 pixels long and 6 pixels wide. I’m trying to locate it between two points, an arbitrary distance apart, and connect them. I figured I could scale the height of the icon and let rotation do the rest; but it looks like scaling always applies to the screen’s x and y directions, not the icon’s, so I just end up with distorted icons. (Sample code below – the GetDirection function returns a number of degrees from 0 to 359.999, with 0 being north.)
Does anyone know what I would do to calculate the correct x and y scales for a given rotation?
[lua] --FIXME: xScale and yScale apparently do not rotate with the object
–rail.xScale = distance / 32
rail.rotation = GetDirection(lastx, lasty, e.x, e.y)
rail.x = (lastx + e.x) / 2
rail.y = (lasty + e.y) / 2
railGroup:insert(rail)
rail:toFront()[/lua]
[import]uid: 117162 topic_id: 20533 reply_id: 320533[/import]
[import]uid: 52491 topic_id: 20533 reply_id: 80561[/import]