z88dk forums

z80 Development Kit

You are not logged in.

#1 2020-06-01 18:57:51

jordi
Member
Registered: 2018-10-28
Posts: 51

creating masks for splib sprites

How masks should be stored?

I do have animated sprite as:
https://user-images.githubusercontent.com/447481/83438172-407d3b80-a441-11ea-8911-e082367d0450.png

and masks as
https://user-images.githubusercontent.com/447481/83438165-3e1ae180-a441-11ea-986d-336d5ee12253.png

so... how mask is represented in the sprite?
Something like this?  defb @MASK_8_bits, @SPRITE_8_bits

Code:

._sprite_protar1_f1

 defb @11111111, @11111001
 defb @11111101, @11111010

I've been trying without luck.

Offline

 

#2 2020-06-01 19:14:38

jordi
Member
Registered: 2018-10-28
Posts: 51

Re: creating masks for splib sprites

just an appointment: eyes should be white, but it's corrected that on my version.

Lot of thanks for the help.

Offline

 

#3 2020-06-02 00:44:28

jordi
Member
Registered: 2018-10-28
Posts: 51

Re: creating masks for splib sprites

Offline

 

#4 2020-06-02 08:57:21

derekfountain
Member
Registered: 2018-03-26
Posts: 33

Re: creating masks for splib sprites

Masked sprites are discussed in the second SP1 getting started article, here.

Offline

 

#5 2020-06-02 11:56:29

jordi
Member
Registered: 2018-10-28
Posts: 51

Re: creating masks for splib sprites

derekfountain wrote:

Masked sprites are discussed in the second SP1 getting started article, here.

Thankyou, but if I follow tutorial something weird happens:


1) I have drawn the tutorial 'circle' and compiled using my own code, and the result is here:
https://github.com/jsmolina/png2sp1spri … masked.asm
(as you see it is 1:1 tutorial binary data)

2) but used, in the good old misifu, it causes weird painting:
https://user-images.githubusercontent.com/447481/83512133-1030ae00-a4d0-11ea-82e7-dea5130cb152.png



sprites are:
https://github.com/jsmolina/speccy-misi … prites.png

while mask:
https://github.com/jsmolina/speccy-misi … s_mask.png

Offline

 

#6 2020-06-02 12:35:31

derekfountain
Member
Registered: 2018-03-26
Posts: 33

Re: creating masks for splib sprites

I don't know what you mean by "in the good old misifu".

I picked up your 'circle' code from your Github page and it works correctly. The sprite_sample.png and sprite_sample_mask.png are correctly converted by my local copy of the png2sp1sprite utility and the example works as expected.

Does your example work for you?

Offline

 

#7 2020-06-02 14:38:06

jordi
Member
Registered: 2018-10-28
Posts: 51

Re: creating masks for splib sprites

derekfountain wrote:

I don't know what you mean by "in the good old misifu".

I picked up your 'circle' code from your Github page and it works correctly. The sprite_sample.png and sprite_sample_mask.png are correctly converted by my local copy of the png2sp1sprite utility and the example works as expected.

Does your example work for you?

yep, the example worked perfectly.

Sorry, Misifu is a game that I did for ZXDev, that I'm improving graphics with a guy.

What I mean is that on
https://github.com/jsmolina/speccy-misifu/
repository I am trying to do the same as the example of the circle, so  cats mask is:

https://github.com/jsmolina/speccy-misi … s_mask.png

And cat sprites is:
https://github.com/jsmolina/speccy-misi … prites.png

But I got the weird result you saw before.

Offline

 

#8 2020-06-02 16:06:17

jordi
Member
Registered: 2018-10-28
Posts: 51

Re: creating masks for splib sprites

maybe the difference is how I create the sprite?

Code:

struct sp1_ss * add_sprite_protar1() {
  struct sp1_ss * sp;
   sp = sp1_CreateSpr(SP1_DRAW_MASK2LB, SP1_TYPE_2BYTE, 3, (int)sprite_protar1, 0);
  sp1_AddColSpr(sp, SP1_DRAW_MASK2,    SP1_TYPE_2BYTE, (int)sprite_protar2, 0);
  sp1_AddColSpr(sp, SP1_DRAW_MASK2,    SP1_TYPE_2BYTE, (int)sprite_protar3, 0);
  sp1_AddColSpr(sp, SP1_DRAW_MASK2,    SP1_TYPE_2BYTE, (int)sprite_protar4, 0);

  sp1_AddColSpr(sp, SP1_DRAW_MASK2RB,  SP1_TYPE_2BYTE, 0, 0);

  sp1_IterateSprChar(sp, initialiseColour);

  return sp;
}

Code:

static void initialiseColour(unsigned int count, struct sp1_cs *c)
{
  (void)count;    /* Suppress compiler warning about unused parameter */

  c->attr_mask = SP1_AMASK_INK;
  c->attr      = INK_BLACK;
}

