Skip to content

Commit f662472

Browse files
committed
Add load_aseprite_file function and example usage in ASEPRITE.BAS
1 parent ac2e1a4 commit f662472

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed

ASEPRITE/ASEPRITE-INFO.BAS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ FUNCTION format_number$ (value AS LONG, width AS INTEGER)
886886
format_number$ = result
887887
END FUNCTION
888888

889-
$IF GJ_LIB_UNIFIED_TESTING = DEFINED AND GJ_LIB_INC_BI = UNDEFINED THEN
889+
$IF GJ_LIB_UNIFIED_TESTING = DEFINED AND GJ_LIB_INC_BM = UNDEFINED THEN
890890
'$INCLUDE:'../_GJ_LIB.BM'
891891
$END IF
892892

ASEPRITE/ASEPRITE.BAS

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
''
2+
' QB64_GJ_LIB
3+
' GRYMMJACK'S ASEPRITE LIB
4+
'
5+
' Simple example of using ASEPRITE in QB64
6+
'
7+
' USAGE:
8+
' Insert '$INCLUDE:'path_to_GJ_LIB/ASEPRITE/ASEPRITE.BI' at the top of file
9+
' Insert '$INCLUDE:'path_to_GJ_LIB/ASEPRITE/ASEPRITE.BM' at the bottom of file
10+
'
11+
' @see https://github.com/aseprite/aseprite/blob/main/docs/ase-file-specs.md
12+
' @author Rick Christy <grymmjack@gmail.com>
13+
'
14+
$IF GJ_LIB_UNIFIED_TESTING = DEFINED AND GJ_LIB_INC_BI = UNDEFINED THEN
15+
'$INCLUDE:'../_GJ_LIB.BI'
16+
$END IF
17+
18+
'$INCLUDE:'ASEPRITE.BI'
19+
20+
$CONSOLE
21+
22+
DIM filename AS STRING
23+
DIM aseprite_image AS LONG
24+
25+
filename = "test-files/DJ Trapezoid - Pumpkin Head.aseprite"
26+
27+
_ECHO "Loading: " + filename$
28+
29+
aseprite_image& = load_aseprite_file(filename$)
30+
IF aseprite_image& = 0 THEN
31+
_ECHO "Failed to load ASEPRITE image: " + filename$
32+
SYSTEM 0
33+
END IF
34+
35+
_TITLE "ASEPRITE ImageViewer"
36+
SCREEN _NEWIMAGE(_WIDTH(aseprite_image&), _HEIGHT(aseprite_image&), 32)
37+
_SCREENMOVE _MIDDLE
38+
_SOURCE aseprite_image&
39+
_DEST 0
40+
_PUTIMAGE
41+
SLEEP
42+
43+
SYSTEM 1
44+
45+
$IF GJ_LIB_UNIFIED_TESTING = DEFINED AND GJ_LIB_INC_BM = UNDEFINED THEN
46+
'$INCLUDE:'../_GJ_LIB.BM'
47+
$END IF
48+
49+
'$INCLUDE:'ASEPRITE.BM'

ASEPRITE/ASEPRITE.BM

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,6 +2109,34 @@ FUNCTION create_full_composite_image& (filename AS STRING, frame_index AS INTEGE
21092109
END FUNCTION
21102110

21112111

2112+
''
2113+
' Loads an ASEPRITE file and returns an ASEPRITE_IMAGE structure
2114+
'
2115+
' @param filename Path to ASEPRITE file
2116+
' @return LONG Image handle for composite image, or 0 on failure
2117+
'
2118+
FUNCTION load_aseprite_file& (filename AS STRING)
2119+
DIM ase_img AS ASEPRITE_IMAGE
2120+
DIM composite AS LONG
2121+
2122+
IF ASEPRITE_DEBUG_MODE THEN
2123+
_ECHO "Loading: " + filename$
2124+
END IF
2125+
CALL load_aseprite_image(filename$, ase_img)
2126+
2127+
IF ase_img.is_valid = _FALSE THEN
2128+
IF ASEPRITE_DEBUG_MODE THEN
2129+
_ECHO "Failed to load ASEPRITE: " + ase_img.error_message
2130+
END IF
2131+
load_aseprite_file& = 0
2132+
EXIT FUNCTION
2133+
ELSE
2134+
composite& = create_composite_image_from_aseprite&(ase_img)
2135+
load_aseprite_file& = composite&
2136+
END IF
2137+
2138+
END FUNCTION
2139+
21122140
''
21132141
' Creates a simple composite image from an already-loaded ASEPRITE_IMAGE
21142142
' This implementation composites each layer in file order using

0 commit comments

Comments
 (0)