Difference between revisions of "Determining location of mouse cursor"
m (1 revision) |
|||
(2 intermediate revisions by the same user not shown) | |||
Line 41: | Line 41: | ||
[[Category:Cursors]] | [[Category:Cursors]] | ||
[[Category:Mouse]] | [[Category:Mouse]] | ||
− | [[Category: | + | [[Category:I/O]] |
[[Category:Examples]] | [[Category:Examples]] |
Latest revision as of 17:56, 22 February 2016
By Cloudee1
This is a question that I recently asked at Mega-Tokyo in which Troflip was good enough to write up some code illustrating that exact functionality. This is a little snippet of code which I had hoped Troflip could enter here, but as he has not signed up yet and I really didn't want to lose this snippet as I plan to find a use for it, I have moved it here.
Troflip's code to get a view to follow the cursor broken up with small explanations added by me.
We first need to create an instance of an Actor, it needs to be an actor so that it can move around the screen. An init method has been included in the instance telling the actor to do what that script says.
(instance thing of Act
(properties
x 100
y 100
view 800
)
(method (init)
(super:init())
(self:setScript(thingScript))
)
)
Now that the instance is complete, we also need to create the script which the instances init method references.
(instance thingScript of Script
(properties)
(method (doit)
(var myEvent)
(super:doit())
(= myEvent Event:new(evNULL))
(send client:setMotion(MoveTo (send myEvent:x) (send myEvent:y)))
(send myEvent:dispose())
)
)
...and then of course do (thing:init()) in your room's init method.