Changes

Jump to navigation Jump to search
→‎Check button state: update for SMAPI 3.3 release, tweak for readability
Line 62: Line 62:  
==APIs==
 
==APIs==
 
===Check button state===
 
===Check button state===
 +
<dl>
 +
<dt><tt>IsDown</tt></dt>
 +
<dd>
 
You can check if any controller/keyboard/mouse button is currently pressed by calling the <tt>IsDown(button)</tt> method. For example:
 
You can check if any controller/keyboard/mouse button is currently pressed by calling the <tt>IsDown(button)</tt> method. For example:
 
<source lang="c#">
 
<source lang="c#">
 
bool isShiftPressed = this.Helper.Input.IsDown(SButton.LeftShift) || this.Helper.Input.IsDown(SButton.RightShift);
 
bool isShiftPressed = this.Helper.Input.IsDown(SButton.LeftShift) || this.Helper.Input.IsDown(SButton.RightShift);
 
</source>
 
</source>
 +
</dd>
   −
{{SMAPI upcoming|3.3|content=For more finetuned control, you can check the button state relative to the previous game tick:
+
<dt><tt>GetState</tt></dt>
 +
<dd>
 +
For more finetuned control, you can check the button state relative to the previous game tick:
 
<source lang="c#">
 
<source lang="c#">
 
SButtonState state = this.Helper.Input.GetState(SButton.LeftShift);
 
SButtonState state = this.Helper.Input.GetState(SButton.LeftShift);
Line 73: Line 79:  
</source>
 
</source>
 
Available button states:
 
Available button states:
{{{!}} class="wikitable"
+
{| class="wikitable"
{{!}}-
+
|-
 
! previous tick
 
! previous tick
 
! current tick
 
! current tick
 
! resulting state
 
! resulting state
{{!}}-
+
|-
{{!}} ☐ up
+
| up
{{!}} ☐ up
+
| up
{{!}} <tt>None</tt>
+
| <tt>None</tt>
{{!}}-
+
|-
{{!}} ☐ up
+
| up
{{!}} ☑ down
+
| down
{{!}} <tt>Pressed</tt>
+
| <tt>Pressed</tt>
{{!}}-
+
|-
{{!}} ☑ down
+
| down
{{!}} ☑ down
+
| down
{{!}} <tt>Held</tt>
+
| <tt>Held</tt>
{{!}}-
+
|-
{{!}} ☑ down
+
| down
{{!}} ☐ up
+
| up
{{!}} <tt>Released</tt>
+
| <tt>Released</tt>
{{!}}}
+
|}
}}
+
</dd>
 +
</dl>
    
===Check cursor position===
 
===Check cursor position===
translators
8,404

edits

Navigation menu