|
Post by johnno56 on Feb 1, 2020 21:12:25 GMT -6
n00b,
As promised... This is a modified prototype of a Sprite Editor I originally wrote using SDLBasic. It too had fill memory issues so I converted it to Naalaa. Funny thing is, Naalaa doesn't have a Flood or Paint command (only PolyF), so I had to think 'outside the box' - Man that was a headache and then some...
Instructions:
You cannot draw on the screen until you select a colour and "Pencil". Draw with the RMB and delete with the LMB.
LOAD works - coded for a fixed image at the moment... a little 'flakey'. Hold LMB a bit longer than a basic click... not sure why...
NEW works SAVE - not coded yet QUIT - Only option that worked 'out of the box' ...
Pencil works Line - not coded yet Grid Size - Coded but "32" used for testing.
Still a LOT of bugs. I'll worry about aesthetics once the program is working properly...
Any suggestions or constructive criticisms are always appreciated.
|
|
|
Post by n00b on Feb 2, 2020 15:18:05 GMT -6
Cool. I will check it out when I get home.
|
|
|
Post by tbird on Feb 2, 2020 20:04:21 GMT -6
I will also check this out, I am very intrigued!
|
|
|
Post by n00b on Feb 2, 2020 22:04:43 GMT -6
Hey Johnno, I tried it out. It was extremely buggy so I fixed some of your major bugs.
I just made changes to the DrawOnGrid() function. Try replacing the DrawOnGrid() function with this:
sub DrawOnGrid() ' DRAW CURRENT COLOUR TO MAIN GRID ' if mb = 1 and mx >0 and mx < 640 and my > 0 and my < 640 and getPixel(mx,my) <> gridcol then setColor(currentcol) RectFill( (Int(mx/gridsize) * gridsize ) + 1, (Int(my/gridsize) * gridsize ) + 1, gridsize-2, gridsize-2) end if end sub
I changed the FloodFill to RectFill and I removed the entire loop you had after. That loop didn't seem neccessary as far as I could tell. Let me know what you think.
|
|
|
Post by johnno56 on Feb 2, 2020 22:54:12 GMT -6
Ok. Changed function applied. After changing "col" to "colour" and "mb" to "mb0". The program ran. Not exactly the results I was hoping for but it ran none the less.
I'm not sure what you meant by, "I removed the entire loop you had after. That loop didn't seem neccessary"... The loop "after" the DrawOnGrid() is the erasefromgrid() or did my poor reading skills misunderstand you? My brain hurts...
|
|
|
Post by n00b on Feb 3, 2020 5:15:38 GMT -6
I made some more changes. I realize what that loop did now. I made it work the way you intended but I removed GetPixel(). That function is incredibly slow in RC. This should run a lot faster and won't crash. Attachments:spredit4.zip (228.7 KB)
|
|
|
Post by johnno56 on Feb 3, 2020 6:50:05 GMT -6
Thank you for the changes... Much better.
Many thanks for the assist...
Quick question Do you think that just 16 and 32 pixel sprites will be enough? Do you think a retro 8x8 size would be ok?
I would like to add a "Toolbox" but to be honest I'm not sure how to code much more than a "Pencil". An eraser can be as simple as RMB to set the currentcol to 0 (black). Maybe just a Pencil is all that is needed... lol
There are still some "Grid Size" coding that needs to be tidied up. Maybe I'll look at the 8x8 option. Perhaps a 'button for each grid size? I like buttons. Oh. Maybe a 'click'? (just one small step to background music? lol - kidding.)
|
|
|
Post by tbird on Feb 3, 2020 8:42:28 GMT -6
Pretty cool, the only issue I noticed is the mini image on the top right doesn't refresh when you start a new image. I wish I had more time to go through the source, I would like to help, but I will check in later and see what you have done.
Good work.
|
|
|
Post by n00b on Feb 3, 2020 9:50:57 GMT -6
Johnno, the sprite size would want to use is going to depend on your screen resolution and how big you want your sprite. I typically use larger sprite sizes of 32x32 or 64x64 but I use 640x480 for screen resolution most of the time. If you are going for more of a retro 8-bit approach then 8x8 or 16x16 would probably be a good size.
Also, I noticed your save button didn't work yet. I coded a function that will export your image to a BMP file. Here is a quick explanaiton of how it works:
*bmp_file - the bmp filename to save the image as *bmp_width - width of the sprite *bmp_height - height of the sprite *pdata - a 2 dimensional array that contains the image *array_width - the width of the 2d array
Example to save a 32 x 32 image:
Dim image[40, 40] 'Normally you would want to make this 32 x 32 as well but this is just an example
ExportBMP("mySprite.bmp", 32, 32, image, 40)
And here is the function:
Function ExportBMP(bmp_file$, bmp_width, bmp_height, byref pdata, array_width) 'BMP FILE FORMAT
'-----------------------------------BMP Header---------------------------------------------------------- Dim BM_Header[14]
BM_Header[0] = Asc("B") BM_Header[1] = Asc("M")
BM_Size = ((bmp_width * bmp_height) * 3) + 54 'Sprite_Width * Sprite_Height * Color_Depth + 54 (54 is size of BMP_Header + Info Header)
BM_Header[2] = AndBit( BM_Size, 255 ) BM_Header[3] = AndBit( BM_Size Shr 8, 255 ) BM_Header[4] = AndBit( BM_Size Shr 16, 255 ) BM_Header[5] = AndBit( BM_Size Shr 24, 255 )
'The next 4 bytes are not used for anything BM_Header[6] = 0 BM_Header[7] = 0 BM_Header[8] = 0 BM_Header[9] = 0
'Offset Where pixel data starts (Its always going to be 54 for this routine) BM_Header[10] = 54 BM_Header[11] = 0 BM_Header[12] = 0 BM_Header[13] = 0
'-----------------------------------End of BMP Header----------------------------------------------------------
'-----------------------------------DIB Header---------------------------------------------------------- Dim DIB_Header[40]
'Size of DIB Header (Its always going to be 40 bytes) DIB_Header[0] = 40 DIB_Header[1] = 0 DIB_Header[2] = 0 DIB_Header[3] = 0
'BMP width in Pixels DIB_Header[4] = AndBit( bmp_width, 255 ) DIB_Header[5] = 0'AndBit( bmp_width Shr 8, 255 ) DIB_Header[6] = 0'AndBit( bmp_width Shr 16, 255 ) DIB_Header[7] = 0'AndBit( bmp_width Shr 24, 255 )
'BMP height in Pixels DIB_Header[8] = AndBit( bmp_height, 255 ) DIB_Header[9] = 0'AndBit( bmp_height Shr 8, 255 ) DIB_Header[10] = 0'AndBit( bmp_height Shr 16, 255 ) DIB_Header[11] = 0'AndBit( bmp_height Shr 24, 255 )
'Number of Color Planes (always 1) DIB_Header[12] = 1 DIB_Header[13] = 0
'Color Depth (Bits per pixel) DIB_Header[14] = 24 DIB_Header[15] = 0
'Compression Method used (always 0 for this routine) DIB_Header[16] = 0 DIB_Header[17] = 0 DIB_Header[18] = 0 DIB_Header[19] = 0
'Image Size (Sprite_Width * Sprite_Height * Color_Depth_In_Bytes( it is 3 for 24-Bit ) ) Image_Size = bmp_width * bmp_height * 3
DIB_Header[20] = AndBit( Image_Size, 255 ) DIB_Header[21] = AndBit( Image_Size Shr 8, 255 ) DIB_Header[22] = AndBit( Image_Size Shr 16, 255 ) DIB_Header[23] = AndBit( Image_Size Shr 24, 255 )
'Pixels Per Meter - I am just setting it to 2834 DIB_PPM = 2834
'Horizontal Resolution (PPM) DIB_Header[24] = AndBit( DIB_PPM, 255 ) DIB_Header[25] = AndBit( DIB_PPM Shr 8, 255 ) DIB_Header[26] = AndBit( DIB_PPM Shr 16, 255 ) DIB_Header[27] = AndBit( DIB_PPM Shr 24, 255 )
'Vertical Resolution (PPM) DIB_Header[28] = AndBit( DIB_PPM, 255 ) DIB_Header[29] = AndBit( DIB_PPM Shr 8, 255 ) DIB_Header[30] = AndBit( DIB_PPM Shr 16, 255 ) DIB_Header[31] = AndBit( DIB_PPM Shr 24, 255 )
'Number of Colors in Color Palette - I am just setting this to default of 0 as well DIB_Header[32] = 0 DIB_Header[33] = 0 DIB_Header[34] = 0 DIB_Header[35] = 0
'Number of Important colors - 0 sets every color to important ( I actually have no idea what this does ) DIB_Header[36] = 0 DIB_Header[37] = 0 DIB_Header[38] = 0 DIB_Header[39] = 0 f = FreeFile FileOpen(f, bmp_file, BINARY_OUTPUT) For i = 0 to 13 WriteByte(f, BM_Header[i]) Next For i = 0 to 39 WriteByte(f, DIB_Header[i]) Next For x = bmp_width-1 to 0 step -1 For y = 0 to bmp_height-1 WriteByte(f, AndBit(pdata[y*array_width+x], 255) ) WriteByte(f, AndBit(pdata[y*array_width+x] Shr 8, 255) ) WriteByte(f, AndBit(pdata[y*array_width+x] Shr 16, 255) ) Next Next FileClose(f) End Function
|
|
|
Post by johnno56 on Feb 3, 2020 15:24:07 GMT -6
Holly cow! I didn't realize a BMP file would be SO complex... Never in a million years would I have tinkered all that together! I'm glad that one of us know what we are doing... lol Just added the SAVE routine. (I really have to add "messages" to these Menu buttons - no auditory or visual indication that the save actually completed...) The routine executed without error and produced a 32x32 BMP file but the image was black. At least the export function works per se... I will try to attach the current version as it is...
(program only - no change to assets)
ps: Working on a simple grid size changer...
|
|
|
Post by n00b on Feb 3, 2020 15:29:40 GMT -6
I will look at it and fix any issue with the save function. Other than that I am pretty impressed with your sprite editor. I am looking forward to seeing where this goes.
|
|
|
Post by johnno56 on Feb 3, 2020 15:40:57 GMT -6
Quick question.
I want to set the Grid Size to automatically adjust to the loaded image size. There is no example of how to use GetImageSize() in the manual. Would you be so kind as to provide an example? Much appreciated.
|
|
|
Post by n00b on Feb 3, 2020 15:59:09 GMT -6
I made some changes to your code and I implemented the save function. It works pretty well. I did notice after looking through the documentation on the BMP file format that the function I wrote will only save BMP files that have a resolution with a multiple of 4 (ie. 4x4, 8x8, 16x16, 24x24, 32x32, etc.). It wouldn't be too difficult to get it to work with any size but considering you were planning on using multiples of 4 anyway I just left it the way it is. Also, I removed the bgrid[] array. You were only using it for one part and it contains the same data as grid[] so I replaced it with grid[] that way you don't have to update 2 arrays whenever you load or draw on the image. Attachments:spredit5.zip (233.92 KB)
|
|
|
Post by n00b on Feb 3, 2020 16:03:15 GMT -6
Here is an example of how GetImageSize() works.
LoadImage(0, "image.png") w = 0 h = 0 GetImageSize(0, w, h)
Print "Image size is ";w;" x ";h
Also, you can resize an array with ReDim. Here is an example of that:
Dim x[4, 5]
ReDim x[10,10]
|
|
|
Post by johnno56 on Feb 3, 2020 17:13:26 GMT -6
Ok.
Since I last posted an update I have been making some minor changes (Grid Size Selection) and got it kind of working ok... You then posted your version 5... Not a problem. I modified my new version with your additions (bmploader. grid[] etc) and implemented the GetImageSize() to automatically adjust the main grid. (8, 16 and 32 at the moment - tested only with 32) I still need to do more work on the 'preview' images. The "actual' sized image needs to be configured to be a similar size to the 'preview'... Here is what I mean. "Load" the default image. Select a grid size other than the default 32. The main grid should clear. The two previews do not. But wait. There's more... Now select "New"... As I said... Needs more work.
But ultimately, your function and changes, now creates a 32x32 file...
Where will this go?
I just want a simple editor to create, load and save images without the learning curve of Photoshop, Gimp or even mspaint. Adding a "Toolbox" is above my pay grade... I may have to leave that to someone who knows how... lol
But, for now, I'm going to grab a coffee and either play a mindless game of Doom or watch a sci-fi flick.... It's just gone 10am, here in Melbourne, and logical thinking is now being placed on the back burner.... Many thanks for you assist so far and have a great day!
|
|