将高清 TMX 瓦片图转换为 sd,我应该手动执行此操作



我有一个 960*640 像素的瓦片地图,使用 64*64 块瓷砖进行高清视网膜显示。现在,我需要一个用于 sd 显示的瓦片地图。(我猜应该是480 * 320像素使用32 * 32瓷砖)

那么,有没有简单的方法可以走呢?

在Mac应用商店中查找"Unretiner"之类的工具。

Unretiner
的"hd img -> sd img"HD TMX -> SD TMX" by ??

谢谢。

这是我用来从hd .tmx生成sd .tmx的Python脚本。您可以通过以下 shell 命令使用它。

>python change_tmx_numbers.py <directory_which_contains_hd_tmx_files> <output_directory>

脚本:

#!/usr/bin/python
import os
import shutil
import sys
import xml.etree.cElementTree as ET
import re

def npath(path):
  if path[-1] == '/':
    return path[:-1]
  return path;
def subdir(*paths):
  return '/'.join(paths)
def changeText(text):
  print text
  pointm = '{(?P<x>-?d+), (?P<y>-?d+)}'
  framem = '{{(?P<x>-?d+), (?P<y>-?d+)}, {(?P<width>d+), (?P<height>d+)}}'
  m = re.match(pointm, text)
  if m != None:
    rt = '{%d, %d}' % tuple([int(f) / 2 for f in m.groups()])
    print 'change %s -> %s' % (text, rt)
    return rt
  else:
    m = re.match(framem, text)
    if m != None:
      rt = '{{%d, %d}, {%d, %d}}' % tuple([int(f) / 2 for f in m.groups()])
      print 'change %s -> %s' % (text, rt)
      return rt
    else:
      print 'text: "' + text + '" is not matched'
      return text
def resizeElement(element):
  elems = list(element)
  if(len(elems) == 0 and element.text != None):
    element.text = changeText(element.text)
  else:
    for el in elems:
      resizeElement(el)
def resizeAttToHalf(attrib, keys):
  for key in keys:
    if key in attrib:
      attrib[key] = str(int(attrib[key]) / 2)
  return attrib
def resizeMap(map):
  map.attrib = resizeAttToHalf(map.attrib, ['tilewidth', 'tileheight'])

def resizeImage(im):
  im.attrib = resizeAttToHalf(im.attrib, ['width', 'height'])
  im.attrib['source'] = im.attrib['source'].replace('-hd', '')
def resizeTileset(ts):
  ts.attrib = resizeAttToHalf(ts.attrib, ['tilewidth', 'tileheight'])
  for image in ts.findall('image'): 
    resizeImage(image)
def resizeProperty(prop):
  if 'name' in prop.attrib and prop.attrib['name'] == 'points':
    points = prop.attrib['value'].split(' ')
    nps = [','.join([str(int(p.split(',')[0])/2), str(int(p.split(',')[1])/2)]) for p in points]
    prop.attrib['value'] = ' '.join(nps)
def resizePolygon(prop):
  points = prop.attrib['points'].split(' ')
  nps = [','.join([str(int(p.split(',')[0])/2), str(int(p.split(',')[1])/2)]) for p in points]
  prop.attrib['points'] = ' '.join(nps)
def resizeObject(obj):
  obj.attrib = resizeAttToHalf(obj.attrib, ['x', 'y', 'width', 'height'])
  for props in obj.findall('properties'):
    for prop in props.findall('property'):
      resizeProperty(prop)
  for poly in obj.findall('polygon'):
    resizePolygon(poly)
def resizeplist(plist, dest):
  doc = ET.parse(plist)
  map = doc.getroot()
  resizeMap(map)
  for tileset in map.findall('tileset'):
    resizeTileset(tileset)
  for objectg in map.findall('objectgroup'):
    for obj in objectg.findall('object'):
      resizeObject(obj)
  destf = open(dest, 'w')
  prologue = '<?xml version="1.0" encoding="UTF-8"?>n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">n'
  destf.write(prologue)
  doc.write(destf)
  destf.close()

def walkdir(path, dest):
  files =  [f for f in os.listdir(path) if not os.path.isdir(subdir(path, f))]
  dirs = [d for d in os.listdir(path) if  os.path.isdir(subdir(path, d))]
  for f in files:
    if (f.endswith('-hd.tmx')):
      resizeplist(subdir(path, f), subdir(path, f.replace('-hd', '')))
#  for d in dirs:
#    walkdir(subdir(path, d), subdir(dest, d))

if __name__ == "__main__":
  path = npath(sys.argv[1])
  dest = npath(sys.argv[2])
  walkdir(path, dest)

相关内容

最新更新