0

Code runs perfectly when the initialization functions are called. I get the bricks, the ball and the paddle which moves with mouse. However, when program calls

move(ball, velocity, vertical);

where velocity = 2 and vertical = 4, the ball disappears from the window. I have tried the syntax in the documentation (i.e. gobject -> move(dx, dy)) but compiler didn't like that. GDB is no help either, tried running getX() to see where ball was, but there was no ball in context. I suppose I could write my own move function, but am wondering why this method makes my ball disappear.

2

If GDB isn't helping, maybe try using printf directly before and after the move statement, e.g.

printf("before: %.2f, %.2f\n", getX(ball), getY(ball)); 
move(ball, velocity, vertical);
printf("after: %.2f, %.2f\n", getX(ball), getY(ball)); 

If that is inside your main while loop you should see a continuous stream of output as the ball moves.

PS: The example syntax gobject->move(dx, dy) is for C++, which is why it doesn't work in a C program. The correct statement to use is move(object, dx, dy), where dx and dy are the values to move the object by (the difference from the current position to the new position). You can also use setLocation(object, x, y) to set the location of the object.

More documentation is available here and in the spec for pset4.

3
  • 1
    Thanks for the tip, it looks like ball is moving all over the place outside the window. Wonder why p get(x) didn't pick it up in GDB. Anyway, that's because I hadn't set borders for ball to bounce off of, which is supposed to be the next step in the pset but didn't get that far as the ball disappeared. – ronga Jul 17 '14 at 13:17
  • @ronga I'm sorry! How are you calling getX()? – Kareem Jul 17 '14 at 14:22
  • @Kareem I was calling getX(ball) directly within gdb (i.e. p getX(ball)), which wasn't working. I have since assigned int x=getX(ball) directly in the code, and called x through p x in gdb, which appears to be working as I'm now able to keep track of ball. – ronga Jul 19 '14 at 13:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .