tips_con_020 - spoolkitamura/nyle-doc-jp GitHub Wiki

ใ‚ญใƒผใƒœใƒผใƒ‰ใŒๆŠผใ•ใ‚ŒใŸใ‹ใฉใ†ใ‹ใ‚’่ชฟในใ‚‹ใซใฏ๏ผŸ

key_down?ใƒกใ‚ฝใƒƒใƒ‰ใพใŸใฏ key_press?ใƒกใ‚ฝใƒƒใƒ‰ใง
ใ‚ญใƒผใƒœใƒผใƒ‰ใŒๆŠผใ•ใ‚ŒใŸใ‹ใฉใ†ใ‹ใ‚’่ชฟในใ‚‹ใ“ใจใŒใงใใพใ™ใ€‚

key_down?ใฏใ‚ญใƒผใƒœใƒผใƒ‰ใŒๆŠผใ•ใ‚Œใฆใ„ใ‚‹้–“ใฏใšใฃใจ trueใ‚’่ฟ”ใ—ใ€
key_press?ใฏใ‚ญใƒผใƒœใƒผใƒ‰ใŒๆŠผใ•ใ‚ŒใŸ็žฌ้–“ใ ใ‘ trueใ‚’่ฟ”ใ—ใพใ™ใ€‚

[้–ข้€ฃๆƒ…ๅ ฑ]
key_down-
key_press-
key_release-
Appendix2-Keycodes

 

  • ใ‚นใƒšใƒผใ‚นใ‚ญใƒผใŒๆŠผใ•ใ‚Œใฆใ„ใ‚‹้–“ใ ใ‘ใ€Œ่ตคใ€ใง่กจ็คบใ™ใ‚‹
require 'nyle'

class Screen < Nyle::Screen
  def initialize
    super(200, 200, {bgcolor: :IVORY})
    @color = :BLACK
  end

  def draw
    Nyle.draw_text(40, 110, "Nyle", {color: @color, size: 50})
  end

  def update
    if Nyle.key_down?(KEY_space)
      @color = :RED
    else
      @color = :BLACK
    end
  end
end

Screen.new.show_all
Nyle.main

[ๅฎŸ่กŒ็ตๆžœ]


  • ใ‚นใƒšใƒผใ‚นใ‚ญใƒผใŒๆŠผใ•ใ‚Œใ‚‹ใŸใณใซใ€Œ้ป’ใ€ใจใ€Œ่ตคใ€ใจใง่‰ฒใ‚’ๅค‰ใˆใฆ่กจ็คบใ™ใ‚‹
require 'nyle'

class Screen < Nyle::Screen
  def initialize
    super(200, 200, {bgcolor: :IVORY})
    @color = :BLACK
  end

  def draw
    Nyle.draw_text(40, 110, "Nyle", {color: @color, size: 50})
  end

  def update
    if Nyle.key_press?(KEY_space)
      if @color == :BLACK
        @color = :RED
      else
        @color = :BLACK
      end
    end
  end
end

Screen.new.show_all
Nyle.main

[ๅฎŸ่กŒ็ตๆžœ]