Wax (Jay Chou) has a crush on Starling (Hsin Ai Lee) in “The Rooftop,” in which Chou directs, scripts, scores and stars. (Well Go USA Entertainment)

Taiwanese heartthrob Jay Chou hasn’t had great luck with movies. The songwriter-turned-singer-turned-actor appeared in “The Curse of the Golden Flower,” one of Chinese director Zhang Yimou’s clunkier epics, and played Kato in Seth Rogen’s disastrous stoner update of “The Green Hornet.”

But Chou hasn’t given up. “The Rooftop,” a candy-colored musical, is his second try at directing, and he also scripts, scores and stars. The result is two-thirds delightful, although the final act flops.

Chou plays Wax, a young tough with a heart of gold and an oiled ’do that suggests “West Side Story” or at least “Grease.” If Wax is living in the 1950s, most of the other characters sport a different retro look: His three inseparable pals include a self-styled hippie with a Hendrix-style Afro.

The four guys live with a dozen or so others in simple but charming shanties atop a row of buildings. Almost anything will spark them to sing and dance to music that ranges from Sino pop to Hawaiian to heavy metal. The opening number, featuring veteran Hong Kong character actor Eric Tsang as a purveyor of sexual vitality potions, is techno-rap. Chou wrote most of the material but also reveals his taste by prominently featuring Bread’s 1971 wimp-rock hit, “If.”

The community has one honorary resident: Starling (Hsin Ai Lee), a starlet whose pretty face graces the billboard that towers over the Rooftop. Wax has a crush on her, which could become real-life romance after he rushes to protect her from attackers on the street. The assault turns out to be a movie scene, and Wax ruins the take. But his mistake gets him a job as a stuntman and the chance to spend time with Starling.

Getting Wax into the movie biz allows Chou to cut between the artificial neighborhood of the Rooftop — mostly shot on sets that don’t pretend to be anything else — and the simulated universe of cinema. The director hops between the dream worlds with amusingly disorienting segues and playfully self-conscious tricks.

The other plot involves corruption at the local housing authority, whose rent collections are made by thugs. Wax’s buddy Tempura (Alan Ko) gets involved in the racket, and eventually Starling is imperiled by the mob’s principal sociopath. This prompts a surprisingly violent showdown that’s irreconcilable with the movie’s earlier tone — and not very interesting, either.

Before it veers off course, “The Rooftop” is lively, funny and colorful. The visuals are excellent, with art direction by Yoshihito Akatsuka (“Kill Bill”) and cinematography by the great Mark Lee Ping Bin (“In the Mood for Love”). Too bad Chou decided to shoehorn the gangster genre into a movie that would have worked just fine as a mere comedy-romance-fantasy musical.

Jenkins is a freelance writer.★★½­

Unrated. At AMC Hoffman Center 22. Contains violence, occasional profanity and comic nudity. In Mandarin and English with subtitles. 121 minutes.