Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Trouble accessing class Variable

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1 Captacha   Members   

141
Like
0Likes
Like

Posted 08 January 2012 - 05:46 PM

I've been working on some 2D Movement in my games for the last few weeks and i'm using the SDL game libary for this game. I have a Player class with a SDL_Rect embedded in it for tracking x,y coordinates. The problem is that my Player will not move because my Input() method does not change the X Value. After doing some debugging, I figured out that my Input()method works and my Draw()method also works, but the Input()method does not change the values at all.

Input():

void Input(SDL_Rect Rect)
{
SDL_Event Event;
while(SDL_PollEvent(&Event))
{

  if(Event.type == SDL_KEYDOWN)
  {
   if(Key == SDLK_LEFT)
   {
	Rect.x--;
  
   }
  
   if(Key == SDLK_RIGHT)
   {
	Rect.x++;
   }
  }
  if(Event.type == SDL_QUIT)
  {
   Exit();
  }
}
}


#2 Wooh   Members   

1088
Like
0Likes
Like

Posted 08 January 2012 - 05:59 PM

You pass the SDL_Rect by value so the changes to Rect will not be visible from outside the function. Instead pass a reference or a pointer.
void Input(SDL_Rect& Rect)
{
	...


#3 Captacha   Members   

141
Like
0Likes
Like

Posted 08 January 2012 - 06:39 PM

Thanks so much for helping me with that. I'm still a begginner with pointers so please excuse the stupid mistake.




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.