CodeProject
To demonstrate how to use Moscrif I am going to show you how to create a coloring game.
The main class for game development is the Game class. Scenes with several layers are inserted afterwords into the game. The scene fills the whole screen and is used to create a practically independent part of the game (f.e.: menu and playground). The layers are used to combine or draw more similar elements together.
Our game has one scene with two layers: first for coloring image and second for lines drawn by user.
When the user taps the screen, a layer for users drawing (called PaintingLayer) calls pointerPressed method, which saves the first point of a line.
Example: start a new line
function pointerPressed(x, y)
{
this._lastPoint = {
x : x,
y : y,
}
}
When user moves his finger on the screen, the PaintingLayer calls pointerDragged method. This method finishes the previous line and starts new line.
function pointerDragged(x, y)
{
if (this._lastPoint) {
this._lines.push(new Line({
color : this.actualColor,
width : System.width / 48,
start : this._lastPoint,
end : { x : x, y : y},
}));
this._lastPoint = {
x : x,
y : y,
}
}
}
Summary
To keep this post short, only few lines of code were shown. However, the whole source code is available to download here!