Librería SpritePack

Todo sobre la creación, diseño y programación de nuevo software para
nuestro Spectrum

Moderador: Sir Cilve Sinclair

Responder
Avatar de Usuario
nicalejo
rst 0
Mensajes: 33
Registrado: Vie May 14, 2010 12:52 pm
Ubicación: Valencia

Librería SpritePack

Mensaje por nicalejo » Mar Ene 13, 2015 11:38 am

Hola, he estado trasteando con la la librería spritepack y no consigo saber como extraer la coordenada x e y actual de un sprite a nivel de pixel.

La estruttura struct sp_SS tiene los campo row y col pero a nivel de caracter y si quiero hacer colisiones finas a nivel de pixel no hay manera.

¿Alguien sabe cómo? ¿Algún ejemplo?

Gracias

Alcoholics Anonymous
rst 0
Mensajes: 21
Registrado: Lun Feb 04, 2008 6:16 am

Re: Librería SpritePack

Mensaje por Alcoholics Anonymous » Vie Ene 16, 2015 5:12 pm

Hello,

(english below in case of bad translation)

Spritepack funciona de la misma manera que sp1. Es sp1's "struct sp1_ss" estructura que será similar a spritepack's:

Código: Seleccionar todo

struct sp1_ss {                       // "sprite structs" - 20 bytes - Every sprite is described by one of these

   uint8_t              row;            // +0  current y tile-coordinate
   uint8_t              col;            // +1  current x tile-coordinate
   uint8_t              width;          // +2  width of sprite in tiles
   uint8_t              height;         // +3  height of sprite in tiles

   uint8_t              vrot;           // +4  bit 7 = 1 for 2-byte graphical definition else 1-byte, bits 2:0 = current vertical rotation (0..7)
   uint8_t              hrot;           // +5  current horizontal rotation (0..7)

   uint8_t             *frame;          // +6  current sprite frame address added to graphic pointers

   uint8_t              res0;           // +8  "LD A,n" opcode
   uint8_t              e_hrot;         // +9  effective horizontal rotation = MSB of rotation table to use
   uint8_t              res1;           // +10 "LD BC,nn" opcode
   uint16_t               e_offset;       // +11 effective offset to add to graphic pointers, equals result of vertical rotation + frame addr
   uint8_t              res2;           // +13 "EX DE,HL" opcode
   uint8_t              res3;           // +14 "JP (HL)" opcode

   struct sp1_cs     *first;          // +15 BIG ENDIAN ; first struct sp1_cs of this sprite

   uint8_t              xthresh;        // +17 hrot must be at least this number of pixels for last column of sprite to be drawn (1 default)
   uint8_t              ythresh;        // +18 vrot must be at least this number of pixels for last row of sprite to be drawn (1 default)
   uint8_t              nactive;        // +19 number of struct sp1_cs cells on display (written by sp1_MoveSpr*)

};
La coordenada de la esquina superior izquierda del sprite en píxeles es:

x_pixel_coord = col*8 + (hrot & 0x07)
y_pixel_coord = row*8 + (vrot & 0x07)

La anchura y la altura de la imagen en píxeles es algo que depende de la propia imagen.

La detección de colisiones se puede hacer mediante la creación de una estructura de rectángulo, escribir esas x y coordenadas Y en él (la anchura y la altura del rectángulo podría ser constantes que dependen de la imagen) y luego las pruebas para las colisiones entre rectángulos.

Alguien en WOS resucitado un viejo código colisión pixel para sp1 que también trabajará con spritepack. Si desea verlo, puedo mirar para arriba y copiar aquí.


=====


Spritepack works the same way as sp1. This is sp1's "struct sp1_ss" structure that will be similar to spritepack's:

Código: Seleccionar todo

struct sp1_ss {                       // "sprite structs" - 20 bytes - Every sprite is described by one of these
...
};

The coordinate of the top left corner of the sprite in pixels is:

x_pixel_coord = col*8 + (hrot & 0x07)
y_pixel_coord = row*8 + (vrot & 0x07)

The width and height of the image in pixels is something that depends on the image itself.


Collision detection can be done by creating a rectangle structure, writing those x and y coords into it (the width and height of the rectangle might be constants depending on the image) and then testing for collisions between rectangles.

Someone at WOS resurrected some old pixel collision code for sp1 that will also work with spritepack. If you'd like to see it, I can look it up and copy it here.

Avatar de Usuario
nicalejo
rst 0
Mensajes: 33
Registrado: Vie May 14, 2010 12:52 pm
Ubicación: Valencia

Re: Librería SpritePack

Mensaje por nicalejo » Sab Ene 17, 2015 10:13 am

Infinitas gracias

Responder

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 13 invitados