Offline

 

#9 2020-06-02 17:00:15

jordi
Member
Registered: 2018-10-28
Posts: 51

Re: creating masks for splib sprites

might be related as the sprite is animated?? it's the only diffence with the circle

Offline

 

#10 2020-06-02 17:32:47

jordi
Member
Registered: 2018-10-28
Posts: 51

Re: creating masks for splib sprites

SOLVED!!!
It was related to frame param, I was sending wrong values.

Offline

 

#11 2020-06-02 17:49:27

jordi
Member
Registered: 2018-10-28
Posts: 51

Re: creating masks for splib sprites

Lot of thanks!

Offline

 

#12 2020-06-02 18:06:00

derekfountain
Member
Registered: 2018-03-26
Posts: 33

Re: creating masks for splib sprites

Heh, good timing, I was just about to start trying to work it out myself. Glad you solved it. smile

Offline

 

#13 2020-06-08 13:39:15

jordi
Member
Registered: 2018-10-28
Posts: 51

Re: creating masks for splib sprites

derekfountain wrote:

Heh, good timing, I was just about to start trying to work it out myself. Glad you solved it. smile

I lied finally, it is driving me crazy the param named 'void *frame' in  'sp1_MoveSprAbs'.

Specially, when sprite has MASK and ANIMATION at the same time.

Let's say I have my cat in this asm file:
https://github.com/jsmolina/speccy-misi … protar.asm

Original file is 216x24. So each frame has 24 pixels with both mask and pixel data, having some padding bytes before.

Which is the right value for each frame then? I am usually calculating, but then getting weird results.

Sprite is created this way

Code:

   sp = sp1_CreateSpr(SP1_DRAW_MASK2LB, SP1_TYPE_2BYTE, 4, (int)sprite_protar1, 1);
  sp1_AddColSpr(sp, SP1_DRAW_MASK2,    SP1_TYPE_2BYTE, (int)sprite_protar2, 0);
  sp1_AddColSpr(sp, SP1_DRAW_MASK2,    SP1_TYPE_2BYTE, (int)sprite_protar3, 0);

  sp1_AddColSpr(sp, SP1_DRAW_MASK2RB,  SP1_TYPE_2BYTE, 0, 0);

So third param is 4, that means 3 tiles + 1. I saw I always have to sum +1 on the heigh parameter of create.

Then drawing the cat with sp1_MoveSprAbs shoudl be frame == 0, then what is next? how I sum up?


Thanks, and sorry for disturbing.

Offline

 

#14 2020-06-08 14:58:55

jordi
Member
Registered: 2018-10-28
Posts: 51

Re: creating masks for splib sprites

And this is another example, that seems to work right for a 16x16 px sprite with mask and frames.

I use these frame values. I don't like because I usually do it "try and error". That means that probably I am doing it wrong.

Code:

#define AUX_PHONE 4
#define AUX_ZAP 52  // + 16x2 + 8x2
#define AUX_ARROWRIGHT 100
#define AUX_ARROWLEFT  148
#define AUX_BROOM 196
#define AUX_BROOM2 244

asm code will look like

Code:

SECTION rodata_user

; Original: 96, 16 (=12 x 2 chars)
; Blocks: 2
; mask, sprite
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000

PUBLIC _auxiliar1
._auxiliar1

._auxiliar1_f1
 defb @11111111, @00000000
 defb @11110000, @00000000
 defb @11000000, @00001111
 defb @10000000, @00111011
 defb @00000000, @01110100
 defb @00000000, @01110110
 defb @00000000, @00000111
 defb @11100000, @00001111
 defb @11100000, @00001100
 defb @11000000, @00011001
 defb @11000000, @00011010
 defb @11000000, @00011001
 defb @11000000, @00011100
 defb @11000000, @00011111
 defb @11100000, @00000000
 defb @11111111, @00000000

 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000

._auxiliar1_f2
 defb @11111111, @00000000
 defb @11111110, @00000000
 defb @11111100, @00000001
 defb @11101000, @00000011
 defb @11000000, @00010010
 defb @10000000, @00110100
 defb @00000000, @01110111
 defb @00000000, @11010100
 defb @00000000, @10010000
 defb @00000001, @00100100
 defb @10000001, @00101100
 defb @10000011, @00111000
 defb @10000111, @00110000
 defb @10001111, @00100000
 defb @10011111, @00000000
 defb @11111111, @00000000

 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000

._auxiliar1_f3
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11110111, @00000000
 defb @11100011, @00001000
 defb @11110001, @00000100
 defb @11111000, @00000010
 defb @11111100, @00000001
 defb @11111110, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000

 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000

._auxiliar1_f4
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111110, @00000000
 defb @11100100, @00000001
 defb @11100000, @00001010
 defb @11100001, @00001100
 defb @11100000, @00001110
 defb @11100000, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000

 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000

