How to get and store screen positions
Monkey Forums/Monkey Beginners/How to get and store screen positions
| ||
I just started with all this , so dont hate me! I am scratching my head over how to store a screen XY position upon a touchdown. Can anyone give me some hints please? I suspect I am not quite grok'ing the data structures in Monkey. The line marked "BAD" is the problem, any help appreciated! (PS the dot.png is just a small circle) ==================================== Import mojo Global DataPoint : TPoint[ 99 ] Class Tpoint Field x : Float Field y : Float Method New(px : Float, py : Float ) Self.x=px Self.y=py End End Class StoreXY Extends App Field pointImage:Image Field points:=New List<Tpoint> Method OnCreate() pointImage=LoadImage( "dot.png",1,Image.XYPadding ) SetUpdateRate 60 End Method OnUpdate() Local out:=New List<Tpoint> For Local dot:=Eachin points out.AddLast dot Next For Local i=0 Until 32 If TouchDown( i ) points.AddLast New Tpoint( TouchX(i),TouchY(i) ) ' DataPoint[ 0 ] = New TPoint( TouchX(i),TouchY(i) ) <---BAD Endif Next End Method OnRender() Local w=DeviceWidth,h=DeviceHeight Cls For Local position:=Eachin points DrawImage pointImage,position.x,position.y End End End Function Main() New StoreXY End |
| ||
The global DataPoint is a TPoint, but for the class you had defined Tpoint. Monkey is case sensitive, so an TPoint <> Tpoint :-) if you change the DataPoint to a Tpoint as well it should work. BR Wyl |
| ||
Welcome.. When posting code if you use the following tags will enclose and format your code.Remove this space \/ [code]Print "Hello World" [ /code] |
| ||
Good spot Wylaryzel! much thanks! i've cleared it up now and it does what I wanted. and thanks Paul for the info re: posting code. I'll make sure I do that in the future. |