Skip to content

Tutorial: Battle Backgrounds

WangledTeb edited this page Jan 14, 2024 · 5 revisions

Battle Backgrounds

EarthBound is unique in that, unlike other RPGs of its time, enemy sprites are displayed in front of a variety of psychedelic shifting and twisting backgrounds, referred to by the original development team as "Video Drugs" aka "Video Relaxants." CoilSnake allows you to customize these backgrounds to your liking in a surprisingly easy manner, with no need for frame-by-frame animation.

List of files used:

  • BattleBGs/
  • bg_data_table.yml
  • bg_distortion_table.yml
  • bg_scrolling_table.yml

Base Images

All of the images are extracted to the BattleBGs/ directory as PNG files, where their filename serves as an ID to identify them for CoilSnake. Each image is used as a base for a battle background defined in bg_data_table.yml (e.g. you can have one image referenced in multiple backgrounds), and depending on the settings of the background, it can go from being hardly modified to being changed almost beyond recognition, using the configuration settings described below.

To edit them, use a program that supports indexed palettes, such as GraphicsGale, Aesprite, or Photoshop in indexed mode.

Additionally, battle backgrounds can either have 4 or 16 colors. If you plan on having two backgrounds layered on top of each other, they both have to be 4 colors.

Configuration in bg_data_table.yml

Each entry describes the effects which should be applied to the image of the same ID in BattleBGs/. There are essentially three types of modifications which can be applied:

  • Colour depth - The depth of color and the palette can both be customized. This number determines the number of bits per pixel used to represent the image in the ROM. 4 stands for 4-bit (16 colors) and 2 stands for 2-bit (4 colors)
  • Distortion - Determines how the base image will be bent and stretched. The game engine will cycle through each distortion specified. The numbers correspond with bg_distortion_table.yml.
  • Palette Cycle - Cycles the palette based on the Palette Cycle Begin and End settings, and the Palette-Changing Speed (Calling it "Palette-Changing Speed" is a bit misleading because the number corresponds to the amount of frames the game will wait before cycling each colour to the next one in the palette. Therefore, higher numbers mean the palette cycles more slowly, and the fastest "speed" you can have is a value of 1.)

There are three different modes (four if you count 'none') available:

  • '1' just uses the values in Palette Cycle 1 Begin and Palette Cycle 1 End
  • 1 (reverse) uses the same values as '1', but cycles through them in reverse order
  • '1 + 2' uses both Palette Cycle Begin and End 1/2 simultaneously. (TODO: Do both palette cycles have to be the same length/number of colours? All the vanilla ones are.)

For example: Let's say your Palette Cycle is set to '1', your Palette Cycle 1 Begin is set to 1, your Palette Cycle 1 End is set to 4, and your Palette-changing speed is set to '60'. After 60 frames (one second, since the SNES displays images at 60 fps) all instances of palette colour 1 in your bg image will be changed to colour 2, all instances of colour 2 will be changed to colour 3, all instances of colour 3 will be changed to colour 4, and all instances of colour 4 will be changed to colour 1. 60 frames later, the same thing will happen again (meaning the colours that were originally colour 1 will now be colour 3!) It might make more sense if you just experiment a bit and see what happens!

  • Scrolling Movement - Determines how the game will scroll the image in both vertical and horizontal directions, as specified. The numbers correspond to bg_scrolling_table.yml.

Configuration in bg_distortion_table.yml

