It doesn’t take a child psychologist to know that somewhere between potty training and adulthood is a phase in which anything poop-related is absolutely hilarious. It’s a stage of development parents often try to shorten, but Dav Pilkey turned it into a career when he published the first of his “Captain Underpants” books in 1997. Accompanied by simple drawings of robotic toilets, bionic boogers and other sub-Marvel creations, Pilkey’s gleefully lowbrow books have sold 80 million copies in 20 languages.

Pilkey’s plots are willfully nonsensical, but “Captain Underpants: The First Epic Movie” manages to stitch together some semblance of a story while maintaining the farcical spirit of the books. Pixar this ain’t, but “Captain Underpants” creates its own special brand of high-spirited mayhem and kid-caliber humor.

advertisement | advertise on newsday

Kevin Hart and Thomas Middleditch are well chosen as the voices of George Beard and Harold Hutchins, respectively, fourth-graders whose spare time is devoted to creating whimsical comic books. It’s their only source of joy after a day at Jerome Horwitz Elementary School, a place so dismal that students shove themselves into their own lockers. Its principal is Mr. Krupp, a vengeful disciplinarian, but one day George and Harold hypnotize him into becoming their most ludicrous creation, Captain Underpants (Ed Helms does both voices). The newly-minted superhero finds his nemesis in the mad scientist Professor Poopypants (Nick Kroll), who wants to rid the world of laughter.

The magic here lies in the screenplay by Nicholas Stoller (“Forgetting Sarah Marshall”), who does an excellent job of maintaining the book’s whoopee-cushion comedy while also throwing sophisticated asides to grown-ups. “You have no sense of humor,” the professor says of one pupil, “like a chair, or a supermodel.” Stoller also deepens the friendship between George and Harold, resulting in moments of something resembling poignancy. Meanwhile, director David Soren keeps up a breakneck pace that only occasionally tips over into the frenetic.

All told, “Captain Underpants” is a crackup, especially if you’re an 8-year-old — or if you can remember what made you laugh when you were one.