Hello, i’m working on a 2d isometric game using pre-rendered sprites and i want to implement “paper doll” system where different pieces of armor and weapons can be drawn over the basic character sprite in various combinations.
I make it in GameMaker and it uses .sprite files to store the origin and order of the frames(just cropped png images in a folder).
I got a script that render all angles of the animation and make the .sprite files but it doesn’t crop the frames and i have to adjust the origin manually, so that the weapon is drawn in the character’s hand for example.
Here is the script:
import bpyimport os
from math import radians
angle = -45
axis = 2 # z-axis
platform = bpy.data.objects["RenderPlatform"]
original_path = bpy.data.scenes[0].render.filepath
directory = os.path.dirname(original_path)
image_width = bpy.data.scenes[0].render.resolution_x
image_height = bpy.data.scenes[0].render.resolution_y
base_name = os.path.basename(original_path)
base_rot = platform.rotation_euler
for i in range(0,8):
# rotate the render platform and all children
temp_rot = platform.rotation_euler
temp_rot[axis] = temp_rot[axis] - radians(angle)
platform.rotation_euler = temp_rot;
if i == 0:
direc = "S"
elif i == 1:
direc = "SW"
elif i == 2:
direc = "W"
elif i == 3:
direc = "NW"
elif i == 4:
direc = "N"
elif i == 5:
direc = "NE"
elif i == 6:
direc = "E"
elif i == 7:
direc = "SE"
name = base_name + direc
# set the filename direction prefix
bpy.data.scenes[0].render.filepath = os.path.join( directory , "images", name + "_#")
# original_path + "_" + prefix + "_"
# render animation for this direction
bpy.ops.render.render(animation=True)
#write GMS Sprite File
framecount = bpy.data.scenes[0].frame_end - bpy.data.scenes[0].frame_start
fname = os.path.join( directory, name + ".sprite.gmx")
file = open(fname, 'w')
file.write("<!--This Document is generated by CMR's Blender Script because the developers of GMS can't be bothered to create better importing.-->
")
file.write("<sprite>
")
file.write(" <type>0</type>
")
file.write(" <xorig>" + str(round(image_width/2,0)).rstrip('0').rstrip('.') + "</xorig>
")
file.write(" <yorigin>" + str(round(image_height/2,0)).rstrip('0').rstrip('.') + "</yorigin>
")
file.write(" <colkind>1</colkind>
")
file.write(" <coltolerance>0</coltolerance>
")
file.write(" <sepmasks>0</sepmasks>
")
file.write(" <bboxmode>0</bboxmode>
")
file.write(" <bbox_left>0</bbox_left>
")
file.write(" <bbox_right>" + str(round(image_width,0)).rstrip('0').rstrip('.') + "</bbox_right>
")
file.write(" <bbox_top>0</bbox_top>
")
file.write(" <bbox_bottom>" + str(round(image_height,0)).rstrip('0').rstrip('.') + "</bbox_bottom>
")
file.write(" <HTile>0</HTile>
")
file.write(" <VTile>0</VTile>
")
file.write(" <TextureGroups>
")
file.write(" <TextureGroup0>0</TextureGroup0>
")
file.write(" </TextureGroups>
")
file.write(" <For3D>0</For3D>
")
file.write(" <width>" + str(round(image_width,0)).rstrip('0').rstrip('.') + "</width>
")
file.write(" <height>" + str(round(image_height,0)).rstrip('0').rstrip('.') + "</height>
")
file.write(" <frames>
")
for j in range(0,framecount+1):
#file.write(' <frame index="' + str(j) + '">images\')
file.write(' <frame index="' + str(j) + '">images' + '\\' + name + "_" + str(j) + '.png</frame>
')
file.write(" </frames>
")
file.write("</sprite>
")
file.close()
bpy.data.scenes[0].render.filepath = original_path
base_rot[axis] = 0
platform.rotation_euler = base_rot;
That’s how the pieces look like: http://www.indiedb.com/games/bogarash-alpha/news/paper-doll-implementation
If i can expand the script to give them all the same origin(around the character’s belt) would be great.
Thank you!