Dynamic pointers in C

Started by
11 comments, last by pauljg 22 years, 2 months ago
Ok. I see. I think. I don''t understand "it can handle 100, with values for x,y" - 100 what? coordinates, like
struct sprite {    int x[100];    int y[100];}; 


or 100 sprites? (eg. sprite array[100]; )

Either way, I would isolate the iterator from the rotate and draw functions. I would write those to work for any sprite and use a completely different function to locate a particular sprite to be passed to rotate and draw.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Advertisement
why not get createSprite to return a ''handle'' to the caller then use that in subsequent calls. In your case the handle would either be an int into the array - or what I did with an Ogl texture manager which was to pass a pointer to the data structure back (if you''re using a linked list). ie your calling code would be something like this
  int hBall;hBall = createSprite("ball.bmp");/* and then elsewhere in the code */rotateSprite(hBall, 25);    // why the hell rotate the actual sprite anywaydrawSprite(hBall, 5, 5);  


btw. I personally feel that you shouldn''t have a routine to rotate the actual sprite, but rather you should have a routine that can draw the sprite at an angle. eg:
  drawSpriteRotated(hBall, 5, 5, 25);   // draw the ball at xy = (5,5) and at angle 25 deg.  

Hope this helps somehow
I can see where your coming from, and I like it !.

But..

It''s having to use the

''int hball; ''

at the start. Ideally I''d like the user to be able to use any label they want, perhaps having a dynamic INT in the create process. But it seems C wont let me.

As for the combined rotate instruction.., hmm.. I had to think long & hard about it, but having separate commands means you would''nt have to keep calling it with a rotation value. It would hold a perminent varaible reference.

This topic is closed to new replies.

Advertisement