Scripts:Fake Parallax

From OHRRPGCE-Wiki
Jump to: navigation, search

Using nightly builds newer than 2011-06-06 it is possible to fake parallax scrolling of map layers using plotscripting.

This example script, taken from Wandering Hamster, requires one timer, and assumes that layer 0 of the map is 1/3 the width and 1/3 the height of the rest of the map. If you want your background layer to be some other size, you can customize the lines that set the layerw and layerh variables.

define constant(4, troll mountain parallax timer)


plotscript, troll mountain autorun, begin
  update troll mountain parallax
end

script, update troll mountain parallax, begin
  variable(sl, mapw, maph, screenw, screenh, layerw, layerh)
  if(current map <> map:troll mountain) then(
    stop timer(troll mountain parallax timer)
    sl := lookup slice(sl:map layer 0)
    set slice x(sl, 0)
    set slice y(sl, 0)
    exit script
  )
  mapw := map width * 20
  maph := map height * 20
  screenw := slice width(sprite layer)
  screenh := slice height(sprite layer)
  layerw := mapw / 3
  layerh := maph / 3
  sl := lookup slice(sl:map layer 0)
  set slice x(sl, (camera pixel x  * (mapw -- layerw) / (mapw -- screenw)))
  set slice y(sl, (camera pixel y  * (maph -- layerh) / (maph -- screenh)))
  set timer(troll mountain parallax timer, 0, 1, @update troll mountain parallax)
end

A small one-pixel lag of the background layer will be visible when using this script. It is not currently possible to avoid, but can be fixed with future engine updates.

Personal tools