Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Draw line
Started by Miro Oct 15 2009 05:20 AM

- - - - -
4 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Miro

[GLOBAL: userInfoPane.html]
Miro
  • Enthusiast

  • 76 posts
  • Guests

Is it possible to draw a line in Corona?
uid: 3018 topic_id: 177 reply_id: 300177


[TOPIC: post.html]
#2

Jeff Johnson

[GLOBAL: userInfoPane.html]
Jeff Johnson
  • Contributor

  • 132 posts
  • Enterprise

By drawing a rect with a width of 1 pixel, you would be drawing a line. You cant say, here's cord. A and cord. B and tell it to connect the dots, you have to draw the box and give it a rotation (asusming A and B aren't on the same axis).

Do you have a code snippet of how you would want that to work? Its possible we may be able to add it somewhere down the road.
uid: 5 topic_id: 177 reply_id: 167


[TOPIC: post.html]
#3

Miro

[GLOBAL: userInfoPane.html]
Miro
  • Enthusiast

  • 76 posts
  • Guests

Hi, thanks for the reply. I found the Rect command but don't think it will work for what I want to do.
I'd like to be able to draw a line following the users finger

Something similar to :

' lineTo(_xmouse, _ymouse) ' in flash would be great.

or basically the ability to draw a line from point x to point y. Also found this: http://wiki.ps2dev.org/psp:lua_player:tutorial

would be nice to be able to do similar in Corona.

Thanks
uid: 3018 topic_id: 177 reply_id: 169


[TOPIC: post.html]
#4

Jeff Johnson

[GLOBAL: userInfoPane.html]
Jeff Johnson
  • Contributor

  • 132 posts
  • Enterprise

I will file a feature request for a simpler method, but I think its technically possible. You can extract coordinates from touch events and then have it draw/rotate based on those coordinates. Here's a simple coordinate finding method:
local t = display.newText( "Click the screen", 0, 0, nil, 12 )
t:setTextColor( 255, 255, 136, 255 )
[code]
local screenBounds = display.newRect( 0,0,320,480 )
screenBounds:setFillColor(255,255,255)
[code]
local function printEvent( event )
	local label = event.name
	if event.phase then
		label = label .. "." .. event.phase;
	end
	print( "event(" .. label .. ") hit("..event.x..","..event.y..")" )
end
[code]
function screenBounds:touch(event)
	local count = event.count
	printEvent (event)
	local phase = event.phase
	return true	
end
[code]
screenBounds:addEventListener( "touch",screenBounds)

You could then store the coordinates in an array and do something like:
[code=auto:0]
local cords = somearrayvalue
line.x = cords

etc. That should point you in the right direction I believe. I will investigate further and see if I can't get you some more code.
uid: 5 topic_id: 177 reply_id: 172


[TOPIC: post.html]
#5

Miro

[GLOBAL: userInfoPane.html]
Miro
  • Enthusiast

  • 76 posts
  • Guests

Thanks for that perfect for what I'm doing. Also would be nice to be able to fill as in flash x.beginFill x.endFill to achieve a polygon with fill color.
uid: 3018 topic_id: 177 reply_id: 181



[topic_controls]
[/topic_controls]