Blog: Hello, World Freezes Over
Read The Docs: Carefully!
Read the Docs! Carefully. No, seriously.
This is a rehash of a post made last year, when I learned how important careful reading of the docs is to getting work done.
I was taking three CS courses at Northern Illinois University last spring (go Huskies!) and our first assignment for advanced Android was to create a simple pong style game, ostensibly to get us re-acquainted with Android Studio and Java since some of us, myself included, had been out of the Android game for a year or more.
The Problem
Simple enough for a first assignment, right? Just pong. It was essentially to make sure we understood basic Android design concepts like the MVC Design Pattern, how to handle events and gestures, and things like dynamically getting the height and width of the view... things of that nature. I mean it's Pong. Well worse, it was really Breakout with nothing to break (Cue Limp Bizkit lyrics)
Anyway I decided to use Rectangles (rects) for my paddle and ball (historically, we didn't have round balls in the early pong type games) and for simple collision detection, I'll use the intersect() method. And voila!
Kinda voila. Except every time the ball strikes the paddle, the paddle essentially disappears, at least until it moves again. What gives?
Fast Forward Two Hours
I quickly narrowed the problem down to the collision detection, but couldn't, for the life of me, figure out why this was happening. Eventually, I got there, and pulled up the docs for the intersect() method in Android. Turns out, intersect() fires when two rectangles intersect... and then modifies the calling rectangle to be the area of intersection of the two.
Oops. What I was looking for was the intersects() method, with that pesky trailing 's', which simply returns a boolean as to whether or not the two rectangles are intersecting. What I had done was:
- Read the first part of the docs for intersect()
- Thought "That oughtta do it!"
- Rolled with it
- Broke the game
The Lesson
Now, whether or not these two functions should both exist and share such astoundingly similar method names like this is up for debate (it's obviously an easy mistake to make) but this re-taught a very important lesson that I've learned many times before: when you're using a method, understand exactly what it's doing thoroughly before you utilize it.
Had I followed my own advice I would've either found the new method, or rewritten the logic to work with the old method, and saved myself a few hours and a headache. Just remember, read those docs. And carefully.
Share Your Feedback...
Website and all content ©2025 Jake Fitzenreider
Website powered by Oqtane