Quantcast
Channel: Сообщество PHP DevelStudio - среда разработки программ
Viewing all articles
Browse latest Browse all 6336

Спрайтовая анимация (набросок)

$
0
0
Делать с утреца было совершенно нечего :-) решил попробовать реализовать спрайтовую анимацию... дээсные игроделы, специально для вас ^_^



Картинка из примера (файл "hero_1.png"):


Скрипт проекта:
Скрытый текст:

PHP код:

c("Form1")->doubleBuffered true// что-бы не было мерцаний

$sprite_img "hero_1.png"// это наша спрайтовая картинка
$sprite_width 64// ширина одного "кадра" - картинки
$sprite_height 70// высота картинки
$sprite_count 8// кол-во кадров

function thread_func($self) {
  
$args igbinary_unserialize(gui_threaddata($self'args'));
  
  
// загружаем спрайт из файла
  
$sprite_img imagecreatefromPNG($args['sprite_img']);
  
  
$count = -1;
  while(
true)
  {
    
$count $args['sprite_count'] - $count++ : $count 0;
    
    
// создаем прозрачное изображение
    //
    // п.с. возможно можно как-то вынести этот участок кода из цикла
    // и копировать ресурс, чтобы не вызывать кучу функций =)
    
$sprite imagecreatetruecolor($args['sprite_width'], $args['sprite_height']);
    
imagealphablending($spritefalse);
    
$color imagecolorallocatealpha($sprite255255255127);
    
imagefilledrectangle($sprite00$args['sprite_width'], $args['sprite_height'], $color);
    
imagealphablending($spritetrue);
    
imagesavealpha($spritetrue);
  
    
// вырезаем нужный "кадр" 
    
imagecopyresampled($sprite$sprite_img00$args['sprite_width'] * $count0$args['sprite_width'], $args['sprite_height'], $args['sprite_width'], $args['sprite_height']);
    
    
// выводим 
    
ob_start(); 
    
imagepng($sprite); 
    
$str ob_get_clean();
    
    
// устанавливаем картинку
    
$args["image1"]->picture->loadFromStr($str'png'); 
    
    
ImageDestroy($sprite);
    
usleep(100000);
  }
}

// создаем картинку для будущего персонажа
$image = new TImage();
$image->5;
$image->40;
$image->$sprite_width;
$image->$sprite_height;
$image->parent c("form1");

$args['image1'] = $image;
$args['sprite_img'] = $sprite_img;
$args['sprite_width'] = $sprite_width;
$args['sprite_height'] = $sprite_height;
$args['sprite_count'] = $sprite_count;
$args['sprite'] = $sprite;

// создаем поток
// p.s. не получилось завести поток без глобалки ;-(
global $th;
$th gui_threadcreate();
gui_threaddata($th'args'igbinary_serialize($args));
event_set($th'onExecute''thread_func');

$b1 = new TBitBtn();
$b1->80;
$b1->25;
$b1->5;
$b1->5;
$b1->text "run";
$b1->parent c("form1");
$b1->onMouseDown  = function() { 
  global 
$th;
  
gui_threadresume($th); 
};

$b2 = new TBitBtn();
$b2->80;
$b2->25;
$b2->85;
$b2->5;
$b2->text "stop";
$b2->parent c("form1");
$b2->onMouseDown  = function() { 
  global 
$th;
  
gui_threadSuspend($th); 
}; 


Viewing all articles
Browse latest Browse all 6336

Latest Images

Trending Articles

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>