Gameboy Development Forum

Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)

You are not logged in.

Ads

#1 2015-09-30 15:03:30

Combou
New member
Registered: 2015-09-30
Posts: 4

Graphics/Tile Functions

Hey!
I am Combou and i am new in this forum.I was searching for a way to create and move sprites, so i found that: http://gbdk.sourceforge.net/doc/html/c0504.html
There is some useful commands there, but i don't know how to use them.I was wondering if someone could help me.
I already know how to create a background and move it.If you don't know, i can try to help you smile

I will make a txt tutorial if I find out how to do it.

Sorry for bad english, i am from Brazil hmm
Thanks! smile

Offline

 

#2 2015-09-30 17:41:40

l0k1
Member
Registered: 2014-10-23
Posts: 44

Re: Graphics/Tile Functions

Your looking for move_sprite() and scroll_sprite().

move_sprite(number_of_sprite_to_move, new_x_coordinate, new_y_coordinate) - This will move the specified sprite to (X,Y) on the screen (i.e. an absolute move).

scroll_sprite(number_of_sprite_to_move, move_on_x_axis_this_much, move_on_y_axis_this_much) - This will move the sprite based on it's current location (i.e. a relative move).

Offline

 

#3 2015-10-01 07:57:13

Combou
New member
Registered: 2015-09-30
Posts: 4

Re: Graphics/Tile Functions

Cool!
But you know how to declare a sprite? Like using: set_sprite_tile()

Thanks!

Offline

 

#4 2015-10-01 12:35:34

Xephyr
Member
From: France
Registered: 2015-02-26
Posts: 59

Re: Graphics/Tile Functions

First, load your sprite datas like you would do for tiles data :
    set_sprite_data(UBYTE first_tile, UBYTE number_of_tiles, unsigned char *data);

Then, you have to choose if you want 8*8 or 8*16 sprites. You can do so with :
    SPRITES_8x8 or SPRITES_8x16

And after that, set your sprites from previously loaded datas :
    set_sprite_tile(UBYTE sprite_number, UBYTE tile_number);

Offline

 

#5 2015-10-01 19:40:18

Combou
New member
Registered: 2015-09-30
Posts: 4

Re: Graphics/Tile Functions

#include <gb/gb.h>
#include <stdio.h>
#include <rand.h>

unsigned char bgtiles1[] =
{
  0x00,0xFF,0x20,0xFF,0x42,0xFF,0x04,0xFF,
  0x00,0xFF,0x28,0xFF,0x40,0xFF,0x00,0xFF,
  0x00,0xFF,0x7E,0xFF,0x7E,0xFF,0x5A,0xDB,
  0x7E,0xFF,0x7E,0xFF,0x7E,0xFF,0x3C,0xFF,
  0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  0x7E,0xFF,0x66,0xFF,0x66,0xFF,0x66,0xFF,
  0x66,0xFF,0x66,0xFF,0x66,0xFF,0x66,0xFF
};

unsigned char playertiles1[] =
{
  0x00,0xFF,0x7E,0xFF,0x7E,0xFF,0x5A,0xDB,
  0x7E,0xFF,0x7E,0xFF,0x7E,0xFF,0x3C,0xFF
};

unsigned char bgmap1[] =
{
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
  0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
  0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
  0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
  0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x03,
  0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x03,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
  0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
  0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
  0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
  0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x03,
  0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x03,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
  0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
  0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
  0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
  0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x03,
  0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x03,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};

int main(){
    set_bkg_data(0, 4, bgtiles1);
    set_bkg_tiles(0, 0, 20, 18, bgmap1);
    move_bkg(0, 0);

    set_sprite_data(1, 1, bgtiles1);
    SPRITES_8x8;
    set_sprite_tile(1, 1);
   
    move_sprite(1, 10, 12);
   
    SHOW_BKG;
    DISPLAY_ON;

    return 0;
}

The sprite is not appearing...What did I miss?

Offline

 

#6 2015-10-02 01:24:31

Xephyr
Member
From: France
Registered: 2015-02-26
Posts: 59

Re: Graphics/Tile Functions

I forgot to mention that you need to use SHOW_SPRITES as for the background and the window x)

Offline

 

#7 2015-10-02 07:47:52

Combou
New member
Registered: 2015-09-30
Posts: 4

Re: Graphics/Tile Functions

Thanks.
So i have to use set_win_data() and stuff like that?

Offline

 

#8 2015-10-02 17:11:24

Xephyr
Member
From: France
Registered: 2015-02-26
Posts: 59

Re: Graphics/Tile Functions

If you don't want to display the window, there's no need to use it.

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson