-1

I'd like to make a map by using an image. It's supposed to be larger than the game screen so I need a way to scroll around said map as my character moves. How do I go about doing this?

I looked at some existing games but I'm still fairly new to Python and coding in general and didn't understand much.

I'm using Python 3.2 and Pygame 1.9.1.

mdakovac
  • 172
  • 1
  • 5
  • 17
  • What code have you tried? How are you showing the map in the first place, or constraining what the user sees? You should provide more specific context so that we can help you over specific obstacles you're running into. – Nathaniel Ford Oct 29 '12 at 18:59
  • Actually, I haven't tried anything, I had no idea how to start this. I see it can be done with offset variables which store where top left of the screen is located. – mdakovac Oct 30 '12 at 16:43

3 Answers3

1

A simple way could be to have an offset_x and offset_y variable. These variables store where the top left of the screen should be. When you render the image, make sure that it's x position is x + offset_x and y + offset_y.

RylandAlmanza
  • 1,358
  • 1
  • 8
  • 14
1

A bit of extra detail on the offset idea:

If you are planning to include obstacles such as trees in your map, you could have the trees be separate objects that you blit to a map surface. You can then use the offset to blit the map surface with all its obstacles and the player to the display before updating.

theroha
  • 11
  • 1
0

I wrote a simple demo that scrolls tiles: how to load an image to a grid using pygame, instead of just using a fill color?

Feel free to take the code. The concept is the same if you want to scroll a single image instead of tiles. You draw using an offset, like RyladAlmanza said.

tileset demo

Community
  • 1
  • 1
ninMonkey
  • 7,211
  • 8
  • 37
  • 66