Comments

Log in with itch.io to leave a comment.

Deleted 8 years ago
(1 edit) (+1)

EDIT: This post looks a bit weird now that Bickers has deleted his comment. He was asking how to change the background image of the game. I'll leave this comment up in case it comes in useful for any other pygame beginners.


Hi Bickers

That's fairly simple to do actually. Firstly make sure you have python and pygame installed, then download my source code by clicking here(or fork it on GitHub if you know how).

In the file libengine.py, on line 50 you'll see it says

screen.fill((135, 206, 250)) # sky blue

What this does is fill 'screen', which is a Surface() object, with the colour (135, 206, 250), which corresponds to a nice sky blue. This line of code is in the update() function, which is run every frame, so about 60 times a second. The reason we have to fill the screen every frame is so it overwrites the previous frame - otherwise everything would have a kind of trail. Try deleting that line and running it to see how it would look.

To set a picture as the background, we firstly need to grab the picture from an image file (probably a .png file). If the picture was called "backgroundImage.png" and was in the same folder as libengine.py, you would add the following line of code somewhere at the top of the file (maybe line 15):

backgroundImgSurf = pygame.image.load("backgroundImg.png")

Obviously replace backgroundImg.png with your image name. This stores your image in a Surface() object.

Then you just need to replace line 50 with the following:

screen.blit(backgroundImgSurf, (0, 0))

What this does is blit your background image onto the screen, so that the top left of the background is at (0, 0), the top left of the game window. Blitting is a bit like sticking one bit of paper on top of another bit of paper.

You need to make sure your background image is 1200 pixels by 800 pixels, otherwise it won't properly fit the window.

Hope this helps! Thanks for playing my game - if you do use my code please do show me! And if you are planning on distributing your modified version of the game - that is fine and lovely, as long as you link people to jellyberg.itch.io somewhere :)