gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > Some questions

#53573 - biubid_boy - Fri Sep 09, 2005 10:39 am

Ok. I have some questions I want to know.

1) Firstly, how would I do the coding equivalent to
Code:
 Press down, change sprite to LookDown.  Press left, change sprite to LookLeft, etc.


2) Can you make 'parent objects' (like from game maker) and if yes, how?

3) How do you make an animated sprite?

4) How would I make a timer to count for a random amount of time?

//EDIT: I'm using this code for my sprites except it's not working. I know it has something to do with attribute2 of my second object. Heres the code:

Code:
sprites[0].attribute0 = COLOR_256 | TALL | ypacman;
    sprites[0].attribute1 = SIZE_32 | xpacman;
    sprites[0].attribute2 = 512;

    sprites[1].attribute0 = COLOR_256 | TALL | yenemy;   
    sprites[1].attribute1 = SIZE_32 | xenemy;      
    sprites[1].attribute2 = 512 + 8;

#53590 - tepples - Fri Sep 09, 2005 4:43 pm

biubid_boy wrote:
Firstly, how would I do the coding equivalent to
Code:
 Press down, change sprite to LookDown.  Press left, change sprite to LookLeft, etc.

First define constants to represent the directions:
Code:
enum
{
  FACING_RIGHT, FACING_UP, FACING_LEFT, FACING_DOWN
};

In the struct that represents your player, have a variable 'theta'. Then use "How can I tell when a button is pressed?" in the FAQ to change theta, and use theta to choose which set of cels the sprite animation uses.

Quote:
3) How do you make an animated sprite?

There are two ways: either load multiple cels into sprite cel VRAM and change the sprite's attribute 2 to point to a different cel after every few frames, or repeatedly load cels into the same area of sprite cel VRAM and set attribute 2 to point to that area.

Quote:
4) How would I make a timer to count for a random amount of time?

First make a random number, then subtract 1 from that timer every vblank, and then perform an action when it reaches zero.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.