LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

how do i turn data strings into sprites?

Root / Programming Questions / [.]

zagg2000Created:
...

Basically, figure out how to use an array and COPY, then figure out how FOR loops work, then discover GPSET. And then figure out how to use SPSET ID,U,V,W,H.

that does not help me at all. thanks.

that does not help me at all. thanks.
That's your choice. See, you have to put some effort in to being helped, too.

that does not help me at all. thanks.
That's your choice. See, you have to put some effort in to being helped, too.
When someone asks for help, they expect a good example of a codebase. And HOW to use it. people that teach must also make an effort to make a simplifyed explanation to the problem. -zagg

When someone asks for help, they expect
you expect (though you didn't ask for)
a good example of a codebase. And HOW to use it. people that teach must also make an effort to make a simplifyed explanation to the problem. -zagg
You were given an explanation for how to solve the problem yourself, which is what people that teach well do. There's some 'musts' for people who ask for help from unpaid volunteers, too. They must make it clear what their question is, for starters.

that does not help me at all. thanks.
That's your choice. See, you have to put some effort in to being helped, too.
When someone asks for help, they expect a good example of a codebase. And HOW to use it. people that teach must also make an effort to make a simplifyed explanation to the problem. -zagg
oh wow sorry i thought someone was going to make a real explanation NOTE: I SPENT AN HOUR ON THIS, I HOPE YOU DON'T EVER COME TO ME EVER AGAIN first off, don't use "strings" per se for your DATA pls. do it like this:
@LABELTHATISNOTALOOPTHANKYOUVERYMUCH
'    01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
Now for the colors! (You're going to use a predefined palette of colors defined HERE!)
'DawnBringer's 16 color palette plus the transparent color (Used in Petit Alchemy!)
@DB16
DATA 0,0,0,0
DATA 255,20 12 28
DATA 255,68,36,52
DATA 255,48,52,109
DATA 255,78,74,78
DATA 255,133,76,48
DATA 255,52,101,36
DATA 255,208,70,72
DATA 255,117,113,97
DATA 255,89,125,206
DATA 255,210,125,44
DATA 255,133,149,161
DATA 255,109,170,44
DATA 255,210,170,153
DATA 255,109,194,202
DATA 255,218,212,94
DATA 255,222,238,214
Now you're going to load it into some arrays like this:
DIM A[17],R[17],G[17],B[17]
RESTORE @DB16
FOR C=0 TO 16
 READ A[C]
 READ R[C]
 READ G[C]
 READ B[C]
NEXT
then make a 2-dimensional array (DIM SPR[X,Y]) and then use COPY to copy the DATA into that array (at this point you should be able to figure out how to use a command from its help page) then use something like
FOR X=0 TO 15
 FOR Y=0 TO 15
  GPSET OX+X,OY+Y,RGB( A[ SPR[X,Y] ],R[ SPR[X,Y] ],G[ SPR[X,Y] ],B[ SPR[X,Y] ] )
 NEXT
NEXT
to draw the sprite. Note that OX and OY should be changed in increments of 16, to ensure that your sprite stays with the grid.

Why are you flagging posts on this thread? (zagg2000)

OPTION STRICT

VAR W%, H%, I%, J%, K$, R%, G%, B%, ROW$
VAR PAL_KEY$[0], PAL_VAL%[0]

ACLS
GPAGE 0, 4 'LOOK AT THE REGULAR PAGE, DRAW ON THE SPRITE PAGE

'LOAD THE "PALETTE"
RESTORE @CLR_DATA
READ J%
FOR I% = 0 TO J% - 1
 READ K$, R%, G%, B%
 PUSH PAL_KEY$, K$
 PUSH PAL_VAL%, RGB(R%, G%, B%)
NEXT I%

'DRAW THE IMAGE
RESTORE @SPR_DATA
READ W%, H%
FOR J% = 0 TO H% - 1
 READ ROW$
 FOR I% = 0 TO MIN(W%, LEN(ROW$)) - 1
  GPSET I%, J%, LOOKUP(ROW$[I%])
 NEXT I%
NEXT J%

'DEFINE THE SPRITE WE JUST MADE, I AM PUTTING IT AT INDEX 0
SPDEF 0, 0, 0, W%, H%, W%/2, H% - 1, 1 'VISIBLE, CENTER AT BOTTOM MIDDLE, JUST BECAUSE

SPSET 0 OUT I%
SPSET 0 OUT J%

'COLOR ONE OF THEM 
SPCOLOR J%, RGB(255, 8, 8)
SPOFS I%, 42, 42
SPOFS J%, 142, 42
LOCATE 0, 10 'SO THE PROMPT DOESN'T DRAW OVER THE SPRITES AND WE CAN SEE THEM
END

DEF LOOKUP(KEY$)
 VAR I%
 FOR I% = 0 TO LEN(PAL_KEY$) - 1
  IF PAL_KEY$[I%] == KEY$ THEN
   RETURN PAL_VAL%[I%]
  ENDIF
 NEXT I%
END

@SPR_DATA
DATA 8, 8
DATA "AAAAAAAA"
DATA "AXXXXXXA"
DATA "AXAAAX A"
DATA "AXAAX  A"
DATA "AXAX A A"
DATA "AXX AA A"
DATA "AX     A"
DATA "AAAAAAAA"

@CLR_DATA
DATA 3
DATA "A", 127, 127, 127
DATA "X", 255, 255, 255
DATA " ", 32, 32, 32 
I think this is what the original poster wanted. How to define a sprite from data statements.I had been wondering it myself. It turns out the only hard part was figuring out which page to draw on. With this you can have custom sprites in your program without a separate data file. Nice for something with few graphics like say Tetris, or PacMan.

basically a different edit: less ghetto implementation of what i did I think this is what the original poster wanted.

OPTION STRICT

VAR W%, H%, I%, J%, K$, R%, G%, B%, ROW$
VAR PAL_KEY$[0], PAL_VAL%[0]

ACLS
GPAGE 0, 4 'LOOK AT THE REGULAR PAGE, DRAW ON THE SPRITE PAGE

'LOAD THE "PALETTE"
RESTORE @CLR_DATA
READ J%
FOR I% = 0 TO J% - 1
 READ K$, R%, G%, B%
 PUSH PAL_KEY$, K$
 PUSH PAL_VAL%, RGB(R%, G%, B%)
NEXT I%

'DRAW THE IMAGE
RESTORE @SPR_DATA
READ W%, H%
FOR J% = 0 TO H% - 1
 READ ROW$
 FOR I% = 0 TO MIN(W%, LEN(ROW$)) - 1
  GPSET I%, J%, LOOKUP(ROW$[I%])
 NEXT I%
NEXT J%

'DEFINE THE SPRITE WE JUST MADE, I AM PUTTING IT AT INDEX 0
SPDEF 0, 0, 0, W%, H%, W%/2, H% - 1, 1 'VISIBLE, CENTER AT BOTTOM MIDDLE, JUST BECAUSE

SPSET 0 OUT I%
SPSET 0 OUT J%

'COLOR ONE OF THEM 
SPCOLOR J%, RGB(255, 8, 8)
SPOFS I%, 42, 42
SPOFS J%, 142, 42
LOCATE 0, 10 'SO THE PROMPT DOESN'T DRAW OVER THE SPRITES AND WE CAN SEE THEM
END

DEF LOOKUP(KEY$)
 VAR I%
 FOR I% = 0 TO LEN(PAL_KEY$) - 1
  IF PAL_KEY$[I%] == KEY$ THEN
   RETURN PAL_VAL%[I%]
  ENDIF
 NEXT I%
END

@SPR_DATA
DATA 8, 8
DATA "AAAAAAAA"
DATA "AXXXXXXA"
DATA "AXAAAX A"
DATA "AXAAX  A"
DATA "AXAX A A"
DATA "AXX AA A"
DATA "AX     A"
DATA "AAAAAAAA"

@CLR_DATA
DATA 3
DATA "A", 127, 127, 127
DATA "X", 255, 255, 255
DATA " ", 32, 32, 32 
I think this is what the original poster wanted. How to define a sprite from data statements.I had been wondering it myself. It turns out the only hard part was figuring out which page to draw on. With this you can have custom sprites in your program without a separate data file. Nice for something with few graphics like say Tetris, or PacMan.
Omg thank you! Your a life saver