In general the publisher pays for development. For big games from known studios, you get a several million dollar advance that pays for development of the game. The game's royalties payback the advance and hopefully you earn something.
That is why EA owns so many game studios one big flop and suddenly you owe EA a couple of million.