The distortion effects in Earthbound are achieved through HDMA, or "Horizontal Direct Memory Access". The short version is, it takes advantage of how old Cathode-Ray Tube televisions used to display images onscreen by updating the positions of the background each scanline, or mid-frame. (For more information, watch this video.) We don't really need to understand this to work with this file, because it's been simplified down to just a handful of parameters for us!

  • Ripple Amplitude - The max distance each line of pixels will be displaced from its starting point. (In other words, the strength of the "wave".) This is measured in 256ths of a pixel, so an amplitude of 256 means each "wave" will be 1 pixel high/wide.
  • Ripple Amplitude Acceleration - This will add a certain amount to the ripple amplitude each frame. These fields use signed 32bit values, meaning they go from $0000 to $FFFF (or, in decimal, 0 to 65535). Values from 1 to 32767 are positive, counting upwards, and values from 65535 to 32768 are negative, counting downwards. This means that if the acceleration value causes the amplitude to go from 32767 to 32768 you will see the background "jump" to from positive 32767 to negative 32767.
  • Ripple Frequency - This is the number of distinct "waves" onscreen at once. The higher the number, the more "waves" there are (and the shorter the length of each wave). If you set this high enough, it will stop looking like distinct waves and start looking more like noise.
  • Ripple Frequency Acceleration - This is the amount to add to the ripple frequency value each frame. Uses signed 32bit values like the Ripple Amplitude Acceleration field does, which means if you want to subtract from the Frequency value each frame, use a number from 65535 (negative 1) to 32768 (negative like. 32767 or something idk)
  • Speed - This is the speed at which the waves move onscreen. Not really sure how the math behind this one works, but higher values mean the waves look like they're moving faster. This can be from 0-255.
  • Type - There are four (five if you count unknown type 0/null) types of distortion to choose from:
  1. horizontal, smooth - the background is displaced in a wave-like (sinusoidal) pattern horizontally.
  2. horizontal, interlaced - the background is displaced in a wave-like pattern, but every second line is mirrored. This makes it look kind of like a helix?
  3. vertical, smooth - the background is displaced in a wave-like pattern, vertically. In practice this doesn't look so much like a wave because of how the image was displayed on CRTs. It looks more like the image is refracting or sometimes even splitting.
  4. unknown type 4 - this works like horizontal, interlaced, except it uses the compression and compression acceleration values to do a sort of skewing effect, where the lower a row is on the screen, the further displaced it is to the left or right. In-game this seems to be unused?

The bottom four values are listed as Unknown, but we actually do know what they do:

  • Unknown A - This is the duration of the distortion pattern. After this number of frames, its Ripple Amplitude and Ripple Frequency will be set back to their default values (only noticeable if the Acceleration values are set other than 0) and it will either restart or go to the next entry in the bg_data_table entry's distortion table. This can be set from 0-65535 (It's an unsigned value because negative duration wouldn't make any sense. Unless you have a Phase Distorter 2 in real life.)
  • Unknown B - This is the "phase" of the distortion. Basically, if you set this to something other than 0, the position of the waves will all be displaced. It also seems to interact with the acceleration values too: If you set Ripple Amplitude to 0, and Ripple Amplitude Acceleration to 1024 or something, and set Unknown B to something other than 0, the image will start out distorted. This can be any value from 0-255. (TODO: Understand this better and then explain it better)
  • Unknown C - In "vertical, smooth" mode: Known internally as "compression", this modifies the vertical offset of the background linearly, instead of sinusoidally. In theory, this means the image will look squished (for positive values 1-32767) and stretched for negative values (66535-32768). In "unknown type 4" mode, this will offset a line further to the left (for positive values) or to the right (for negative ones) the further down the screen it is. In practice, extreme values will give you all kinds of glitchy, trippy, and potentially seizure-inducing results, because the screen only has a height of about 224 pixels, so once pixels start being displaced by more than that amount they will loop back around to the other side of the screen. This gets even trippier and glitchier when combined with acceleration using Unknown D.
  • Unknown D - This also only has an effect in "vertical, smooth" and "unknown type 4" modes. This is the acceleration value for the compression. It works just like the acceleration values for ripple amplitude and frequency!

Configuration in bg_scrolling_table.yml

These values will be self-explanatory if you understand the bg_distortion_table! Horizontal and vertical movement control the rate of horizontal and vertical scrolling (to the right/down for positive values 1-32767, and to the left/up for negative values 66535-32768). Acceleration controls the increase/decrease of the scrolling rate over time.

Remember that you can have 4 distortion patterns and scrolling patterns per background! This means you can do some cool stuff like; have a scrolling pattern that gradually speeds up, then slows back down to 0, then starts scrolling in the opposite direction, then slows back down to 0 again. Each of those would be a separate entry in bg_scrolling_table, with their movements and accelerations set accordingly. Experiment and have a calculator onhand!

CAST SCREEN

  • It has been discovered (by Messianic) that battle background 279 is the black background connected to the Cast Screen at the end of the game. Modifying its data in the bg_data_table.yml has shown to cause the game to show a black screen at the Cast Screen and basically play the music with no graphics and then hang there. It is unable to progress beyond this. It is likely that modifying the battle background itself could also cause issues.

  • It is not currently know if other backgrounds and their data that are used for particular things like the Tea and Coffee scenes would cause the same error, but it is likely.

Clone this wiki locally