Ejemplo n.º 1
0
 public function layout(Job $job)
 {
     $packer = new GrowingPacker();
     $packer->maxWidth = $this->configuration->getInt('maxWidth', Configuration::VALUE_REQUIRED);
     $packer->maxHeight = $this->configuration->getInt('maxHeight', Configuration::VALUE_REQUIRED);
     $unpackedBlocks = [];
     foreach ($job->sprites as $sprite) {
         if (!$sprite->enabled) {
             continue;
         }
         $block = new GrowingPackerBlock($sprite->spriteOuterWidth, $sprite->spriteOuterHeight);
         $block->data = $sprite;
         $unpackedBlocks[] = $block;
     }
     $unpackedBlocks = $packer->sortBlocks($unpackedBlocks);
     while (count($unpackedBlocks)) {
         $spritesheet = $job->createSpritesheet();
         $result = $packer->pack($unpackedBlocks);
         foreach ($result->packedBlocks as $block) {
             /** @var Sprite $sprite */
             $sprite = $block->data;
             $sprite->spriteX = $block->node->x;
             $sprite->spriteY = $block->node->y;
             $spritesheet->addSprite($sprite);
         }
         $unpackedBlocks = $result->unpackedBlocks;
     }
 }
Ejemplo n.º 2
0
 public function layout(Job $job)
 {
     $naming = $this->configuration->getSubConfiguration('naming');
     $useSpriteName = $naming->getBool('useSpriteName');
     $prefix = $naming->getString('prefix');
     $suffix = $naming->getString('suffix');
     foreach ($job->sprites as $sprite) {
         if (!$sprite->enabled) {
             continue;
         }
         $sprite->spriteX = $sprite->spriteY = 0;
         $spritesheet = $job->createSpritesheet();
         $spritesheet->addSprite($sprite);
         if ($useSpriteName) {
             $spritesheet->name = $sprite->name;
         }
         $spritesheet->name = $prefix . $spritesheet->name . $suffix;
     }
 }