-
Notifications
You must be signed in to change notification settings - Fork 6
example
premasagar edited this page Sep 22, 2011
·
6 revisions
Download the Jungle and open up index.html in your browser. Hopefully you'll see the jungle.
To create a creature you need to create a new javascript file to hold your creature.
Add this at the bottom of the /javascript/creatures.js file: see the text "* PUT YOUR DEV CREATURE SCRIPT HERE *".
Now we need a function that calls the jj.createCreature()
method. Here we create a simple canvas circle and move it around. You can use SVG or just CSS with background images if you prefer.
jj.createCreature('creature', function (creature) {
var canvas = document.createElement('canvas'),
context = canvas.getContext('2d'),
width = canvas.width = 100,
height = canvas.height = 100,
world = jj.size(),
top = 50,
left = jj.center().left - (width / 2);
creature.size({width: width, height: height});
creature.position({top: top, left: left});
creature.el.append(canvas);
context.fillStyle = "#8ED6FF";
context.beginPath();
context.arc(50, 50, width / 2, 0, Math.PI * 2, true);
context.closePath();
context.fill();
jj.bind('tick', function () {
if (top > world.height) {
top = -height;
} else {
top += 5;
}
if (left > world.width) {
left = -width;
} else {
left += 10;
}
creature.position({top: top, left: left});
});
});
Once this is done make it available online. Gists are a good way to do this. https://gist.github.com/
Then give either Prem (@premasagar), Simon (@purge) or Aron (@aron) a shout and we'll add it to the main site.