1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 from fife import fife
25 from fife.extensions.serializers import ET
26
28 f = engine.getVFS().open(filename)
29 f.thisown = 1
30
31 imgMgr = engine.getImageManager()
32
33 tree = ET.parse(f)
34 node = tree.getroot()
35
36 animation = fife.Animation.createAnimation()
37
38 common_frame_delay = int(node.get('delay', 0))
39 x_offset = int(node.get('x_offset', 0))
40 y_offset = int(node.get('y_offset', 0))
41 animation.setActionFrame(int(node.get('action', 0)))
42
43 frames = node.findall('frame')
44 if not frames:
45 raise InvalidFormat('animation without <frame>s')
46
47 for frame in frames:
48 source = frame.get('source')
49 if not source:
50 raise InvalidFormat('animation without <frame>s')
51
52 frame_x_offset = int(frame.get('x_offset', x_offset))
53 frame_y_offset = int(frame.get('y_offset', y_offset))
54 frame_delay = int(frame.get('delay', common_frame_delay))
55
56
57 path = filename.split('/')
58 path.pop()
59 path.append(str(source))
60
61 image_file = '/'.join(path)
62
63 img = imgMgr.create(image_file)
64 img.setXShift(frame_x_offset)
65 img.setYShift(frame_y_offset)
66
67 animation.addFrame(img, frame_delay)
68
69
70 return animation
71