This is because when the metals are heated (burned), their electrons can briefly 'jump' from lower energy electron shells to higher energy electron shells. This requires energy to happen, and light is not released just yet. Because the metallic atom is unstable at this point, the electrons only stay in the higher energy shells very briefly. When they return back to the lower energy levels, they emit light. The color of the light corresponds to the energy level difference between the two shells (e=hf and c=fλ are two equations with which many exercises can be solved, where the first formula states that the energy of a photon is equal to Planck's constant multiplied by the frequency of the photon, and the second formula states that c, the speed of light, is equal to the frequency of a light wave multiplied by its wavelength).