Determining Location of Mouse Cursor: Difference between revisions

From Sierra Wiki
Jump to navigationJump to search
Andrew Branscom (talk | contribs)
m Andrew Branscom moved page Determining location of mouse cursor to Determining Location of Mouse Cursor without leaving a redirect
 
Andrew Branscom (talk | contribs)
No edit summary
 
(One intermediate revision by the same user not shown)
Line 51: Line 51:


[[Category:Cursors]]
[[Category:Cursors]]
[[Category:SCI Cursors]]
[[Category:Mouse]]
[[Category:Mouse]]
[[Category:SCI Mouse]]
[[Category:I/O]]
[[Category:I/O]]
[[Category:SCI I/O]]
[[Category:SCI I/O]]
[[Category:Examples]]
[[Category:Examples]]
[[Category:SCI Examples]]
[[Category:SCI Examples]]

Latest revision as of 19:51, 28 April 2025

SCI Tutorials SCI Tutorials and Guides


Determining Location of Mouse Cursor
By Cloudee1



Introduction

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.

Code:
(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.

Code:
(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.