Rpg Maker VX Resources
It's always Christmas here - New sprites daily!
Download over 1037 RMVX resources!


RMVX Window Lighting

This is a VX resource script that automatically creates an eye candy effect for “Tile C” RTP window tiles. It lets light stream in from the outside, like the screenshot shown above. Many people use “picture” type events for the same type of effect.

The instructions for this one are more complex than most scripts, but it’s also plug & play. If you can’t figure out what to change from looking below & at the script itself - don’t edit it!

AutoLightTiles[id] = [x-off,y-off,width,height]
AutoLightStart[id] = starting opacity
AutoLightColors[id] = color hash, alpha’s above
AutoLightOpac = opacity of ALL lights. can use as variable instead with “$game_variables[#]“. it’s an evaluated string
AutoLightZ = z layer for ALL lights

module GameBaker
  AutoLightTiles = Hash.new
  AutoLightTiles[280] = [8,4,16,56]
  AutoLightTiles[281] = [9,4,14,48]
  AutoLightTiles[283] = [12,5,10,36]
  AutoLightTiles[296] = [7,10,18,64]
  AutoLightTiles[297] = [9,10,14,64]
  AutoLightTiles[299] = [7,12,18,64]
  AutoLightTiles[300] = [7,12,18,64]
  AutoLightTiles[301] = [7,3,18,56]
  AutoLightTiles[302] = [7,3,18,48]
  AutoLightTiles[303] = [7,3,18,36]

  AutoLightColors = Hash.new([255,255,255])
  AutoLightColors[299] = [128,196,255]

  AutoLightStart = Hash.new(255)
  AutoLightStart[281] = 220
  AutoLightStart[283] = 134
  AutoLightStart[296] = 196
  AutoLightStart[297] = 220
  AutoLightStart[302] = 220
  AutoLightStart[303] = 134

  AutoLightOpac = “96″
  AutoLightZ = 100000
end

class Spriteset_Map
  alias gamebaker_autolight_init initialize
  def initialize
    create_gblights
    gamebaker_autolight_init
  end

  alias gamebaker_autolight_disp dispose
  def dispose
    if @gb_autolights
      @gb_autolights.dispose if !@gb_autolights.disposed?
      @gb_autolights = nil
    end
    gamebaker_autolight_disp
  end

  alias gamebaker_autolight_upd update
  def update
    update_gblights
    gamebaker_autolight_upd
  end

  def update_gblights
    return if !@gb_autolights
    @gb_autolights.opacity = eval(GameBaker::AutoLightOpac).to_i
    @gb_autolights.ox = $game_map.display_x / 8
    @gb_autolights.oy = $game_map.display_y / 8
  end

  def create_gblights
    data = $game_map.data
    for x in 0…$game_map.width
      for y in 0…$game_map.height
        next if data[x,y,2] == 0
        if GameBaker::AutoLightTiles.include?(data[x,y,2])
          create_gblight(data[x,y,2],x,y)
        end
      end
    end
  end

  def create_gblight(num,x,y)
    sg = GameBaker::AutoLightTiles[num]
    light = Bitmap.new(sg[2],sg[3])
    clr = GameBaker::AutoLightColors[num]
    start = GameBaker::AutoLightStart[num]
    num = (start).to_f
    numup = num / (sg[3] + 6).to_f
    for i in 0…sg[3]
      rect = Rect.new(0,i,sg[2],i+1)
      color = Color.new(clr[0],clr[1],clr[2],num.to_i)
      light.fill_rect(rect,color)
      num = (num -= numup)
      num = (num -= numup) if i < 6
    end
    if !@gb_autolights
      @gb_autolights = Sprite.new
      @gb_autolights.bitmap = Bitmap.new($game_map.width * 32,$game_map.height * 32)
      @gb_autolights.z = GameBaker::AutoLightZ
      @gb_autolights.opacity = eval(GameBaker::AutoLightOpac).to_i
    end
    @gb_autolights.bitmap.blt((x * 32) + sg[0],(y * 32) + sg[1],light,
      Rect.new(0,0,sg[2],sg[3]))
  end
end

16 Responses to “RMVX Window Lighting”

  1. VampireLordAlucard Says:

    When I try to use this, I get a syntax error at line 60. I don’t know anything about coding, could someone fix it?

  2. Rpg Maker VX Blog Says:

    Hmm, that’s odd. Shouldn’t be happening :( Wordpress might’ve messed up the script rgss2 code a bit I guess but no one else has reported it yet

  3. Mean1 Says:

    No. I am getting the same exact problem. I tired this a few days ago and got the same problem again

    This is the line that is messing up

    for x in 0…$game_map.width

  4. Rpg Maker VX Blog Says:

    That’s definitely not a problem with this rgss2 ruby light script then. Are you guys using a RMVX script that has a map for the title screen? $game_map not existing yet is the only reason I can think of for that

  5. Mean1 Says:

    I dont have a script like that no. I made my own Title screen. Besides its a syntax error. If the $game_map is non existent then wouldn’t it say
    unable to find graphic/picture/$game_map?

  6. Rpg Maker VX Blog Says:

    $game_map is a script variable made whenever someone hits “New game” or loads an old one. Treated differently than pictures, the window lights RMVX script expects a number :)

  7. Mean1 Says:

    So I need to find that number huh? hmmm…it shouldnt be that hard to find

  8. Mean1 Says:

    Last question…Where would I find that number? I mean I have looked all through my own scripts for it and cannot find it.

  9. SolstICE Says:

    sg u need to put link in script. people reposting it at places without credit

  10. Mean1 Says:

    Im crediting. I always do :P

  11. NamelessOne Says:

    Any word on the line 60 error yet?

  12. Kitezer Says:

    Why do I get line error 60? I can make a completely new game and just start it from scratch and ONLY put in that script and I still get that error. If there is something wrong with the coding please fix it because I would really like to use this code.

  13. Gamemaker2000 Says:

    for x in 0…$game_map.width
    (line 60)

    I have problems there =’ (
    Send me a mail if you know anything…
    thomas_dalen93@hotmail.com

  14. Gamemaker2000 Says:

    Rpg Maker VX Blog?? What number needed?

  15. Gamemaker2000 Says:

    mean1? do u know the number? if you do. please tell me! =D

  16. Rpg Maker VX Blog Says:

    We’re going to move this script over to another page like we did with our sparkly windows. It works as intended, and does for some other people, but it’s possible that wordpress might be messing it up in your browser

    Watch the front page for a few days and we’ll repost window lighting :)


Part of the Rpg Maker System category.

Tags, Eye candy, Rpg Maker code, Rpg Maker patch, Rpg Maker rtp, Rpg Maker window