Qbasicnews.com

Full Version: Great... now i'm asking how to make a Sprite Editor...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How would I make a sprite editor's interface work with an image set up like...

Image%(3000)

instead of

Image%(30,100)

Because the X,Y format is the type of image I'm used to, but if I want this to be correct, I'll have to use this format... can someone help please?
Code:
'For DIM Image%(1 TO 30, 1 TO 100):
Image%(x%, y%) = whatever%

'For DIM Image%(1 TO 3000):
Image%( (y%-1) * 30 + (x%-1) + 1 ) = whatever%
Just replace the number 30 with the width of the image.

Also, it makes things easier if you start off with 0 instead of 1:
Code:
'For DIM Image%(29, 99):
Image%(x%, y%) = whatever%

'For DIM Image%(2999):
Image%( y% * 30 + x% ) = whatever%

And then there's the fact that GET and PUT pack 2 pixels into one integer. The best way to do that is with POKE (in this example the top left is 0,0 not 1,1):
Code:
DEF SEG = Image%(0)
POKE y% * 30 + x%, whatever%

And now the final example. Here we account for the fact the GET and PUT store the image's width and height in the first 2 integers. Actually, the first integer is the width times 8, which never made any sense the me. The second integer is just the height. Anyway:
Code:
Image%(0) = 30 * 8  ' substitute 30 for image's width
Image%(1) = 100  ' substitute 100 for image's height

DEF SEG = VARSEG(Image%(0))
POKE 4 + y% * 30 + x%, whatever%

The "4 + " part in the POKE command skips over the first 2 integers, the width and height.
I think I see what you're saying. I'm sure your code is right, but just to make sure... how would I get that to work with different sizes of images. I'm pretty sure that by using that, it takes care of it, but just making sure. Thanks a lot though Sterling...
Sorry, I have a habit of posting before I'm really done. You responded while I was revising my post. Anyway, I think it answers your question now. For an image of a different size, just change 30 to the image's width, and 100 to the image's height (and 29 to the image's width minus one, etc...) in all the formulas.

The method denomstrated in the last example will result in a sprite that will work with PUT, but only in SCREEN 13 or DirectQB (and possiblly other libs). It's the same format GET uses.

Oh yeah, I forgot the tell you how to calculate sprite size. You need 2 integers for the width and height, plus one more for every 2 pixels. If the sprite has an odd number of pixels (like 7x7 = 49), you have to make sure to round up so that the last odd pixel has an integer to hold it.

Code:
DIM Image%(1 TO 2 + (height% * width% + 1) \ 2)
'or:
DIM Image%(1 + (height% * width% + 1) \ 2)
Alright! Thanks a lot Sterling... One more question, that last example, is that how I can plot a pixel in the array?
The last 2 lines do that! (in the last example of my first post) Just set x% and y% for the pixel you want to plot, with (0,0) as the top left.