English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. Blitz Basic

 
 
Thread Tools
Old 05 March 2020, 03:15   #1
jvdw007
Registered User
 
Join Date: Jun 2012
Location: London
Posts: 58
Question about 32 colour game

So, I'm very new to Blitzbasic 2. Not new to coding at all, but Blitz has some weirdness I'm still trying to wrap my head around.
For my first simple game attempt, I want to recreate a Python game I made before. It's based on this game. As can be seen I need to be able to draw a background interface and the bobs will be the individual face bits, 4 per face.

Now, in Aseprite, I've drawn the amiga graphics using 32 colours.
My ideal solution, would be to save out the image with everything on it as a "spritesheet" - some of you may recognise this term as a single image, where you can copy out shapes (in blitz terms) as individual bobs.
Now, since this game is a single playfield game and no scrolling or moving as such is required, I would just like to know if this is possible?
In XNView on the PC I converted the spritesheet into a 32 colour .iff file. Obviously since this is a single image with everything on it, all graphics use the same palette too.

From my limited blitz understanding, I assume I can load in this single image, including the palette and then create shapes from that, then release the bitmap as I then no longer need it?

I am using the copperlist/displayimage display method as used in the doublebuffer example in the blitzdemos folder and have managed to display a single image on there for testing purposes.

I will likely have more questions as I hopefully make progress in this endeavour
jvdw007 is offline  
Old 05 March 2020, 11:18   #2
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 4,507
Welcome to Blitz Yeah, that approach seems sound to me. You can create and load bitmaps as you need (Bitmap, LoadBitmap are the commands involved - a bitmap object needs to exist before you can load data into it), disposing of them afterwards to free up chip RAM. If all your shapes are regularly spaced out, a simple For...Next loop will let you cut them out - GetaShape is the command to look at here.

Though it's not object-orientated in the strictest sense, the Blitz object system does have some OO elements to it. For example, an object (be it a bitmap, sound, shape etc.) can be freed using Free <objectname>, <objectnumber>, and can be made current by Use <objectname>, <objectnumber>.

Don't forget to also load the required palette object (this is included in the LoadBitmap command via an optional extra parameter), as the palette needs to be applied separately to the display.
Daedalus is offline  
Old 06 March 2020, 15:34   #3
jvdw007
Registered User
 
Join Date: Jun 2012
Location: London
Posts: 58
Thanks for the confirmation, Daedalus. So far, I've now managed to load in the spritesheet, grab the first row of faces off it and display it.

Here's the code so far:

Code:
; New types for objects
DEFTYPE .w
NEWTYPE.img
x.w
y.w
End NEWTYPE

; Set logo
logo.img\x = 00
logo.img\y = 50

; Load the sprite sheet image
BitMap 0, 320, 480, 5
LoadBitMap 0, "data/spriteSheet.iff", 0
; Get the palette
LoadPalette 0, "data/spriteSheet.iff", 0

; Go into Blitz mode
BLITZ

; Then grab the shapes from it
pos = 0

For i = 0 To 4
	GetaShape i, pos, 0, 64, 64
	pos + 64
Next

; Then release the spritesheet
Free BitMap 0

; Init a Bitmap with 32 colours
BitMap 0, 320, 200, 5

; And another for DBing
BitMap 1, 320, 200, 5

; Init a queue for QBlit command
Queue 0, 50

; And one for the DB
Queue 1, 50

; Init a slice and colour palette
;			#id, start Y, height, type, sprites, colours, customs
InitCopList 0, 44, 200, 3, 8, 32, 0
DisplayPalette 0, 0
DisplayBitmap 0, 0
CreateDisplay 0

; Main loop
While Joyb(0) = 0
	VWait
	
	; Double buffer swap
	DisplayBitmap 0, db:db = 1 - db: Use BitMap db
	
	; Unqueue/clear shapes
	UnQueue db
	
	; Update
	
	
	; Draw
	pos = 0
	For i = 0 To 4
		QBlit db, i, logo\x + pos, logo\y
		pos + 64
	Next
Wend
I notice now the colours are wrong. I converted my Aseprite file to .png which by default is a 256 colour image. I then down converted it in XNview to 32 colours. I then loaded the .iff file into Grafx2 and can confirm the image is displaying correctly but the colour indexes are different to what they are in Aseprite. My mate spud said I might need to use something to change or convert the colour palette somewhere/somehow as that should help display the colours correctly in the game?

Any advice welcome, thanks.

Last edited by jvdw007; 06 March 2020 at 15:53.
jvdw007 is offline  
Old 07 March 2020, 07:28   #4
MickGyver
Registered User

MickGyver's Avatar
 
Join Date: Oct 2008
Location: Finland
Posts: 548
I think you need to add a "Use Palette 0" command.
MickGyver is offline  
Old 07 March 2020, 13:33   #5
Master484
Registered User
Master484's Avatar
 
Join Date: Nov 2015
Location: Vaasa, Finland
Posts: 424
From my own experiences with XnView, to get a specific palette color order, you have to do this before saving IFF images from it:

Put all your palette colors to the upper left corner of your spritesheet image, starting from color 0, then 1, 2, 3 and so on, until all 32 colors are in the order that you want your palette to be. So just have a row of small "color boxes" at the upper left corner, with transparent color 0 first, and then the other colors.

