r3d_sprite.c 1012 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include "r3d.h"
  2. #include <raymath.h>
  3. R3D_Sprite R3D_LoadSprite(Texture2D texture, int xFrameCount, int yFrameCount)
  4. {
  5. R3D_Sprite sprite = { 0 };
  6. sprite.material = R3D_GetDefaultMaterial();
  7. sprite.material.albedo.texture = texture;
  8. sprite.material.blendMode = R3D_BLEND_ALPHA;
  9. sprite.material.billboardMode = R3D_BILLBOARD_Y_AXIS;
  10. sprite.frameSize.x = (float)texture.width / xFrameCount;
  11. sprite.frameSize.y = (float)texture.height / yFrameCount;
  12. sprite.xFrameCount = xFrameCount;
  13. sprite.yFrameCount = yFrameCount;
  14. return sprite;
  15. }
  16. void R3D_UnloadSprite(const R3D_Sprite* sprite)
  17. {
  18. R3D_UnloadMaterial(&sprite->material);
  19. }
  20. void R3D_UpdateSprite(R3D_Sprite* sprite, float speed)
  21. {
  22. R3D_UpdateSpriteEx(sprite, 0, sprite->xFrameCount * sprite->yFrameCount, speed);
  23. }
  24. void R3D_UpdateSpriteEx(R3D_Sprite* sprite, int firstFrame, int lastFrame, float speed)
  25. {
  26. sprite->currentFrame = Wrap(sprite->currentFrame + speed, (float)firstFrame, (float)lastFrame);
  27. }