morgans303 Posted August 25, 2011 Share Posted August 25, 2011 I plan on making a 2d 8-bit style side scroller in Python / Pygame. Does anyone have any tips on achieving background scrolling? Thanks! Quote Link to comment Share on other sites More sharing options...
suzumebachi Posted August 25, 2011 Share Posted August 25, 2011 just draw your background relative to the x position of your dude (or the x position of your screen if it's not locked to your dude). divide it by whatever number feels right to you. like 2. so for every 2 pixels your dude moves, the background moves 1 pixel. Quote Link to comment Share on other sites More sharing options...
morgans303 Posted August 25, 2011 Author Share Posted August 25, 2011 Ok, so I kinda screwed this up. I achieved background scrolling by keeping my character at a fixed point, and moving the background. It worked fine, until I added an patrolling enemy. He syncs with the background when standing still, but I haven't figured out how to make him patrol without falling out of sync with the level. One possible solution is to add collidable objects, but then he'd behave more like a lemming. Is there a better solution? Quote Link to comment Share on other sites More sharing options...
Tyler Gill Posted August 26, 2011 Share Posted August 26, 2011 Generally, the more intuitive the design is, the easier it is to add things to it without breaking other things. Keeping the player still and moving everything else on the stage seems like a really unintuitive workaround to me. I've never really used pygame, so I don't know what functionality it gives you, but in standard OOP design, these are the objects I'd have for this: Camera - invisible object who lives just to keep track of what the offset in the room is to draw everything. The other objects are draw with respect to this, and the background can simply be offset by the camera's x/someScale, y/someScale. Player - the human player, who moves based on keyboard input, and draws itself at its current x,y position each frame. Enemy - same concept as above, moves around and draws itself. Does that make sense? If you have a sample of the code, it'd be a lot easier to explain that way. Quote Link to comment Share on other sites More sharing options...
morgans303 Posted August 26, 2011 Author Share Posted August 26, 2011 Generally, the more intuitive the design is, the easier it is to add things to it without breaking other things. Keeping the player still and moving everything else on the stage seems like a really unintuitive workaround to me.I've never really used pygame, so I don't know what functionality it gives you, but in standard OOP design, these are the objects I'd have for this: Camera - invisible object who lives just to keep track of what the offset in the room is to draw everything. The other objects are draw with respect to this, and the background can simply be offset by the camera's x/someScale, y/someScale. Player - the human player, who moves based on keyboard input, and draws itself at its current x,y position each frame. Enemy - same concept as above, moves around and draws itself. Does that make sense? If you have a sample of the code, it'd be a lot easier to explain that way. Helpful. I'll have to research how to go about this in Python. There's a shortage of Python game development tutorials for sidescrollers. Quote Link to comment Share on other sites More sharing options...
FireSlash Posted August 26, 2011 Share Posted August 26, 2011 You're referring to Parallax Scrolling. This is a common technique in 2d game development. Syncing the parallax bgs with your fg though can be difficult, if you need it. Usually you'll need to use math to determine the right offsets as they relate to your bg. In most cases the BGs aren't important to the FG content so this isn't an issue. Your level should never move. Instead move the player, then have the camera follow the player. Quote Link to comment Share on other sites More sharing options...
morgans303 Posted August 26, 2011 Author Share Posted August 26, 2011 Your level should never move. Instead move the player, then have the camera follow the player. How to implement this in Python is my primary obstacle. Quote Link to comment Share on other sites More sharing options...
Kenogu Labz Posted August 27, 2011 Share Posted August 27, 2011 A useful skill you'll need to learn is the separation of the abstractions of the game from the programming language. In other words, it shouldn't matter here whether you're using Python, C#, Ruby, or any other language. The language is a vehicle to accomplish your goal (from a broad perspective, anyway. If you choose to program it in Scheme, that's a different issue altogether, hahah). From what I've seen of Python, you should be able to represent the camera as an object-type (or class). The camera would store, for example, the coordinates of the top-left view corner that would be presented to the player. In your game's logic loop, when drawing the graphics, you would then ask the current camera object where the corner is, and based on that, you would know where to draw the other entities in the level. If you're having a hard time understanding how an object-oriented system would work, I'd strongly advise picking up some books or, if possible, taking a course or two in basic programming. Even online tutorials can help you with those concepts. Trying to make any program - let alone a game - without understanding how to use the program structures available to you would just be fruitless and frustrating to you very quickly. Also make sure you know what Pygame does and doesn't do for you; you might need to build other supplementary structure that interfaces with Pygame to suit your game's system. Aaaaand sorry for the heavy jargon. D: Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.