2

Given an image, how could one "wrap" that image around the screen?

For example, if you set the image's rect style object below the screen edge- the invisible half would blit onto the top of the screen.

imageRect.top=800 #Below screen edge
screen.blit(image,imageRect) #Blit on both sides of the screen

Is this by any ways possible (in pygame)?

double-beep
  • 5,031
  • 17
  • 33
  • 41
user2592835
  • 1,547
  • 5
  • 18
  • 26

2 Answers2

1

I don't think there's anything built in; just figure out where the vertical and horizontal divisions in the image are, and perform multiple blits.

user3757614
  • 1,776
  • 12
  • 10
1

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

jcarder
  • 164
  • 4
  • 17