Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
Joined: 25/06/2022 Location: United KingdomPosts: 2127
Posted: 01:50am 18 Oct 2024
Copy link to clipboard
Print this post
cool phil. hdmi mode 5 shows 4 blue, 8 green, 8 red.. but only shows 6 colours but nice demo another different problem you could help me with maybe please.
SPRITE LOADARRAY [#]n, w,h, array%() Creates the sprite 'n' with width 'w' and height 'h' by reading w*h RGB888 values from 'array%()'. The RGB888 values must be stored in order of columns across and then rows down starting at the top left. This allows the programmer to create simple sprites in a program without needing to load them from disk or read them from the display. The firmware will generate an error if 'array%()' is not big enough to hold the number of values required
how do I get data to array? ie make array instead of data and this crude way? ie create array with shortcut colour values
'copy data to screen for spht=0 to 15 for spw=0 to 15 read sp1 pixel spw+10,spht+10,sp1 next spw next spht 'read screen to sprite sprite READ 1,10,10,16,16
sprite1: data wh,bl,bl,bl,bl,bk,bk,bk,bk,bk,bk,bl,bl,bl,bl,wh data bk,bl,re,re,re,bl,bl,bk,bk,bl,bl,re,re,re,bl,bk data bk,bk,bk,bl,re,wh,bl,bk,bk,bl,wh,re,bl,bk,bk,bk data bk,bk,bk,bl,re,wh,bl,bk,bk,bl,wh,re,bl,bk,bk,bk data bk,bk,bk,bk,bl,wh,bl,bk,bk,bl,wh,bl,bk,bk,bk,bk data bk,bk,bk,bk,bk,bl,bl,bk,bk,bl,bl,bk,bk,bk,bk,bk data bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk data bk,bk,bk,bk,ye,ye,ye,bk,bk,ye,ye,ye,bk,bk,bk,bk data bk,bk,bk,ye,bk,bk,bk,bk,bk,bk,bk,bk,ye,bk,bk,bk data bk,ye,ye,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,ye,ye,bk data bk,ye,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,ye,bk data ye,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bl,ye data ye,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,ye data ye,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,ye data bk,ye,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,ye,bk data bk,bk,ye,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,ye,bk,bk
should have added 'colour shortcuts const WH =RGB(255, 255, 255) 'WHITE const YE =RGB(255, 255, 0) 'YELLOW const LI =RGB(255, 128, 255) 'LILAC const BR =RGB(255, 128, 0) 'BROWN const FU =RGB(255, 64, 255) 'FUCHSIA const RU =RGB(255, 64, 0) 'RUST const MA =RGB(255, 0, 255) 'MAGENTA const RE =RGB(255, 0, 0) 'RED const CY =RGB(0, 255, 255) 'CYAN const GR =RGB(0, 255, 0) 'GREEN const CE =RGB(0, 128, 255) 'CERULEAN const MI =RGB(0, 128, 0) 'MIDGREEN const CO =RGB(0, 64, 255) 'COBALT const MY =RGB(0, 64, 0) 'MYRTLE const BL =RGB(0, 0, 255) 'BLUE const Bk =RGB(0, 0, 0) 'BLACK const Gy =RGB(128, 128, 128) 'GREY const Lg =RGB(210, 210, 210) 'LITEGREY const Og =RGB(255, 165, 0) 'ORANGE const PK =RGB(255, 160, 171) 'PINK const Gd =RGB(255, 215, 0) 'GOLD const SA =RGB(250, 128, 114) 'SALMON const BE =RGB(245, 245, 220) 'BEIGE Edited 2024-10-18 12:27 by stanleyella
phil99
Guru
Joined: 11/02/2018 Location: AustraliaPosts: 2135
Posted: 02:26am 18 Oct 2024
Copy link to clipboard
Print this post
Mode 5 is 8 bits - RGB332, 3 bits = 8 shades. Black counts as a colour and the two brightest shades may be hard to tell apart. 256=8 bits
wh=RGB(white) bl=RGB(blue) re=RGB(red) ye=RGB(yellow) bk=RGB(black) my=RGB(myrtle) Option Base 0 Dim array%(255) '256 = 16 hor x 16 vert - 1 (-1 as array is Base 0)
For sp=0 To 255 Read array%(sp) Next sp
Sprite LOADARRAY #1, 16,16, array%() Sprite SHOW #1, 36,36,0
sprite1: Data wh,bl,bl,bl,bl,bk,bk,bk,bk,bk,bk,bl,bl,bl,bl,wh Data bk,bl,re,re,re,bl,bl,bk,bk,bl,bl,re,re,re,bl,bk Data bk,bk,bk,bl,re,wh,bl,bk,bk,bl,wh,re,bl,bk,bk,bk Data bk,bk,bk,bl,re,wh,bl,bk,bk,bl,wh,re,bl,bk,bk,bk Data bk,bk,bk,bk,bl,wh,bl,bk,bk,bl,wh,bl,bk,bk,bk,bk Data bk,bk,bk,bk,bk,bl,bl,bk,bk,bl,bl,bk,bk,bk,bk,bk Data bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk Data bk,bk,bk,bk,ye,ye,ye,bk,bk,ye,ye,ye,bk,bk,bk,bk Data bk,bk,bk,ye,bk,bk,bk,bk,bk,bk,bk,bk,ye,bk,bk,bk Data bk,ye,ye,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,ye,ye,bk Data bk,ye,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,ye,bk Data ye,bk,bk,bk,bk,my,bk,bk,bk,my,bk,bk,bk,bk,bl,ye Data ye,bk,bk,bk,bk,bk,bk,my,bk,bk,bk,bk,bk,bk,bk,ye Data ye,bk,bk,bk,bk,bk,bk,my,bk,bk,bk,bk,bk,bk,bk,ye Data bk,ye,bk,bk,bk,my,bk,bk,bk,my,bk,bk,bk,bk,ye,bk Data bk,bk,ye,bk,bk,bk,my,my,my,bk,bk,bk,bk,ye,bk,bk
Edited 2024-10-18 15:01 by phil99
stanleyella
Guru
Joined: 25/06/2022 Location: United KingdomPosts: 2127
Posted: 04:47pm 18 Oct 2024
Copy link to clipboard
Print this post
thanks phil, I was looking for dim sprite1(wh,bl,bl,bl,bl,bk,bk,bk,bk,bk,bk,bl,bl,bl,bl,wh, bk,bl,re,re,re,bl,bl,bk,bk,bl,bl,re,re,re,bl,bk, bk,bk,bk,bl,re,wh,bl,bk,bk,bl,wh,re,bl,bk,bk,bk, bk,bk,bk,bl,re,wh,bl,bk,bk,bl,wh,re,bl,bk,bk,bk, bk,bk,bk,bk,bl,wh,bl,bk,bk,bl,wh,bl,bk,bk,bk,bk, bk,bk,bk,bk,bk,bl,bl,bk,bk,bl,bl,bk,bk,bk,bk,bk, bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk, bk,bk,bk,bk,ye,ye,ye,bk,bk,ye,ye,ye,bk,bk,bk,bk, bk,bk,bk,ye,bk,bk,bk,bk,bk,bk,bk,bk,ye,bk,bk,bk, bk,ye,ye,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,ye,ye,bk, bk,ye,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,ye,bk, ye,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bl,ye, ye,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,ye, ye,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,ye, bk,ye,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,ye,bk, bk,bk,ye,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,ye,bk,bk)
but get Error : Expected closing bracket using mmedit regards, stan
stanleyella
Guru
Joined: 25/06/2022 Location: United KingdomPosts: 2127
Posted: 07:50pm 18 Oct 2024
Copy link to clipboard
Print this post
I stuck with my first option
cls restore sprite1:sht=15:swid=15 udg1 'draws sprite1 on screen at 10,10 sprite READ 1,10,10,16,16 'reads sprite1 from screen to blit buffer1
restore sprite2 udg1 'draws sprite2 on screen at 10,10 sprite read 2,10,10,16,16 'reads sprite2 from screen to blit buffer2
restore cannon:sht=9:swid=11 udg1 'draws sprite1 on screen at 10,10 sprite READ 3,10,10,12,10 'reads sprite1 from screen to blit buffer1
restore missile:sht=15:swid=0 udg1 'draws sprite1 on screen at 10,10 sprite READ 4,10,10,1,16 'reads sprite1 from screen to blit buffer1
sub udg1 'draws data for blit to copy for spht=0 to sht for spw=0 to swid read sp1 pixel spw+10,spht+10,sp1 next spw next spht end sub
using Dim array%(255) '256 = 16 hor x 16 vert - 1 (-1 as array is Base 0) 'restore sprite1 'For temp=0 To 255 'Read array%(temp) 'Next temp 'Sprite LOADARRAY #1, 16,16, array%() ' 'restore sprite2 'For temp=0 To 255 'Read array%(temp) 'Next temp 'Sprite LOADARRAY #2, 16,16, array%() ' 'restore cannon 'For temp=0 To 119 'Read array%(temp) 'Next temp 'Sprite LOADARRAY #3, 12,10, array%() ' 'restore missile 'For temp=0 To 15 'Read array%(temp) 'Next temp 'Sprite LOADARRAY #4, 1,16, array%()
can't use the array%() for other size sprites , each needs it's own array.
phil99
Guru
Joined: 11/02/2018 Location: AustraliaPosts: 2135
Posted: 08:28pm 18 Oct 2024
Copy link to clipboard
Print this post
The arrays don't need to be permanent, erase them after the sprite is created.
Dim array1%(xy1) 'make sprite 1 Erase array1%()
Dim array2%(xy2) 'make sprite 2 Erase array2%()
Dim array3%(xy3) 'make sprite 3 Erase array3%() Edited 2024-10-19 06:29 by phil99
stanleyella
Guru
Joined: 25/06/2022 Location: United KingdomPosts: 2127
Posted: 08:52pm 18 Oct 2024
Copy link to clipboard
Print this post
I was wondering if release or un dim was possible.thanks. big manual,gets bigger.
phil99
Guru
Joined: 11/02/2018 Location: AustraliaPosts: 2135
Posted: 09:19pm 18 Oct 2024
Copy link to clipboard
Print this post
Another option, make the array big enough for the biggest sprite so you can re-use it. Only erase it after all have been made.
Tested ok.
wh=RGB(white) bl=RGB(blue) re=RGB(red) ye=RGB(yellow) bk=RGB(black) my=RGB(myrtle) MODE 2 Option base 0 Dim array%(999)
For sp=0 To (16*16-1) '16 hor x 16 vert - 1 (-1 as array is Base 0) Read array%(sp) Next sp Sprite LOADARRAY #1, 16,16, array%()
For sp=0 To (16*5-1) '16 hor x 5 vert - 1 (-1 as array is Base 0) Read array%(sp) Next sp Sprite LOADARRAY #2, 16,5, array%()
Erase array%()
Sprite SHOW #1, 36,36,1 Sprite SHOW #2, 96,36,1
sprite1: Data wh,bl,bl,bl,bl,bk,bk,bk,bk,bk,bk,bl,bl,bl,bl,wh Data bk,bl,re,re,re,bl,bl,bk,bk,bl,bl,re,re,re,bl,bk Data bk,bk,bk,bl,re,wh,bl,bk,bk,bl,wh,re,bl,bk,bk,bk Data bk,bk,bk,bl,re,wh,bl,bk,bk,bl,wh,re,bl,bk,bk,bk Data bk,bk,bk,bk,bl,wh,bl,bk,bk,bl,wh,bl,bk,bk,bk,bk Data bk,bk,bk,bk,bk,bl,bl,bk,bk,bl,bl,bk,bk,bk,bk,bk Data bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk Data bk,bk,bk,bk,ye,ye,ye,bk,bk,ye,ye,ye,bk,bk,bk,bk Data bk,bk,bk,ye,bk,bk,bk,bk,bk,bk,bk,bk,ye,bk,bk,bk Data bk,ye,ye,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,ye,ye,bk Data bk,ye,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,ye,bk Data ye,bk,bk,bk,bk,my,bk,bk,bk,my,bk,bk,bk,bk,bl,ye Data ye,bk,bk,bk,bk,bk,bk,my,bk,bk,bk,bk,bk,bk,bk,ye Data ye,bk,bk,bk,bk,bk,bk,my,bk,bk,bk,bk,bk,bk,bk,ye Data bk,ye,bk,bk,bk,my,bk,bk,bk,my,bk,bk,bk,bk,ye,bk Data bk,bk,ye,bk,bk,bk,my,my,my,bk,bk,bk,bk,ye,bk,bk
Sprite2: Data ye,bk,bk,bk,bk,my,bk,bk,bk,my,bk,bk,bk,bk,bl,ye Data ye,bk,bk,bk,bk,bk,bk,my,bk,bk,bk,bk,bk,bk,bk,ye Data ye,bk,bk,bk,bk,bk,bk,my,bk,bk,bk,bk,bk,bk,bk,ye Data bk,ye,bk,bk,bk,my,bk,bk,bk,my,bk,bk,bk,bk,ye,bk Data bk,bk,ye,bk,bk,bk,my,my,my,bk,bk,bk,bk,ye,bk,bk
Edited 2024-10-19 07:29 by phil99
stanleyella
Guru
Joined: 25/06/2022 Location: United KingdomPosts: 2127
Posted: 11:34pm 18 Oct 2024
Copy link to clipboard
Print this post
this seems best and apart from data statements, leaves no waste, like using the screen but faster. live n learn didn't know Dim array%(16*16+16*16+12*10+1*16) works
Dim array%(255) '16x16 sprite restore sprite1 For temp=0 To 255:Read array%(temp):Next temp Sprite LOADARRAY 1, 16,16, array%() ' restore sprite2 '16x16 sprite For temp=0 To 255:Read array%(temp):Next temp Sprite LOADARRAY 2, 16,16, array%() erase array%() ' Dim array%(119) '12x10 sprite restore cannon For temp=0 To 119:Read array%(temp):Next temp Sprite LOADARRAY #3, 12,10, array%() erase array%() ' Dim array%(15) '1x16 sprite restore missile For temp=0 To 15:Read array%(temp):Next temp Sprite LOADARRAY #4, 1,16, array%() erase array%() ' Edited 2024-10-19 09:56 by stanleyella
phil99
Guru
Joined: 11/02/2018 Location: AustraliaPosts: 2135
Posted: 11:58pm 18 Oct 2024
Copy link to clipboard
Print this post
As the biggest sprite is 16 x 16 you only need to erase array%() after the last one. See my previous post, it doesn't matter if the array is bigger than the sprites.
Dim array%(16*16) is enough as for each sprite the For...Next starts from 0 again, overwriting the previous array elements.
Erase has been in the manual from the beginning.
Edit If you want to save some memory the data for symmetrical sprites can be cut in half and a mirror image of the first half put in the second half of the array. For vertical symmetry this is done line by line. Eg.
wh=RGB(white) bl=RGB(blue) re=RGB(red) ye=RGB(yellow) bk=RGB(black) my=RGB(myrtle) MODE 2 Option base 0 Dim array%(16*16-1) 'Size of largest Sprite
For sp=0 To (16*16-1) '-1 as array is Base 0 Read array%(sp) 'fill first half of each line n%=(15+sp)-(sp Mod 8)*2 'fill second half of each line in reverse order array%(n%)=array%(sp) If sp Mod 8 = 7 Then Inc sp,8 Next sp Sprite LOADARRAY #1, 16,16, array%()
For sp=0 To (15*5-1) 'Symmetrical sprite with an odd number of pixels Read array%(sp) 'fill first half of each line n%=(14+sp)-(sp Mod 8)*2 'fill second half of each line in reverse order array%(n%)=array%(sp) If sp Mod 8 = 7 Then Inc sp,8 array%(n%+8)=BK 'set the last pixel of each line to background colour EndIf Next Sprite LOADARRAY #2, 16,5, array%()
Erase array%()
Sprite SHOW #1, 36,36,1 Sprite SHOW #2, 66,36,1
sprite1: Data wh,bl,bl,bl,bl,bk,bk,bk Data bk,bl,re,re,re,bl,bl,bk Data bk,bk,bk,bl,re,wh,bl,bk Data bk,bk,bk,bl,re,wh,bl,bk Data bk,bk,bk,bk,bl,wh,bl,bk Data bk,bk,bk,bk,bk,bl,bl,bk Data bk,bk,bk,bk,bk,bk,bk,bk Data bk,bk,bk,bk,ye,ye,ye,bk Data bk,bk,bk,ye,bk,bk,bk,bk Data bk,ye,ye,bk,bk,bk,bk,bk Data bk,ye,bk,bk,bk,bk,bk,bk Data ye,bk,bk,bk,bk,my,bk,bk Data ye,bk,bk,bk,bk,bk,bk,my Data ye,bk,bk,bk,bk,bk,bk,my Data bk,ye,bk,bk,bk,my,bk,bk Data bk,bk,ye,bk,bk,bk,my,my
sp2: Data bk,bk,ye,bk,bk,my,bk,bk Data bk,ye,bk,bk,bk,bk,bk,my Data ye,bk,bk,bk,bk,bk,bk,my Data bk,ye,bk,bk,bk,my,bk,bk Data bk,bk,ye,bk,bk,bk,my,my
Edited 2024-10-19 15:07 by phil99
stanleyella
Guru
Joined: 25/06/2022 Location: United KingdomPosts: 2127
Posted: 06:01pm 19 Oct 2024
Copy link to clipboard
Print this post
Dim array%(16*16) is enough as for each sprite the For...Next starts from 0 again, overwriting the previous array elements. yes,works. I got error before with smaller than 16x16 sprites.
Dim array%(16*16) '16x16 sprite restore sprite1 For temp=0 To 255:Read array%(temp):Next temp Sprite LOADARRAY 1, 16,16, array%() ' restore sprite2 For temp=0 To 255:Read array%(temp):Next temp Sprite LOADARRAY 2, 16,16, array%() ' restore cannon For temp=0 To 119:Read array%(temp):Next temp Sprite LOADARRAY #3, 12,10, array%() ' restore missile For temp=0 To 15:Read array%(temp):Next temp Sprite LOADARRAY #4, 1,16, array%() erase array%() ' SPRITE READ [#]b, x, y, w, h and SPRITE WRITE [#]b, x, y [,mode] to draw half symmetrical sprite, reverse it and join on screen and read whole sprite. same for flipping any sprite, using screen can seem easier
stanleyella
Guru
Joined: 25/06/2022 Location: United KingdomPosts: 2127
Posted: 10:00pm 19 Oct 2024
Copy link to clipboard
Print this post
half symmetrical sprite using screen mode 2 OPTION BASE 0 ' 0 based arrays option DEFAULT INTEGER ' const WH =RGB(255, 255, 255) 'WHITE const Bk =RGB(0, 0, 0) 'BLACK const BL =RGB(0, 0, 255) 'BLUE const RE =RGB(255, 0, 0) 'RED const YE =RGB(255, 255, 0) 'YELLOW
cls restore sprite1:sht=15:swid=7 udg1 'draws sprite1 on screen at 10,10 sprite READ 1,10,10,8,16 'reads sprite1 from screen to blit buffer1 SPRITE WRITE 1,18,10,&B001 'inverts sprite horizontal and draws next to first half SPRITE CLOSE 1 'clears sprite 1 for reuse sprite READ 1,10,10,16,16 'reads whole sprite1 from screen to blit buffer1
sprite WRITE 1,10,50 'draws whole sprite end
sub udg1 'draws data for blit to copy for spht=0 to sht for spw=0 to swid read sp1 pixel spw+10,spht+10,sp1 next spw next spht end sub 'half symmetrical sprite data sprite1: data wh,bl,bl,bl,bl,bk,bk,bk ',bk,bk,bk,bl,bl,bl,bl,wh data bk,bl,re,re,re,bl,bl,bk ',bk,bl,bl,re,re,re,bl,bk data bk,bk,bk,bl,re,wh,bl,bk ',bk,bl,wh,re,bl,bk,bk,bk data bk,bk,bk,bl,re,wh,bl,bk ',bk,bl,wh,re,bl,bk,bk,bk data bk,bk,bk,bk,bl,wh,bl,bk ',bk,bl,wh,bl,bk,bk,bk,bk data bk,bk,bk,bk,bk,bl,bl,bk ',bk,bl,bl,bk,bk,bk,bk,bk data bk,bk,bk,bk,bk,bk,bk,bk ',bk,bk,bk,bk,bk,bk,bk,bk data bk,bk,bk,bk,ye,ye,ye,bk ',bk,ye,ye,ye,bk,bk,bk,bk data bk,bk,bk,ye,bk,bk,bk,bk ',bk,bk,bk,bk,ye,bk,bk,bk data bk,ye,ye,bk,bk,bk,bk,bk ',bk,bk,bk,bk,bk,ye,ye,bk data bk,ye,bk,bk,bk,bk,bk,bk ',bk,bk,bk,bk,bk,bk,ye,bk data ye,bk,bk,bk,bk,bk,bk,bk ',bk,bk,bk,bk,bk,bk,bl,ye data ye,bk,bk,bk,bk,bk,bk,bk ',bk,bk,bk,bk,bk,bk,bk,ye data ye,bk,bk,bk,bk,bk,bk,bk ',bk,bk,bk,bk,bk,bk,bk,ye data bk,ye,bk,bk,bk,bk,bk,bk ',bk,bk,bk,bk,bk,bk,ye,bk data bk,bk,ye,bk,bk,bk,bk,bk ',bk,bk,bk,bk,bk,ye,bk,bk