user1597438
user1597438

Reputation: 2221

Manipulating lines in Corona

I've created a line in Corona using display.newLine() thanks to tutorials online. I'm still learning, so I have a few questions.

Is it possible to create touch events for the drawn line? Like once I have the line on my scene, if I touch that line, something should happen.

If it is possible, how do I do this? I tried what I would do with other objects and used something like line:addEventListener("touch", something) but it did not work.

Also, is it possible to create some sort of animation for the drawn line? Like draw the line, the after a few frames, erase it and draw a new one? (I'm talking about automatically instead of drawing it through touch events)

Lastly, is it possible to draw a curved line using only 1 line? I'm trying to avoid having to use so many lines if I'm going to create some sort of animation using the line drawn.

Upvotes: 2

Views: 1366

Answers (1)

hjpotter92
hjpotter92

Reputation: 80639

Is it possible to create touch events for the drawn line?

Yes, according to Corona Labs API for LineObjects, the methods and properties are inherited from DisplayObject and one of those methods include EventListeners. You can try it like this:

local line = display.newLine( ... )
line:addEventListener( "tap", myFunc )

Is it possible to create some sort of animation for the drawn line? Like draw the line, the after a few frames, erase it and draw a new one?

Once again, yes. You can use the performWithDelay method from the timer table. An example would be like this:

i, line = 30, display.newLine( 20, 50, 200, 300 )
changeText = function()
  line.x1 = 20 + (i % 80)
  line.x2 = 50 + (i % 100)
  i = i * 2
end
timer.performWithDelay( 1000, changeText )

Is it possible to draw a curved line using only 1 line?

You need to read a bit about geometry. A line can not be curved. Otherwise a circle wouldn't be a polygon.

Upvotes: 1

Related Questions