The animated movie greatly expands on the kids’ book on which it’s based in a clever and engaging first half. But the second half leaves a foul aftertaste. Slapdash action scenes play against dreary warnings to fear wealth and beauty.

Flint Lockwood (Bill Hader) is a genial young genius whose inventions always go wrong. The latest is a machine that converts water to food. Although ridiculed by the townsfolk (Mr. T makes a funny contribution), he could save his decaying island home, whose only industry is sardines. Things go bonkers, and the gizmo winds up in the clouds, raining food on the delighted town. A foxy weather girl (Anna Faris) hurries to the scene: “My forecast: Sunny! Side up!”

Flint ignores the warnings of his humble dad (voice of James Caan, looks of G. Gordon Liddy). Dad is poor — he spends his days grinding sardines into chum at his bait shop. He’s also verbally inept, technologically illiterate and stuck in the past — and he’s the voice of reason. He’s the only one who sees the aporkalypse coming.

The island has an environmental problem (excess food goes to a dump that threatens to overflow) and people are getting obese. Dad wants Flint to save the day by shutting down his machine.

But that would plunge the island back into rusty destitution. The town problem isn’t complacency or greed — it’s just growth. When steaks the size of Priuses rain down, the father’s point is proved: The population is being buried by its own prosperity, and the solution is not to manage the resources but to cut them off.

Why not export the surplus and get rich? Because then there’d be no message about our collective guilt. It’s telling that the gadgets in the film are relics from the 1970s and ’80s (loved the use of the old Simon electronic party game). The movie is a high-tech celebration of Luddism, not because the filmmaking digerati are actually nostalgic for low tech themselves, but because they think it, like poverty and ugliness, suits the sweaty throngs out beyond the 310 area code who are messing up the planet.

The Faris character, a secret brainiac who is beautiful at the start, is aggressively unattractive in the second half because ugliness, we’re told, is more real. Now we’re knocking on the doors of the Puritans and the Taliban, with their warnings against prettiness.

Because no kid movie is complete without a global-warming message, the comedy turns into “The Day After Tomorrow” plus marinara sauce. The breakneck battle scenes, the repetitive slapstick (one guy slips into the body of a giant chicken, another into a giant olive) and the wordplay (“What if we’ve bitten off more than we can chew?”) don’t drown out the lecturing: “This mess we’re in is all our fault.”

Hang on — it’s morally wrong to try to produce an answer to the island’s poverty? The movie is as clueless as Marie Antoinette. The peasants are eating too much cake. Let them eat sardines!