Using a PNG file as an interactive map in pygame -



Using a PNG file as an interactive map in pygame -

i working pygame. want build 2d scrolling game. don't want have programme necessary rects in order create big map. possible utilize png file (which map) , have sprite interact part of image if rect? or import , convert image rects? in advance.

i assume "interact" you're referring collision detection (i.e. controlling on map character can , cannot move). that's broad topic lots of resources available.

look pygame.mask module (docs here). you're describing, create separate mask images overlaying levels e.g. 1 color areas cannot passed through , areas can. pygame.mask.from_threshold() automatically create mask object can utilize observe collisions between sprites , level.

as simple example, consider mario level:

a collision mask might this:

note boxes aren't accounted on mask despite beingness "part of level;" approach useful static pieces of level. boxes sprite own rect/mask observe collisions. in case, pipe solid object.

also note 1 big image entire level complex mask lead performance problems. in experience scrolling big image not pygame well.

tl;dr - it's possible (to extent), won't performance-friendly.

maps pygame

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -