@@ -77,7 +77,7 @@ void TraceAseprite(Aseprite aseprite); // Display a
77
77
Texture GetAsepriteTexture (Aseprite aseprite ); // Retrieve the raylib texture associated with the aseprite
78
78
int GetAsepriteWidth (Aseprite aseprite ); // Get the width of the sprite
79
79
int GetAsepriteHeight (Aseprite aseprite ); // Get the height of the sprite
80
- int GetAsepriteTagCount (Aseprite aseprite ); // Get the total amount of available tags
80
+ int GetAsepriteTagCount (Aseprite aseprite ); // Get the total amount of available tags
81
81
void DrawAseprite (Aseprite aseprite , int frame , int posX , int posY , Color tint );
82
82
void DrawAsepriteV (Aseprite aseprite , int frame , Vector2 position , Color tint );
83
83
void DrawAsepriteEx (Aseprite aseprite , int frame , Vector2 position , float rotation , float scale , Color tint );
@@ -228,6 +228,8 @@ Aseprite LoadAsepriteFromMemory(unsigned char* fileData, unsigned int size) {
228
228
texturePointer -> width = texture .width ;
229
229
texturePointer -> height = texture .height ;
230
230
aseprite .ase = ase ;
231
+ TraceLog (LOG_INFO , "ASEPRITE: Loaded successfully (%ix%i - %i frames)" , ase -> w , ase -> h , ase -> frame_count );
232
+
231
233
return aseprite ;
232
234
}
233
235
@@ -285,6 +287,7 @@ inline Texture GetAsepriteTexture(Aseprite aseprite) {
285
287
texture .format = 0 ;
286
288
return texture ;
287
289
}
290
+
288
291
Texture2D * texturePointer = (Texture2D * )aseprite .ase -> mem_ctx ;
289
292
return * texturePointer ;
290
293
}
@@ -301,6 +304,7 @@ int GetAsepriteWidth(Aseprite aseprite) {
301
304
TraceLog (LOG_WARNING , "ASEPRITE: Cannot get width from non-existant aseprite" );
302
305
return 0 ;
303
306
}
307
+
304
308
return aseprite .ase -> w ;
305
309
}
306
310
@@ -316,6 +320,7 @@ int GetAsepriteHeight(Aseprite aseprite) {
316
320
TraceLog (LOG_WARNING , "ASEPRITE: Cannot get width from non-existant aseprite" );
317
321
return 0 ;
318
322
}
323
+
319
324
return aseprite .ase -> h ;
320
325
}
321
326
@@ -331,6 +336,7 @@ int GetAsepriteTagCount(Aseprite aseprite) {
331
336
TraceLog (LOG_WARNING , "ASEPRITE: Cannot get tag count non-existant aseprite" );
332
337
return 0 ;
333
338
}
339
+
334
340
return aseprite .ase -> tag_count ;
335
341
}
336
342
@@ -358,6 +364,8 @@ void UnloadAseprite(Aseprite aseprite) {
358
364
359
365
// Destory the aseprite data.
360
366
cute_aseprite_free (ase );
367
+
368
+ TraceLog (LOG_INFO , "ASEPRITE: Unloaded Aseprite data successfully" );
361
369
}
362
370
363
371
void DrawAseprite (Aseprite aseprite , int frame , int posX , int posY , Color tint ) {
@@ -406,14 +414,11 @@ void DrawAsepritePro(Aseprite aseprite, int frame, Rectangle dest, Vector2 origi
406
414
void TraceAseprite (Aseprite aseprite ) {
407
415
ase_t * ase = aseprite .ase ;
408
416
if (ase == 0 ) {
409
- TraceLog (LOG_INFO , "ASEPRITE: Empty file information" );
417
+ TraceLog (LOG_INFO , "ASEPRITE: Empty Aseprite information" );
410
418
return ;
411
419
}
412
420
413
- TraceLog (LOG_INFO , "ASEPRITE: File information:" );
414
- TraceLog (LOG_INFO , " > Size: %ix%i" , ase -> w , ase -> h );
415
- TraceLog (LOG_INFO , " > Frames: %i" , ase -> frame_count );
416
- TraceLog (LOG_INFO , " > Slices: %i" , ase -> slice_count );
421
+ TraceLog (LOG_INFO , "ASEPRITE: Aseprite information: (%ix%i - %i frames)" , ase -> w , ase -> h , ase -> frame_count );
417
422
TraceLog (LOG_INFO , " > Colors: %i" , ase -> number_of_colors );
418
423
TraceLog (LOG_INFO , " > Mode: %i" , ase -> mode );
419
424
TraceLog (LOG_INFO , " > Layers: %i" , ase -> layer_count );
@@ -427,6 +432,12 @@ void TraceAseprite(Aseprite aseprite) {
427
432
ase_tag_t * tag = ase -> tags + i ;
428
433
TraceLog (LOG_INFO , " - %s" , tag -> name );
429
434
}
435
+
436
+ TraceLog (LOG_INFO , " > Slices: %i" , ase -> slice_count );
437
+ for (int i = 0 ; i < ase -> slice_count ; i ++ ) {
438
+ ase_slice_t * slice = ase -> slices + i ;
439
+ TraceLog (LOG_INFO , " - %s" , slice -> name );
440
+ }
430
441
}
431
442
432
443
/**
@@ -530,6 +541,8 @@ void DrawAsepriteTagPro(AsepriteTag tag, Rectangle dest, Vector2 origin, float r
530
541
531
542
/**
532
543
* Generate an aseprite tag with sane defaults.
544
+ *
545
+ * @return An AsepriteTag with sane defaults.
533
546
*/
534
547
AsepriteTag GenAsepriteTagDefault () {
535
548
struct AsepriteTag tag ;
@@ -543,6 +556,7 @@ AsepriteTag GenAsepriteTagDefault() {
543
556
tag .loop = true;
544
557
tag .paused = false;
545
558
tag .name = 0 ;
559
+
546
560
return tag ;
547
561
}
548
562
@@ -559,30 +573,51 @@ AsepriteTag GenAsepriteTagDefault() {
559
573
*/
560
574
AsepriteTag LoadAsepriteTagFromIndex (Aseprite aseprite , int index ) {
561
575
AsepriteTag tag = GenAsepriteTagDefault ();
576
+
577
+ // Ensure the Aseprite exists.
562
578
ase_t * ase = aseprite .ase ;
563
579
if (ase == 0 ) {
564
580
TraceLog (LOG_ERROR , "ASEPRITE: Asprite not loaded when attempting to load tag #%i" , index );
565
581
return tag ;
566
582
}
567
583
584
+ // Ensure the tag exists
568
585
if (index < 0 || index >= ase -> tag_count ) {
569
586
TraceLog (LOG_ERROR , "ASEPRITE: Tag index %i out of range for %i tags" , index , ase -> tag_count );
570
587
return tag ;
571
588
}
572
589
590
+ // Base tag information
573
591
tag .aseprite .ase = aseprite .ase ;
574
592
tag .tag = & ase -> tags [index ];
575
- tag .currentFrame = tag .tag -> from_frame ;
593
+
594
+ // Set up the frame range
576
595
tag .direction = 1 ;
596
+ tag .currentFrame = tag .tag -> from_frame ;
577
597
if (tag .tag -> loop_animation_direction == ASE_ANIMATION_DIRECTION_BACKWORDS ) {
578
598
tag .currentFrame = tag .tag -> to_frame ;
579
599
tag .direction = -1 ;
580
600
}
581
- tag .timer = (float )(ase -> frames [tag .currentFrame ].duration_milliseconds ) / 1000.0f ; // Timer in seconds.
601
+
602
+ // Pause the animation if it's a one-frame tag
603
+ if (tag .tag -> from_frame == tag .tag -> to_frame ) {
604
+ tag .paused = true;
605
+ }
606
+
607
+ // Timer in seconds
608
+ tag .timer = (float )(ase -> frames [tag .currentFrame ].duration_milliseconds ) / 1000.0f ;
609
+
610
+ // Color
582
611
tag .color .r = (unsigned char )tag .tag -> r ;
583
612
tag .color .g = (unsigned char )tag .tag -> g ;
584
613
tag .color .b = (unsigned char )tag .tag -> b ;
614
+
615
+ // Name
585
616
tag .name = (char * )tag .tag -> name ;
617
+
618
+ // Display a trace log about the aseprite tag
619
+ TraceLog (LOG_TRACE , "ASEPRITE: [ID %i] Asprite tag loaded successfully (%s)" , index , tag .name );
620
+
586
621
return tag ;
587
622
}
588
623
@@ -612,7 +647,9 @@ AsepriteTag LoadAsepriteTag(Aseprite aseprite, const char* name) {
612
647
}
613
648
}
614
649
650
+ // Display a warning about the missing aseprite
615
651
TraceLog (LOG_WARNING , "ASEPRITE: Could not find tag \"%s\"" , name );
652
+
616
653
return tag ;
617
654
}
618
655
0 commit comments