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.

Graphics > Probably an easy Sprite question

#66515 - Issac - Wed Jan 11, 2006 3:12 pm

Hello all, I have been searching, and looking through some tutorials, But i can't seem to figure out how to use my sprites.
I have:
a 16x16 player sprite. (with black as transparent)
a 16x16 "get-this-item" sprite (black as transparent)
a 8x8 bullet sprite (black transparency)
a 32x32 enemy sprite (black transparency here too)

Now, How do i insert em all into my game?

I have set's of .H, pallette.o and data.o for each sprite...

for example.. all those "0x000000032" things (just don't know what to call them) where in the memory should they be placed and such things...

hmm, running out of time now, but i hope you get what I need help with..

pretty noobish eh? =)

thanks in (gameboy) advance hehehe...
_________________
yeah, well, maybe... or? anyways.... eh... what was i talking about??

#66523 - keldon - Wed Jan 11, 2006 3:44 pm

Check out the Tonc tutorials for how to use sprites in software
http://user.chem.tue.nl/jakvijn/tonc/toc.htm

#66761 - Issac - Fri Jan 13, 2006 9:59 am

Issac wrote:
Hello all, I have been searching, and looking through some tutorials, But i can't seem to figure out how to use my sprites.


i've been looking through that... but i can't seem to figure out the things i want to know through these things....

can someone give a bit more precise eplanation... i must be dumb...
_________________
yeah, well, maybe... or? anyways.... eh... what was i talking about??

#66810 - poslundc - Fri Jan 13, 2006 6:02 pm

Issac wrote:
Issac wrote:
Hello all, I have been searching, and looking through some tutorials, But i can't seem to figure out how to use my sprites.


i've been looking through that... but i can't seem to figure out the things i want to know through these things....


Try doing all of the code examples instead of merely looking through them, and changing parts of them so you understand how they work better. Eventually you should be able to get one of the sprite demos working, and then see if you can figure out how to swap in one of your own sprites. Try making more than a superficial effort.

Dan.

#66863 - Issac - Fri Jan 13, 2006 11:08 pm

well, im sorry..
My english isn't the best, i must say, but i've been looking, reading, trying to understand... but i can't... and what i don't even understand are all the tables and stuff... i think it is kinda advanced written...

I do know some other stuff, so im not completely stupid.. but now i've been struggling with sprites for a month... without ANY progression.. so i'd like some explaining on certain basic things...

I mean... i have my small sprites... and on the tonc things there are.. sprites divided into maps and stuff... it gets all confusing...

what would be best, is some kickstart of my brain.. by telling me some very basic stuff so i atleast understand what all the things are in cearns tutorial...

(and please, no comments like: "if you don't understand, quit doing this")
_________________
yeah, well, maybe... or? anyways.... eh... what was i talking about??

#66864 - keldon - Fri Jan 13, 2006 11:19 pm

Hmmm. I would suggest doing the following:

(a) get some code that loads a single 8x8 tile into sprite memory using any method
(b) get this one sprite to display
(c) get some code that loads a 16x8 (or any other size) sprite into memory in either 1D or 2D mode
(d) get this one sprite to display

In fact you can just take the tonc sprite example and learn from there. First you must make sure that you have the correct sprite data loaded. Next you use the correct attributes. Use the TONC defines for setting the object attributes for now.

#66866 - poslundc - Fri Jan 13, 2006 11:37 pm

Issac wrote:
(and please, no comments like: "if you don't understand, quit doing this")


Quit doing what? You haven't done anything yet.

Try running the code in the tutorial. Then try changing it. Let us know where you run into specific problems and we'll help as best we can.

Just saying "I don't get it" doesn't help us explain things to you. Things are already explained in the tutorial. What would you have us say that hasn't already been said there?

Dan.

#66870 - Issac - Sat Jan 14, 2006 12:21 am

I meant quit trying to code for the gba... and yes i HAVE done something...

i've already made a pong clone...

and.. on this one.. i've made the basic stuff, and backgrounds..

the pong clone had normal graphic / bitmapped things as players.... and not sprites.. and i want to use sprites for this game...

but okay... i will try the tonc guide for the fiftyelfth time.. :P
_________________
yeah, well, maybe... or? anyways.... eh... what was i talking about??

#66881 - pure_ev1l - Sat Jan 14, 2006 2:19 am

*sigh* - experts can be mean sometimes, but you have to see it from there point of view, same questions again and again.
_________________
-Rory

"Planning makes for a boring life, but a good game"

#66884 - gauauu - Sat Jan 14, 2006 2:46 am

Quote:
and what i don't even understand are all the tables and stuff.


I'll go out on a limb and try to help, even though like everyone else, I'm not sure where you're having problems.

