Electronegativity of fluorine is more than that of oxygen atom, so F gains electron with negative charge.
In oxygen difluoride (OF2) and dioxygen difluoride (O2F2), oxygen transfers electron to fluorine atom.
Thus, Oxidation number of oxygen in OF2=+2
Oxidation number of oxygen in O2F2=+1.