Package fife :: Package extensions :: Package serializers :: Module xmlanimation
[hide private]
[frames] | no frames]

Source Code for Module fife.extensions.serializers.xmlanimation

 1  # -*- coding: utf-8 -*- 
 2   
 3  # #################################################################### 
 4  #  Copyright (C) 2005-2009 by the FIFE team 
 5  #  http://www.fifengine.de 
 6  #  This file is part of FIFE. 
 7  # 
 8  #  FIFE is free software; you can redistribute it and/or 
 9  #  modify it under the terms of the GNU Lesser General Public 
10  #  License as published by the Free Software Foundation; either 
11  #  version 2.1 of the License, or (at your option) any later version. 
12  # 
13  #  This library is distributed in the hope that it will be useful, 
14  #  but WITHOUT ANY WARRANTY; without even the implied warranty of 
15  #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
16  #  Lesser General Public License for more details. 
17  # 
18  #  You should have received a copy of the GNU Lesser General Public 
19  #  License along with this library; if not, write to the 
20  #  Free Software Foundation, Inc., 
21  #  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA 
22  # #################################################################### 
23   
24  from fife import fife 
25  from fife.extensions.serializers import ET 
26   
27 -def loadXMLAnimation(engine, filename):
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 # xml paths are relative to the directory of the file they're used in. 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 # animation.thisown = 0 70 return animation
71