Direct observation of a buckling transition during the formation of thin colloidal crystals