I have a basic understanding of history, but I often think about this question. What made Constantine move the capital from Rome to Byzantium, instead of staying and protecting it from the encroaching Barbarians? I understand Byzantium would make a better capital, but that wouldn’t exactly be ideal to move the capital when the other one is in danger, and risking the western part of your empire to fall into enemy hands?
This isn't really accurate.
Firstly Rome was already of diminished political importance by this time. Back at the end of the Crisis of the Third Century Diocletian effectively began to shift political importance away from Rome already. Firstly because as the Principate shifted into the Dominate much of that political importance that remained for the senate that was meeting in Rome diminished. Secondly the seat of the Imperial government was no longer there. When Diocletian created the Tetrarchy, dividing the empire to be administered by four emperors so that an emperor could be dealing with more than one problem at once with the junior emperors in particular being able to spend plenty of time in the field. At this point Rome was already being abandoned as an impractical seat of for the imperial throne.
Diocletian himself chose to make himself the senior emperor (Augustus) of the east with a seat in the city of Nicomedia in modern Turkey. The Augustus of the west, Maximian, ruled not from Rome but from Mediolanum, modern Milian. Rome was too far from the border to be practical, moving to northern italy allowed the emperors to get news faster and more easily respond to problems along the frontier.
Now to skip over the details civil wars that occurred after Diocletian retired all you basically have to know is the Constantine came out on top in the west then conquered the east of the empire and became sole emperor.
Then then effectively moved the two primary capitals of the empire not from rome but from Milan and Nicomeda. Secondly this really wasn't an act of running away in the middle of being invaded by a barbarian horde. Alaric's sack of Rome was eighty years after Constantinople was founded, the second that marked the end of the western roman empire 125, both long after Constantine died.
The east was wealthier, Constantinople was an exceedingly good place to have a capital, the east also needed defending from invasions over the Danube. The argument really doesn't make any sense.