tazdij / raylib-pas

A complete header translation (binding) of the raylib 2.6.0-dev to Pascal. Without any funky helper functions for memory alignment issues. Inspired and partially based on the drezgames/raylib-pascal binding, however a little cleaner and more recent, with FPC 3.0.4 support.
28 stars 5 forks source link

PlayAudioBuffer() : No audio buffer #14

Closed GuvaCode closed 4 years ago

GuvaCode commented 4 years ago

when using TSound, the program just crashes ...

When loading, for some reason, the data is immediately unloaded. error

my example

program sprite_explosion;

{$mode objfpc}

uses cmem, raylib, math;

const screenWidth = 800; screenHeight = 450;

NUM_FRAMES_PER_LINE = 5; NUM_LINES = 5;

var fxBoom:TSound; explosion:TTexture2D; position:TVector2; frameRec: TRectangle; frameWidth,frameHeight,currentFrame,currentLine : integer; framesCounter:integer; active:boolean; begin InitWindow(screenWidth, screenHeight, 'raylib [textures] example - Sprite explosion'); InitAudioDevice(); fxBoom := LoadSound('res/boom.wav'); explosion := LoadTexture('res/explosion.png'); frameWidth := explosion.width div NUM_FRAMES_PER_LINE; // Sprite one frame rectangle width frameHeight := explosion.height div NUM_LINES; // Sprite one frame rectangle height currentFrame := 0; currentLine := 0; frameRec.x:=0; frameRec.y:=0; frameRec.height:=frameHeight; frameRec.width:=frameWidth;

position.y:=0.0; position.x:=0.0; active := false; framesCounter := 0; SetTargetFPS(120);

// Main game loop while not WindowShouldClose() do begin if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) and (not active) then begin position := GetMousePosition(); active := true; position.x := position.x- frameWidth/2; position.y := position.y - frameHeight/2; PlaySound(fxBoom); end; // Compute explosion animation frames if (active) then begin inc(framesCounter);// framesCounter++; if (framesCounter > 2) then begin inc(currentFrame);// currentFrame++; if (currentFrame >= NUM_FRAMES_PER_LINE) then begin currentFrame := 0; inc(currentLine);//++; if (currentLine >= NUM_LINES) then begin currentLine := 0; active := false; end; end; framesCounter := 0; end; end;

frameRec.x := frameWidthcurrentFrame; frameRec.y := frameHeightcurrentLine;

BeginDrawing(); ClearBackground(RAYWHITE);

if (active) then DrawTextureRec(explosion, frameRec, position, WHITE); EndDrawing(); end; UnloadTexture(explosion); // Unload texture UnloadSound(fxBoom); // Unload sound CloseAudioDevice(); CloseWindow(); // Close window and OpenGL context end.

GuvaCode commented 4 years ago

the problem is in the packet record. If you leave just record, everything works(in Linux it definitely works) PAudioStream = ^TAudioStream; TAudioStream = record sampleRate : dword; sampleSize : dword; channels : dword; buffer : PrAudioBuffer; end;
well at least one example is a plus