._auxiliar1_f5
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111110, @00000000
 defb @11111110, @00000000
 defb @11111000, @00000001
 defb @11110000, @00000111
 defb @11100000, @00001111
 defb @11100000, @00001111
 defb @11000000, @00011111
 defb @11000000, @00000110

 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000

._auxiliar1_f6
 defb @11111110, @00000000
 defb @11111110, @00000000
 defb @11111110, @00000000
 defb @11111110, @00000000
 defb @11111110, @00000000
 defb @11111110, @00000000
 defb @11111110, @00000000
 defb @11111110, @00000000
 defb @11111110, @00000000
 defb @11111110, @00000000
 defb @11111100, @00000001
 defb @11111100, @00000001
 defb @11111000, @00000011
 defb @11111000, @00000011
 defb @11111000, @00000011
 defb @11111000, @00000010

 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000

PUBLIC _auxiliar2
._auxiliar2

._auxiliar2_f1
 defb @11111111, @00000000
 defb @00001111, @00000000
 defb @00000011, @11110000
 defb @00000001, @11011100
 defb @00000000, @00101110
 defb @00000000, @01101110
 defb @00000000, @11100000
 defb @00000111, @11110000
 defb @00000111, @00110000
 defb @00000011, @01011000
 defb @00000011, @10011000
 defb @00000011, @01011000
 defb @00000011, @00111000
 defb @00000011, @11111000
 defb @00000111, @00000000
 defb @11111111, @00000000

 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000

._auxiliar2_f2
 defb @11111111, @00000000
 defb @01111111, @00000000
 defb @00100111, @10000000
 defb @00000011, @10011000
 defb @00000001, @11011100
 defb @00000000, @11010110
 defb @00000000, @11010010
 defb @00000000, @11010110
 defb @00000000, @01011100
 defb @00000000, @01010001
 defb @00000000, @00010011
 defb @11000000, @00000110
 defb @11100001, @00000000
 defb @11100011, @00001000
 defb @11100011, @00000000
 defb @11111111, @00000000

 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000

._auxiliar2_f3
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @01111111, @00000000
 defb @00100111, @10000000
 defb @00000111, @01010000
 defb @10000111, @00110000
 defb @00000111, @01110000
 defb @00000111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000

 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000

._auxiliar2_f4
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11101111, @00000000
 defb @11000111, @00010000
 defb @10001111, @00100000
 defb @00011111, @01000000
 defb @00111111, @10000000
 defb @01111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000

 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000

._auxiliar2_f5
 defb @11100111, @00000000
 defb @11100011, @00001000
 defb @11000011, @00011000
 defb @11000111, @00010000
 defb @10000111, @00110000
 defb @10001111, @00100000
 defb @00001111, @01100000
 defb @00011111, @01000000
 defb @00011111, @11000000
 defb @00111111, @10000000
 defb @00111111, @10000000
 defb @01111111, @00000000
 defb @00111111, @10000000
 defb @00111111, @10000000
 defb @00111111, @10000000
 defb @00111111, @10000000

 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000

._auxiliar2_f6
 defb @00111111, @10000000
 defb @00111111, @10000000
 defb @00111111, @10000000
 defb @00111111, @10000000
 defb @00111111, @10000000
 defb @00111111, @10000000
 defb @00111111, @10000000
 defb @00111111, @10000000
 defb @00111111, @10000000
 defb @00111111, @10000000
 defb @00111111, @10000000
 defb @00011111, @11000000
 defb @00001111, @11100000
 defb @00001111, @11100000
 defb @00000111, @11110000
 defb @00000111, @11000000

 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000

Offline

 

#15 2020-06-12 09:09:02

Timmy
Member
Registered: 2012-03-10
Posts: 125

Re: creating masks for splib sprites

Is there anything I can do to make this easier in the future?

To be honest I thought my sp1 example explained a lot already.

But maybe I need to make a tutorial for sp1 then? (Can't promise that it will be good, just that I can make one.)

Offline

 

#16 2020-06-12 19:18:28

fraespre
Member
Registered: 2019-08-19
Posts: 21

Re: creating masks for splib sprites

Timmy wrote:

Is there anything I can do to make this easier in the future?
To be honest I thought my sp1 example explained a lot already.
But maybe I need to make a tutorial for sp1 then? (Can't promise that it will be good, just that I can make one.)

Personally I think sp1 has some functionalities little or no documented.

For example:
- sp1_IterateUpdateArr
- Functions for displaying independent struct_sp1_cs not connected with any sprites (foregrounds)
  https://github.com/z88dk/z88dk/blob/mas … h/zx/sp1.h

I would appreciate some simple example to demonstrate these features. And avoid guessing what the assembly code does :-D

Thanks in advanced

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson