I thought about making something with ApeOut graphics long before it came out and its release motivated me to try - I'm having tons of fun but I stumbled upon a pickle.

I can imagine storing polygons is a very common task in game development. I'm prototyping with pygame and currently store each polygon as a list of Vector2 coordinates/vertices on a 10x10 field and keep these lists in a Python dict. This can't be a good practice.

  1. Is there an established format to store list of vertices (preferably supported by some free editor)? I was thinking about SVG but it works with curves and I only need straight edges. Or is SVG still the better option?
  2. What's a sensible way to store frames of an animation for such polygon (e.g. "deer" lowering its head when eating or moving its shoulders while walking, etc.; legs will be driven by invert kinematics)? Right now I'm thinking about each animation being a list of frames where each frame is list of vertices but it'll become unmanageable if I don't separate animations to different files.

What I have so far:

shapes = {
    # I edit this in my head, was fun, slowly becomes a nightmare
    'deer': [(5,0), (4,1), (2,0), (3,1), (2,1), (1,0), (1,1), (4,2), (3,3), (4,5), (3,7), (3,8), (5,10), (7,8), (7,7), (6,5), (7,3), (6,2), (9,1), (9,0), (8,1), (7,1), (8,0), (6,1)],

def loadShape(name, size):
    resolution = 10 # 10x10
    verts = shapes.get(name)
    scaled = [tuple((point[0]/resolution*size, point[1]/resolution*size)) for point in verts]
    surface = pygame.Surface((size, size), pygame.SRCALPHA)
    pygame.draw.polygon(surface, colors.get(name), scaled)
    return surface

Deer shape, scaled and rotated.

  • \$\begingroup\$ In games, we usually store and render these polygons as a 3D "mesh". Even though the gameplay of Ape Out uses a 2D presentation, I would not be surprised if it is using 3D models under the hood. That way you can take advantage of off-the-shelf 3D modelling software, standardized 3D mesh interchange formats, skeletal animation systems, and the GPU rendering pipeline, rather than micromanaging each individual vertex in your code. \$\endgroup\$
    – DMGregory
    Commented Feb 28, 2021 at 13:55
  • \$\begingroup\$ Well, that's a jump to an entirely different area but what I take from your comment is that I could store vertices in OBJ files and edit them in e.g. Blender. I'm not quite sure how to load only vertices from an OBJ as all libs I found so far create full blown 3D objects and require some extra OpenGL stuff which I don't need. Will look into that. Thank you. \$\endgroup\$
    – cprn
    Commented Feb 28, 2021 at 18:09
  • \$\begingroup\$ I moved to Ursina game engine for prototyping and store meshes in Blender files (Ursina translates those to OBJ on the fly) but it amazes me nobody posted a "standard" 2D solution yet. I managed to use SVG with "straight curves" (i.e. curves with only node data) but it seems like an overkill. Nothing simpler? Sounds like going with custom tool and format is best solution for now. \$\endgroup\$
    – cprn
    Commented Mar 4, 2021 at 11:24
  • \$\begingroup\$ That looks like it's worth posting as an Answer below. \$\endgroup\$
    – DMGregory
    Commented Mar 4, 2021 at 12:30
  • \$\begingroup\$ I thought about it and I don't consider "use a different engine and a 3d file format" a valid answer to a question about storing 2d polygons, it brings unnecessary complications. I don't believe the only real answer is "implement it yourself" either so I'll leave it open. \$\endgroup\$
    – cprn
    Commented Mar 30, 2021 at 11:59


You must log in to answer this question.

Browse other questions tagged .