sky = background('Map Open1background NIGHT256.dmi', REPEAT_X + REPEAT_Y)
sky.width=256
sky.height=256
sky.px = -src.px*5
sky.py = -src.py*2
sky.owner=src
sky.show()
Readme
Background
vars
image/image
This is how the background image is displayed. If we just used
objs, every other player would be able to see your background. So,
we use images and attach them to an obj. You shouldn't ever have
to access this directly.
obj/object
If we used an obj to display your background, every other player
would be able to see it. So, we leave this obj blank but attach
images to it. The mob's set_camera proc adjusts the position of
this object to position the background based on px and py. You
shouldn't ever have to access this directly.
mob/owner
The mob that the background image is displayed for. Because the
position of the background can be different for different players,
you need to create a /Background object for each player.
px, py
The offset of the background image in pixels. By default (0, 0) the
lower left corner of the image is in the center of the screen.
width, height
The width and height of the image used to create the background.
procs
hide()
Removes the image from the owner's image list and removes the
/Background object from the owner's backgrounds list.
show()
Adds the image to the owner's image list and adds the /Background
object to the owner's backgrounds list.
Some words
I believe this line of code is more or less a direct copy of forum_account's sliding background demo. I have played with it extensively, read over the readme as well as the changelog extensively and still haven't gotten it to work the way I want it to.
Without any edits to the library, I believe it's impossible to edit the speed at which objects move. Which is a problem since not all background layers should move at the same speed and when they do, it's visually displeasing(A forest directly behind the player should move faster than the mountains on the horizon). Although, if you can edit this speed, please elaborate to me on how to do so.
Although, the speed at which the background moves is not my main concern: What I'd primarily like to do is have is to either:
1. Increase the amount of backgrounds displayed at once in order to cover the surface area needed OR
2. Line up two separate backgrounds which do not overlay one another in order to replicate the same thing, I believe this method shouldn't require an edit to the library.
// depending on the scroll_mode we need to create
// overlays to cover additional area:
//
// +---+ +---+---+
// | | | | |
// +---+ +---+---+ +---+ +---+---+
// | | | | | | | | | |
// +---+ +---+---+ +---+ +---+---+
// none: X: Y: X + Y:
//
In other words, instead of just X + Y, I'd like to have X + X + Y + Y, 8 boxes instead of 4.
I can replicate this by making my backgrounds 512x512 instead of 256x256 but this does not allow for me to edit my backgrounds directly in Dream Maker, which isn't preferred but something I can always fall back on.
So what's up guys, I know a fair share of the community is not overly fond of Forum_Account's libraries, although some of his libraries like this one in particular are unique and have yet to have someone replicate them. So please keep your concerns directed at my questions rather than the fact that I shouldn't be using these libraries in the first place.
Edit: Here is the full library:
// File: background.dm
// Library: Forum_account.Sidescroller
// Author: Forum_account
//
// Contents:
// This file contains the code for creating background
// objects. The code for updating the positions of
// background objects is in pixel-movement.dm
var
const
REPEAT_X = 1//1
REPEAT_Y = 2
// The /Background object contains the actual object
// and image that are the visual background display, it
// also contains size and position info. To move the
// background you change the px and py vars and the
// set_camera proc adjusts the background accordingly.
Background
var
obj/object
image/image
width
height
px = 0
py = 0
mob/owner
repeat = 0
New(mob/m, i, scroll_mode)
owner = m
repeat = scroll_mode
var/icon/I = new(i)
width = I.Width()
height = I.Height()
object = new()
object.animate_movement = 0
object.layer = 0
image = new(i, object)
image.layer = 0
// depending on the scroll_mode we need to create
// overlays to cover additional area:
//
// +---+ +---+---+
// | | | | |
// +---+ +---+---+ +---+ +---+---+
// | | | | | | | | | |
// +---+ +---+---+ +---+ +---+---+
// none: X: Y: X + Y:
//
if(scroll_mode & REPEAT_X)
var/obj/o = new()
o.layer = 0
o.icon = I
o.pixel_x = width
image.overlays += o
if(scroll_mode & REPEAT_Y)
var/obj/o = new()
o.layer = 0
o.icon = I
o.pixel_y = height
image.overlays += o
if(scroll_mode & REPEAT_X)
var/obj/o2 = new()
o2.layer = 0
o2.icon = I
o2.pixel_x = width
o2.pixel_y = height
image.overlays += o2
Del()
hide()
del image
del object
..()
proc
show()
if(owner && owner.client)
owner.client.images += image
owner.backgrounds += src
image.layer=1
hide()
if(owner && owner.client)
owner.client.images -= image
owner.backgrounds -= src
mob
var
list/backgrounds = list()
proc
// This creates and returns a new /Background object.
background(i, scroll_mode = 0)
if(!client) return
if(scroll_mode == 0 || scroll_mode == REPEAT_X || scroll_mode == REPEAT_Y || scroll_mode == REPEAT_X | REPEAT_Y)
return new /Background(src, i, scroll_mode)
else
CRASH("[scroll_mode] is an invalid value for scroll_mode. Use zero or the REPEAT_X and REPEAT_Y constants.")
// This proc exists to be overridden. By default it does
// nothing but it's called from set_camera to give you a
// chance to adjust the px/py of backgrounds every time
// the camera moves.
set_background()
I implemented the parallax scrolling backgrounds with his library by overriding his mob.set_background().
Here's what mine ended up looking like:
The coefficients to spx and spy determine the speed at which the background scrolls. The smaller this coefficient, the further away the background will appear to be.
camera is from Forum_account's sidescroller library.