My background works by creating 2 copies of the same image, and depending on which direction it is scrolling the 2nd image starts off of the screen and scrolls in while the first scrolls out. The moment one image is entirely off the screen its position is updated to flip sides
I just cannot figure out what is causing the gap.
This is the code for the displayable I created:
Code: Select all
python:
...
self.BG = SimpleBKG()
self.BG.createNew(Image('exampleimage.png', False, [-1,0], [1280, 720], 1)
...
self.BG.update(1)
...
self.BG.render( renderer, shownTimebase, animationTimebase )
Code: Select all
python:
import pygame
# Simple Background Object
class SimpleBKG():
def __init__(self):
# Initialize variables
self.image = None
self.active = False
self.position = [ 0, 0 ]
self.position2 = [ 0, 0 ]
self.static = True
self.speed = [0, 0]
self.dimXY = [0, 0]
def createNew(self, image, static, dirXY, dimXY, speed):
# Setup the background image
self.image = image
self.static = static
self.position = [ 0, 0 ]
self.position2 = [ (dimXY[0] * dirXY[0]), (dimXY[1] * dirXY[1]) ]
self.speed = [ (speed*dirXY[0]), (speed*dirXY[1]) ]
self.dimXY = [ dimXY[0], dimXY[1] ]
self.active = True
def update(self, deltaTime):
if ( self.active ):
if ( self.static == False ):
# Tile image
if ( self.position[0] < (-1 * self.dimXY[0]) ):
self.position[0] = self.dimXY[0]
if ( self.position[0] > self.dimXY[0] ):
self.position[0] = ( -1 * self.dimXY[0] )
if ( self.position[1] < (-1 * self.dimXY[1]) ):
self.position[1] = self.dimXY[1]
if ( self.position[1] > self.dimXY[1] ):
self.position[1] = ( -1 * self.dimXY[1] )
if ( self.position2[0] < (-1 * self.dimXY[0]) ):
self.position2[0] = self.dimXY[0]
if ( self.position2[0] > self.dimXY[0] ):
self.position2[0] = ( -1 * self.dimXY[0] )
if ( self.position2[1] < (-1 * self.dimXY[1]) ):
self.position2[1] = self.dimXY[1]
if ( self.position2[1] > self.dimXY[1] ):
self.position2[1] = ( -1 * self.dimXY[1] )
# Update position
self.position[0] += (self.speed[0] * deltaTime)
self.position[1] += (self.speed[1] * deltaTime)
self.position2[0] += (self.speed[0] * deltaTime)
self.position2[1] += (self.speed[1] * deltaTime)
def render( self, renderer, shownTimebase, animationTimebase ):
# Display this object
if ( self.active ):
r = renpy.render( self.image, SCENE_RIGHT, SCENE_DOWN, shownTimebase, animationTimebase )
renderer.blit( r, (self.position[0], self.position[1]) )
renderer.blit( r, (self.position2[0], self.position2[1]) )