c2ephp

sprites/SPRFile.php

Go to the documentation of this file.
00001 <?php
00002 require_once(dirname(__FILE__).'/SPRFrame.php');
00003 require_once(dirname(__FILE__).'/SpriteFile.php');
00004 require_once(dirname(__FILE__).'/../support/IReader.php');
00005 
00007 
00011 class SPRFile extends SpriteFile {
00012 
00014 
00018     public function SPRFile(IReader $reader) {
00019         parent::SpriteFile('SPR');
00020         $frameCount = $reader->ReadInt(2);
00021         
00022         for($i=0;$i<$frameCount;$i++) {
00023             $offset = $reader->ReadInt(4);
00024             $width = $reader->ReadInt(2);
00025             $height = $reader->ReadInt(2);
00026             $this->AddFrame(new SPRFrame($reader,$width,$height,$offset));
00027         }
00028     }
00029 
00031     public function Compile() {
00032       $data = pack('v',$this->GetFrameCount());
00033       $offset = 2+(8*$this->GetFrameCount());
00034       foreach($this->GetFrames() as $frame) {
00035         $data .= pack('V',$offset);
00036         $data .= pack('vv',$frame->GetWidth(),$frame->GetHeight());
00037         $offset += $frame->GetWidth()*$frame->GetHeight();
00038       }
00039       foreach($this->GetFrames() as $frame) {
00040         $data .= $frame->Encode();
00041       }
00042       return $data;
00043     }
00044 }
00045 ?>
 All Classes Files Functions Variables Enumerations