Those tables of sprite attributes work like this. Each sprite has a few bytes of data that control what is displayed to the screen. You set certain bits in these bytes to get different effects.

So, for example, if you want to change a sprite's shape, you look in the tables and see which bits control the shape....bits E-F of attribute 0. So you write to those bits to set the sprite to the shape you want. (you'll HAVE to have an understanding of bitwise operators to be able to do this....if code like:
Code:
sprite->attribute1 &= ~(0x03 << 14);

makes no sense to you, first go find a tutorial about bit operators such).

Another thing that might be causing you grief is how much of the tutorials refer to actual memory locations. The tutorials are always saying things like
Quote:
This starts at address 0700:0000h and is 1024 bytes long
.

Unlike most windows/pc programming, on GBA, you'll be writing directly to specific memory locations A LOT. How do you write to specific memory? The easiest way is to get yourself a basic gba.h that defines a lot of these memory locations, possibly like:
Code:
u32* OAMmem        =(u32*)0x7000000;

Then you can write to the memory directly as easy as:
Code:
*OAMmem = yourdata;

or using array indexing:
Code:
OAMmem[index] = value;


Anyway, if tonc is making no sense to you, maybe you'll need to back up and get a better grasp of how these types of memory/bitwise/pointer operations work.

Or maybe I'm totally going the wrong direction, and there's something else that's losing you?

#66987 - Cearn - Sat Jan 14, 2006 10:14 pm

Before we gon into explanations of how GBA sprites work, it might be better to get an idea of how well you understand what's going on first.
  1. Do you understand the basic principles of memory and how you can use it in programming? The use of different data-types (char, short, int)? Arrays and pointers? Hexidecimal numbers? You must have used it to make the pong thing, but do you actually understand what you're doing, rather than copying what everybody else does?
  2. Do you understand that the values in memory can have a different interpretation. For example, I hope you know that VRAM starts at address 0x0600:0000. So what happens if I put 0x001F (red in 16bit BGR format) in the first halfword of VRAM? If you answered that it'd plot a red pixel on the screen, you are wrong! This will only be true for modes 3 and 5, but not for the others. VRAM is not a simple representation of the screen. The way its contents are used depends on the video mode, and a few other things.
  3. Do you know how memory is used for a bitmap? It is a not a bunch of colored pixels, but a bunch of bytes with values, interpreted by a program in a certain way so that it looks like a bunch of colored pixels to us humans. Can you see the distinction?
  4. Do you understand how the IO registers work? The stuff starting at 0x0400:0000 I mean. Do you understand that bits can acts as switches (in fact, they are switches), and that setting or clearing a single one or a group of them can be used to establish different effects (like setting the video mode)?
  5. What do you think sprites are? What does it mean when someone mentions the word 'sprite' to you? If your answer is something like "a smaller bitmap on screen", that is the wrong way of looking at them for a programmer. A sprite actually encompasses a number of things, the bitmap is only the visual representation. For the GBA, what makes up a sprite are its attributes: position, size, shape, flip/rotation flags, order and what not. These are kept in OAM (Object Attribute Memory, 0x0700:0000). The stuff that goes into object VRAM (0x0601:0000) has almost nothing to do with what an object actually is, it is only a depository for what a sprite can use for its graphical representation.

Issac wrote:
for example.. all those "0x000000032" things (just don't know what to call them) where in the memory should they be placed and such things...

"Data" perhaps. We can't tell you where to put all the "0x000000032" things, if we don't know which things you are referring to. If it's the graphics data you mean, you put that in object VRAM in this case.

Issac wrote:
...what i don't even understand are all the tables and stuff...
Which tables? these things, for the attributes? There's nothing really to understand about them, they just indicate which bits control which effects, exactly like what all the IO registers do.

Issac wrote:
and on the tonc things there are.. sprites divided into maps and stuff... it gets all confusing...

Maps? Not sure what you're referring to here. I do compare them to tilemaps because in a lot of ways they are very similar, but I can't recall actually saying they are divided into maps.

poslundc wrote:
Try running the code in the tutorial. Then try changing it. Let us know where you run into specific problems and we'll help as best we can.
This is good advice. At what point do you start to get lost?

#69717 - Issac - Wed Feb 01, 2006 2:48 pm

Hey, Long time no writing for me...
Thanks Cearn, that helped.
and Thanks gauauu.

this made some more sense...

And i've probably been in a "bad understanding"-period...

ive inserted a sprite, but it wont show up... ive been looking a lot..... and will look a bit more.. but if I fail, is it okay to mail my source or something?

to you cearn? or someone else?

well well.. im in a hurry right now.. so i got to go...

thanks, and sorry for being "stupid" :p
_________________
yeah, well, maybe... or? anyways.... eh... what was i talking about??