serafim / ffi-sdl-mixer
PHP语言的SDL Mixer FFI绑定
2.0.1
2023-08-28 00:15 UTC
Requires
- php: ^8.1
- ext-ffi: *
- ffi-headers/contracts: ^1.0
- ffi/env: ^1.0
- ffi/location: ^1.0
- ffi/preprocessor: ^0.2
- ffi/proxy: ^1.0
- ffi/work-directory: ^1.0
- psr/simple-cache: ^1.0|^2.0|^3.0
- serafim/ffi-sdl: ^2.0
Requires (Dev)
- ffi/ide-helper-generator: ^0.1|^1.0
- friendsofphp/php-cs-fixer: ^3.22
- phpunit/phpunit: ^10.3
- symfony/cache: ^5.4|^6.0
- vimeo/psalm: ^5.14
This package is auto-updated.
Last update: 2024-08-28 02:35:43 UTC
README
A SDL_ttf扩展FFI绑定,兼容PHP语言的SDL FFI绑定。
要求
- PHP ^8.1
- ext-ffi
- Windows, Linux, BSD或MacOS
- Android, iOS或其他平台目前不支持
- SDL和SDL Mixer >= 2.0
安装
库作为composer仓库可用,可以使用以下命令在项目根目录安装。
$ composer require serafim/ffi-sdl-mixer
附加依赖
- 基于Debian的Linux:
sudo apt install libsdl2-mixer-2.0-0 -y
- MacOS:
brew install sdl2_mixer
- Windows: 可从此处下载
文档
库API完全支持并重复C语言中的类似功能。
初始化
如果你需要特定的SDL实例,应显式传递。
$sdl = new Serafim\SDL\SDL(version: '2.28.3'); $mixer = new Serafim\SDL\Mixer\Mixer(sdl: $sdl); // If no argument is passed, the latest initialized // version will be used. $mixer = new Serafim\SDL\Mixer\Mixer(sdl: null);
! 建议始终显式指定SDL依赖。
要显式指定库路径,可以在Serafim\SDL\Mixer\Mixer
构造函数中添加library
参数。
默认情况下,库将尝试自动解析二进制的路径。
// Load library from pathname (it may be relative or part of system-dependent path) $mixer = new Serafim\SDL\Mixer\Mixer(library: __DIR__ . '/path/to/library.so'); // Try to automatically resolve library's pathname $mixer = new Serafim\SDL\Mixer\Mixer(library: null);
您还可以显式指定库版本。根据此版本,SDL Image的相关功能将可用。
默认情况下,库将尝试自动解析SDL Image版本。
// Use v2.0.5 from string $mixer = new Serafim\SDL\Mixer\Mixer(version: '2.0.5'); // Use v2.6.3 from predefined versions constant $mixer = new Serafim\SDL\Mixer\Mixer(version: \Serafim\SDL\Mixer\Version::V2_6_3); // Use latest supported version $mixer = new Serafim\SDL\Mixer\Mixer(version: \Serafim\SDL\Mixer\Version::LATEST);
为了加快头文件编译器的速度,您可以使用任何PSR-16兼容的缓存驱动器。
$mixer = new Serafim\SDL\Mixer\Mixer(cache: new Psr16Cache(...));
此外,您还可以显式控制其他预处理器指令。
$pre = new \FFI\Preprocessor\Preprocessor(); $pre->define('true', 'false'); // happy debugging! $mixer = new Serafim\SDL\Mixer\Mixer(pre: $pre);
示例
use Serafim\SDL\SDL; use Serafim\SDL\Mixer\Mixer; $sdl = new SDL(); $mixer = new Mixer(sdl: $sdl); $sdl->SDL_Init(\Serafim\SDL\InitFlags::SDL_INIT_EVERYTHING); $mixer->Mix_Init(\Serafim\SDL\Mixer\InitFlags::MIX_INIT_MP3); $mixer->Mix_OpenAudio(44100, SDL::AUDIO_S16SYS, 2, 2048); $music = $mixer->Mix_LoadMUS(__DIR__ . '/example.mp3'); $mixer->Mix_PlayMusic($music, 0); while (true) { usleep(1); } $mixer->Mix_Quit(); $sdl->SDL_Quit();