Code: Select all
import rfwindow, rfobjects
import menuelement
class menubackground(menuelement.menuelement):
def __init__(self, filename):
self.id = 'background'
self.image = rfobjects.image(filename)
self.centered = rfobjects.position()
self.centered.x = (rfwindow.getresolution().width - self.image.getsize().width)/2
self.centered.y = (rfwindow.getresolution().height - self.image.getsize().height)/2
self.image.setposition(self.centered)
del self.centered
Code: Select all
import rfwindow, rfobjects # Imports the RF2 built-in stuff needed by this script
import menuelement # Imports the very simple menuelement script, which this element is based off of
class menubackground(menuelement.menuelement): # Makes a new menu element, inheriting from menuelement
def __init__(self, filename): # This method is executed whenever a new background is made, filename is a string used to identify what image to use
self.id = 'background' # Tells the menu system that this element is a background
self.image = rfobjects.image(filename) # Make a member variable of this background called 'image', and load the image from disk
self.centered = rfobjects.position() # Make a new temporary position object
self.centered.x = (rfwindow.getresolution().width - self.image.getsize().width)/2 # Calculate the x position that will center the background
self.centered.y = (rfwindow.getresolution().height - self.image.getsize().height)/2 # Calculate the y position that will center the background
self.image.setposition(self.centered) # Move the background image to the center of the screen (which we just calculated)
del self.centered # Delete the temporary position object. Not needed, just tidyness