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
Post a Comment