Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.


+2 votes

I don't understand how to check the dragon's location. Do I use a getCenter() then getX() or getY()?

asked in CSC201 Spring 2021 by (8 points)

2 Answers

+3 votes

we changed the if statements we already had for determining which way the dragon moves.
if pressedKey == "Left" and (condition for the dragon being too far left)

answered by (8 points)

That was it, thank you!

+3 votes

I used getAnchor on the dragon object to get its center point, and then getx and gety on that. Then, when I check for the keypress, I also used the x and y I found to see if the dragon is at the edge of the window, and keep the dragon from moving if its too close.

answered by (4.1k points)