And now save the IFF, and it's color palette should have this same order. And if you have many spritesheets, then all of them need to have the same palette in the upper left corner.

---

I quess that the reason why it works this way, is that when you save an IFF image from XnView, it automatically generates a palette for that image. And it does this by going through the pixels, one by one, starting from the upper left corner of the image, moving right until that horizontal row has been processed, after which it starts processing the next row. And during this process, when it sees a new color, it adds that to the palette. And this goes on until the palette is "complete", so for example when all 16 or 32 colors have been found.

And then, when you load the image in Blitz (or in some paint program), you get that XnView generated color order.

This is why in all your images, you need to put your palette colors to the upper left corner, in the correct order.

In my own projects I use MS Paint to make the graphics, and then use XnView to convert them to IFF, and only by using this "palette on upper left corner" trick I can get the color order right.
Master484 is offline  
Old 08 March 2020, 15:43   #6
jvdw007
Registered User
 
Join Date: Jun 2012
Location: London
Posts: 58
Thanks, @MickGyver. Unfortunately, no matter where I put "Use Palette 0", all I got was "No currently used object" as an error. I looked at all the examples in the Blitz demos I could find and wasn't able to find any examples of it in use. Also the manual doesn't specify an example either.

@Master484 - thanks very much for that info, that's great to know! How large do you make the blocks? 1px by 1px or larger?

This is what it looks like in WinUAE: https://www.dropbox.com/s/ic0utuhh6o...creen.png?dl=0

And this is in Aseprite: https://www.dropbox.com/s/2kso895p80...creen.png?dl=0

Looks to me like the screen is 16 colours instead of 32, but I can't see why..

Last edited by jvdw007; 08 March 2020 at 15:52.
jvdw007 is offline  
Old 08 March 2020, 18:14   #7
Master484
Registered User
Master484's Avatar
 
Join Date: Nov 2015
Location: Vaasa, Finland
Posts: 424
Quote:
How large do you make the blocks? 1px by 1px or larger?
Usually something like 4px by 4px, so that they're easier to see. But I have tested that 1px by 1px will also work.

Quote:
no matter where I put "Use Palette 0", all I got was "No currently used object" as an error.
I think palettes have to be initialized before use.

Try putting "InitPalette ID, number of colors" to the beginning of your code.

Although I think "Use Palette" is used only with Slices, and with Displays the "DisplayPalette" command replaces it.

---

Also in your InitCopList, the "Type" parameter "3" looks strange:
InitCopList 0, 44, 200, 3, 8, 32, 0

Try setting it to $00005 to create a 32 color screen. Or if you're using AGA, then use $10005. The manual tells how to compose that value to make all kinds of screens, but last number is always the number of bitplanes, so 5 bitplanes are needed for a 32 color screen. If you put just "3" as the value, then I think it interpretes that as $00003, and gives you 3 bitplanes = only 8 colors.

Also about these lines:

DisplayPalette 0, 0
DisplayBitmap 0, 0
CreateDisplay 0

Try putting "CreateDisplay" first, and after that "DisplayPalette" and "DisplayBitmap". Right now I think the 2 display commands can fail, because the Display hasn't been created yet.

---

And also, when making the BLITZ command right after loading stuff, it's good to put a VWAIT 250 before the BLITZ happens. This causes a break of 5 seconds and gives the disk drive enough time to stop running. The BLITZ command shuts down the operating system, and if the disk drive is running when this happens, then it'll keep on spinning during your program even when no disk access is happening.

Although I don't think this is dangerous when you're just loading stuff. But when saving files, that is when bad things could possibly happen. In WINUAE you're probably safe, but I think on a real Amiga saving a file and then doing BLITZ immediately after without any waiting can possibly cause file corruption, or maybe even break the disk drive / Amiga hard drive, who knows.

The Blitz manual warns about this, and so does the Amiga hardware manual, and this is why I always put a 5 second wait before entering Blitz mode.
Master484 is offline  
Old 09 March 2020, 01:53   #8
jvdw007
Registered User
 
Join Date: Jun 2012
Location: London
Posts: 58
Thank you @Master484 - you were spot on. I actually created a separata 1px high iff just for the palette. The type in the InitCopList was indeed wrong and I'm happy you pointed that out to me as well as the order of the Display stuff. It is now all working.
What's frustrating is that I was following examples in the provided demos, which shows that they are also faulty.

I am glad to make better sense of this all now, so I can hopefully move onto working on the actual game now

PS, InitPalette wasn't needed since I already load the palette in.
PPS. You were also correct about putting the palette pixels at the top of the spritesheet too for the XNview conversion. When I removed it from the image, the palette was messed up again, despite me loading in the same colours in a separate .iff file.
I'll stick to using it like this going forward.

Last edited by jvdw007; 09 March 2020 at 02:08.
jvdw007 is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Xbox Game Pass Question jmmijo OT - Gaming 1 03 February 2020 00:14
Game storage question PussEKatt support.Amiga Forever 4 16 September 2019 19:27
Question for Toni: game specific IK+ hack possible? rsn8887 support.WinUAE 12 31 January 2019 11:58
Question over DID old game titles ? Celluloïd Nostalgia & memories 9 24 November 2005 09:23
Silly Question - My game starts and then... Sly support.WinUAE 3 12 June 2005 23:08

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 11:52.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Page generated in 0.06775 seconds with 14 queries