본문 바로가기
루아(LUA)/마이크로스튜디오_예제

클릭할 때마다 배경색 바뀌는 예제

by JK77 2022. 1. 13.

아래 예제를 실행하면 검은 화면에서 마우스로 클릭할 때 마다 배경색이 바뀌게 됩니다.

http://lotusjk77.com/wp-content/game/mousepress/index.html

 

코드는 아래와 같습니다.

init = function()
  
end

update = function()
  
  function random_color()
    if mouse.press == 1 then
      r_color = math.random(255)
      g_color = math.random(255)
      b_color = math.random(255)
      delayTime = 60
      return "rgb("..r_color..","..g_color..","..b_color..")"  
    end
  end
  
  color = random_color()
end

draw = function()
  screen:fillRect(0,0,screen.width, screen.height,color)
end