Re: A89: Pointers (too confusing)


[Prev][Next][Index][Thread]

Re: A89: Pointers (too confusing)




At 01:07 2001-01-17, you wrote:
>Hello,
>
>       I have recently started an RPG for the 89 written in C.  I am working
>on the movement engine now and am a little stuck!  I have two sprites for
>each direction when the arrows are pushed so as to give some what of an
>animation effect.  What I am looking for is how to make a pointer to the
>current sprite so I can XOR the sprite on the screen away before changing the
>coordinates and putting the new sprite down.    I have know idea how make a
>pointer to a sprite such as:
>
>static unsigned char tree_1[]=
>{0x00, 0x38, 0x44, 0x44, 0x38, 0x10, 0x10, 0x00};//taken directly
>from my //code, just an average tree, nothin too fancy
>
>and be able to change the sprite that the pointer points to.  Can someone
>help me please?
>
>CalenWakefield


declare a pointer like this:

unsigned char * spritepointer = 0;

and then you can give this the adress of your spritearray, simply like this:

spritepointer = tree_1;

then you can use "spritepointer" instead of "tree_1" in your sprite8()...

spritepointer can ofcourse then later be changed to point to some other 
sprite, with another
spritepointer = tree_23; or something.

the star means that it is a pointer to an unsigned char, instead of just an 
unsigned char.
a pointer is simply a variable that contains a value that should be 
interpreted as an adress in memory where another value is stored, instead 
of just any value..
and arrays is also pointers actually, but you are not allowed to change them.
that is why you can assign the array to the pointer just like that.
You can also write spritepointer[4] or something like that on any pointer, 
to in this case get element 4 of your tree-array. (the value 0x38)
(don't know if that made it much clearer though....)

///Olle





References: