Example 2 Given the function $f: \mathbf{R} \rightarrow \mathbf{R}$, satisfying $f(0) \neq 0$, and for any $x, y \in \mathbf{R}$ we have
$$
f\left((x-y)^{2}\right)=f^{2}(x)-2 x f(y)+y^{2} .
$$

Then $f(2012)=$ $\qquad$
Let $x=y=0$.
Then $f(0)=f^{2}(0) \Rightarrow f(0)=1$ or 0 (discard 0).
Let $y=x$.
$$
\begin{array}{l}
\text { Then } f(0)=f^{2}(x)-2 x f(x)+x^{2}=(f(x)-x)^{2} \\
\Rightarrow f(x)=x \pm 1 .
\end{array}
$$

If there exists $x_{0}$ such that $f\left(x_{0}\right)=x_{0}-1$, let
$$
\begin{array}{l}
x=x_{0}, y=0 \text {. } \\
\text { Then } f\left(x_{0}^{2}\right)=f^{2}\left(x_{0}\right)-2 x_{0} \\
=\left(x_{0}-1\right)^{2}-2 x_{0}=x_{0}^{2}-4 x_{0}+1 \text {. }
\end{array}
$$

Now let $x_{0}=0, y=x_{0}$.
$$
\begin{array}{l}
\text { Then } f\left(x_{0}^{2}\right)=f^{2}(0)+x_{0}^{2}=1+x_{0}^{2} \\
\Rightarrow x_{0}^{2}-4 x_{0}+1=1+x_{0}^{2} \\
\Rightarrow x_{0}=0 \Rightarrow f(0)=-1 .
\end{array}
$$

This contradicts $f(0)=1$,
Therefore, for any $x \in \mathbf{R}$, we have
$$
f(x)=x+1 \text {. }
$$

Thus, $f(2012)=2013$.