I had the same problem when I attempted a side wrap drop and collect style game. On further inspection I found a way to achieve this feat with two images. Below is the code I used.
First create two variables display_width
and display_height
these are the width and height of your game window.
display_width = [width of window]
display_height = [height of window]
Next create two more variables for the 'x' position of the first and second images. Then declare the image width in pixels under the obj_width
variable.
img_x = ['x' position of first image]
img2_x = ['x' position of second image, works best with same 'x' as 'img_x' above]
obj_width = [width of img]
Now make a image function that takes the img_x
and img_y
. img_x
is a local variable and not to be confused with the other img_x
.
def img(img_x,img_y):
screen.blit([image file here], (img_x,img_y))
Here are the conditionals I used for the program. Feel free to copy and paste.
if img_x + img_width > display_width:
img(img2_x, display_height * 0.8)
img2_x = img_x - display_width
if img_x < 0:
img(img2_x, display_height * 0.8)
img2_x = img_x + display_width
if img2_x + bag_width > display_width:
img(img_x, [where you want the image to appear, ex. display_height * 0.8])
img_x = img2_x - display_width
if img2_x < 0:
img(img_x, display_height * 0.8) #same as above
img_x = img2_x + display_width
In this example the image moves horizontal, if you want vertical movement just change around the variables to your liking. I hope this answers your question, if something isn't working correctly or if their are any typos feel free to comment below. I know this was question was posted roughly a year ago, so sorry if its too late.
Good luck, JC