% -*- mode: latex; -*- mustache tags:  
\ifx\wholebook\relax\else

	\documentclass[10pt,twoside,english]{root/support/latex/sbabook/sbabook}
  \usepackage{import}
  \subimport{root/support/latex/}{common.tex}

  \hypersetup{pdfinfo = {
    Title = {{Pharo Mooc}},
    Author = {},
    Keywords = {pharo, smalltalk}}}
  \begin{document}
\fi

\chapter{Challenge 4 - Solution}
How to set up a simple game window that uses a very large scrollable game board with a huge image as the background, so that game pieces placed on that background would scroll in and out of view? 
You can get some nice maps on the web site \url{http://imgur.com/}. Use the following url to fetch them: \url{http://i.imgur.com/}. The following images \url{http://imgur.com/gallery/OssbQN3.jpeg} and \url{http://i.imgur.com/XXxgr7x.jpeg} are particularly nice map background. The solution may look like the figure below. 
\subsection{Hints: }
\begin{itemize}
\item You can create a morph from an image using \textcode{AlphaImageMorph withForm:}.
\item You can obtain the size of an image (usefull to create a PasteUpMorph of the right size) with the following messages \textcode{width} and \textcode{height}.
\item You can download a picture using \textcode{ZnEasy getJpeg: url}.
\item Have a look at \textcode{PasteUpMorph} this is a morph to drop stuff in. 
\item To define the size  of a pasteUpMorph, use the message \textcode{extent:}. To define the background morph of a pasteUpMorph use the message \textcode{backgroundMorph:}.
\item You will need to add Scrollbars so use a ScrollPane: Use \textcode{aScrollPane scroller addMorph: aPasteUp} to put the scrollbar around the pasteUp.  
\end{itemize}


\begin{figure}

\begin{center}
\includegraphics[width=0.8\textwidth]{figures/map.png}\caption{A nice map with an orange morph on it. \label{figures/map.png}}\end{center}
\end{figure}

\subsection{Solution}
\begin{displaycode}{smalltalk}
	| window pane board background |

	background := AlphaImageMorph withForm: (ZnEasy getJpeg: 'http://i.imgur.com/XXxgr7x.jpeg').
	background lock.

	board := PasteUpMorph new.
	board 
		color: Color gray;
		borderWidth: 3;
		borderColor: Color black;
		extent: background width@ background height; 
		backgroundMorph: background;
		addMorph: (CircleMorph new color: Color cyan; position: 41@23; yourself);
		addMorph: (Morph new color: Color orange; position: 1200@1200; yourself).

	pane := ScrollPane new.
	pane scroller addMorph: board.

	window := pane openInWindow.
	window position: 20@20; extent: 420@420.
\end{displaycode}


\ifx\wholebook\relax\else
\end{document}
\fi