This is how they defeated Ansem in Ryan's Quest.
They are in Canterlot High
Ryan: Is this... my school?
They went to the Secret Place.
Ansem: This world has been connected.
The school disappeared
Crash: What was that?
Ansem: Tied to the darkness... Soon to be completely eclipsed.
The houses vanishes into thin air
Ansem: There is so very much to learn.
The sky froths, turns a dark violet color
Ansem: You understand so little.
The Town starts to rumble and quake
Ansem: A meaningless effort. One who knows nothing can understand nothing
Canterlot High has been rip apart and they saw Cody and they know Ansem still possessed in Cody's Body
Ansem: Take a look at this tiny place. To the heart-seeking freedom, this high school is a prison. Surrounded by cars. And so this techno-organic brother of Sari sought out to escape from his prison. He sought a way to cross into other worlds, and he open his heart and spark to darkness.
Then turn into himself as Ansem
Ansem: Don't bother, techno-organic. Your voice can no longer reach him where he is. His heart belongs again to darkness. All worlds begin in darkness, and also ends. The heart is no different. Darkness sprouts within it. It grows, consumes it. Such is it's nature. In the end, every heart returns to the darkness whence it came.
They back away from him
Ansem: You see, Darkness is the heart's true essence.
Ryan: Stop lying! The heart maybe weak. But it may give in sometimes. The thing is that I learned from someone, that deep down, there is a light that will NEVER go out.
Ansem: You have come this far and you still understand nothing. Every light must fade, every heart return to Darkness!
A Heartless guardian appears behind him
Evil Ryan: This guy's a Heartless!? [to Ryan] This doesn't make any sense.
Ryan: I know. Let's fight this fella!
Ryan: He's getting away!