Facebook: Daniel Sternlicht
Twitter: @dsternlicht
LinkedIn: Daniel Sternlicht
Portfolio: danielsternlicht.com
Blog: Graphic & Technology
My Portfolio
Just another ordinary day in Netanya
Conduit Mobile - Best solution for mobile apps
Graphic & Technology blog
Compare Ninja
HTML Element
<canvas id="myCanvas"></canvas>
JS Call
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
window.onload = function() {
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
context.beginPath();
context.moveTo(100, 150);
context.lineTo(450, 50);
context.lineWidth = 10;
context.strokeStyle = "#ff0000";
context.stroke();
};
<canvas id="board" width=350 height=350></canvas>
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
=
<div id="board"></div>
var stage = new Kinetic.Stage({
container: "board",
width: 350,
height: 350
});
// stage.content = div
// Create a new layer
var layer = new Kinetic.Layer();
// Connect the stage to the layer
stage.add(layer);
Rectangles, Circles, Lines, Images and so on...
// Create a new shape
var rect = new Kinetic.Rect({
x: 10,
y: 10,
width: 200,
height: 100,
name: "square",
fill: "red",
stroke: "black",
strokeWidth: 3
});
// Add the shape to the layer
layer.add(rect);
// Create a new group
var group = new Kinetic.Group();
// Add the shape to the group
group.add(rect);
// Add the group to the layer
layer.add(group);
// Reset
if(stage != null) {
stage.clear();
}
// Create a new stage
stage = new Kinetic.Stage({
container: "board",
width: 350,
height: 350
});
var layer = new Kinetic.Layer();
var group = new Kinetic.Group();
var squaresDimensions = 5;
// Get a single square's width and height
singleCubeWidth = stage.getWidth() / squaresDimensions;
singleCubeHeight = stage.getHeight() / squaresDimensions;
var gameMapping = [];
for (i = 0; i < squaresDimensions; i++) {
gameMapping[i] = [];
for (x = 0; x < squaresDimensions; x++) {
gameMapping[i][x] = false;
var box = new Kinetic.Rect({
x : left,
y : top,
width : singleCubeWidth,
height : singleCubeHeight,
name : 'square' + [i],
fill : '#cccccc',
stroke : "#999999",
strokeWidth : 3,
shadow : {
color : '#fff',
blur : 0,
offset : [-3, -3],
alpha : 0.8
}
});
group.add(box);
}
}
layer.add(group);
stage.add(layer);
{
id: 1,
characters: [
{
name: 'Stannis',
position: [1,1]
},
{
name: 'Robb',
position: [3,2]
},
{
// Main Character
name: 'Daenerys',
position: [1,4]
}
]
}
playersLayer = new Kinetic.Layer();
var playersGroup = new Kinetic.Group();
var levelData = levels[level];
for(i = 0; i < levelData.characters.length; i++) {
// Get character's data
var cahracter = levelData.characters[i];
// Create a new player
var player = new Kinetic.Image({
x: x,
y: y,
stroke: '#971919',
strokeWidth: 4,
width: 46,
height: 46,
image: imageResources[cahracter.name],
name: cahracter.name,
position: [cahracter.position[0], cahracter.position[1]]
});
// Add player to players group
playersGroup.add(player);
// Map the player to the mapping array
gameMapping[cahracter.position[0]][cahracter.position[1]] = true;
}
// Add cursor styling
playersGroup.on("mouseover", function(e) {
document.body.style.cursor = "pointer";
});
playersGroup.on("mouseout", function(e) {
document.body.style.cursor = "default";
});
playersGroup.on('click tap', function(evt) {
// Clear previus options
clearOptions();
// Get the clicked shape
var shape = evt.shape;
// Highlight the relevant shape
shape.setShadow({...});
playersLayer.draw();
// Create the options layer
getOptions(level, shape);
});
mouseover - mouseout - mouseenter - mouseleave - mousemove - mousedown - mouseup - click - dblclick - dragstart - dragend
touchstart - touchmove - touchend - tap - dbltap - dragstart - dragmove - dragend
selectedPlayer.transitionTo({
x: shape.getX(),
y: shape.getY(),
duration: 0.5,
easing: 'linear',
callback: function() {
checkWinning(selectedOne);
}
});
<audio id="move" preload="auto">
<source src="audio/move.mp3" />
</audio>
Cross browser compatibility
<audio id="move" preload="auto">
<!-- Chrome -->
<source src="audio/move.mp3" />
<!-- Firefox -->
<source src="audio/move.ogg" />
<!-- Not supported -->
Your browser sucks.
</audio>
// Get the sound's element
var sound = document.getElementById('move');
// Play the sound
sound.play();
Facebook: Daniel Sternlicht
Twitter: @dsternlicht
LinkedIn: Daniel Sternlicht
Portfolio: danielsternlicht.com
Blog: Graphic & Technology