BUILD Examples:
// SHAPES - CIRCLE, RECTANGLE & TRIANGLE
// easy shapes that can have their color and strokes modified dynamically
// makes use of the new createjs Shape classes for redrawing commands
// the shapes are also containers so you can put things in them
// radius, fill, stroke color, stroke size
var circle = new zim.Circle(40, "black", "black", 4);
circle.setFill("green");
circle.setStroke("yellow");
circle.setStrokeSize(10);
stage.addChild(circle);
// width, height, fill, stroke color, stroke size, rounded corner size
var rectangle = new zim.Rectangle(20, 200, null, null, null, 10);
rectangle.setFill("white");
// rectangle.setStroke("yellow"); // cannot set because not set at start
// rectangle.setStrokeSize(10); // cannot set because not set at start
rectangle.alpha = .5;
rectangle.x = 10;
rectangle.y = 10;
rectangle.rotation = -10;
stage.addChild(rectangle);
// three line lengths, fill, stroke color, stroke size, center, adjust
var triangle = new zim.Triangle(100, 100, 100, #CCC", "#444");
triangle.setFill("green");
triangle.setStroke("yellow");
triangle.setStrokeSize(4); // can set as long as stroke color was initially set
stage.addChild(triangle);
// CHECKBOX & LABEL
// a traditional CheckBox ;-)
// label can just be text or can supply a ZIM Label
// ZIM Label object lets you customize labels of buttons, panes, checkboxes and radio buttons
// labelText, fontSize, font, textColor, textRollColor, shadowColor, shadowBlur
var label = new zim.Label("OPTIONS", 32, "verdana", "#222", "#C60");
// size, label, startChecked, color, margin
var checkBox = new zim.CheckBox(40, label, false, "#222222");
checkBox.x = 450; checkBox.y = 470;
stage.addChild(checkBox);
checkBox.on("change", function(e) {
zog(e.target.label.text, e.target.checked, e.target.label);
// can use text or checked to figure out what to do
});
// RADIO BUTTON
// A horizontal or vertical set of radio buttons
// size, buttonData, vertical, color, spacing, margin
// buttonData can also have more information:
// [{label:ZIM Label or text, id:optional id, selected:optional Boolean}, {etc...}]
var radio = new zim.RadioButtons(40, ["OFF", "MID", "MAX"], false, "#222222");
radio.x = 450; radio.y = 540;
radio.on("change", function(e) {
zog(e.target.text, e.target.selectedIndex, e.target.selected, e.target.label);
});
// BUTTON
// use the zim.Button() class to make a button with rollovers
// requires stage.enableMouseOver(10); // for rollover
// requires createjs.Touch.enable(stage,true); // for mobile
// the following parameters are available (all are optional)
// width, height, label,
// backingColor, backingRollColor, borderColor, borderThickness,
// corner, shadowColor, shadowBlur
// label is a reference to a ZIM Label object (or text for a default label)
// corner is the corner radius (default 20)
// shadow color defaults to # is a blur of the drop shadow (default 16)
var button = new zim.Button(300, 80, "Try Button");
button.on("click", function() {zog("Button Pressed");});
// WAITER
// extends a createjs.Container
// adds a little animated three dot wait widget
// var waiter = new zim.Waiter(parameters);
// you need to call the waiter.show() to show the waiter and waiter.hide() to hide it
// you do not need to add it to the stage - it adds itself centered
// you can change the x and y (with origin and registration point in middle)
// pass in the stage and speed in ms for the cycle time (default 600ms)
// pass in backing color and dot color
// corner is the corner radius default 14
// color and value for shadow blur - 0 for no shadow
// we will waiter.show() and waiter.hide() below as we open the pane
var waiter = new zim.Waiter(stage);
// PANE
// use the zim.Pane() class to make a pop panel
// Pane extends createjs container so you can add objects to it
// the following are parameters:
// stage, width, height, color, drag, resets, modal, corner
// we center on the stage by default
// the panel is also added to the stage with the show() method
// and removed from the stage with the hide() method
// label is a reference to a ZIM Label object (or text for a default label)
// drag is a boolean that defaults to false - set to true to drag
// drag is limited to the stage
// resets is a boolean defaulting to false that if set to true
// makes it so the pane always starts at the start position on opening
// the modal parameter defaults to true so you can't click off the pane
// without the pane closing. if you set the modal to false
// then you must close the pane manually with hide()
// corner is the corner radius (default 20)
// backingAlpha defaults to .14 - you can set it to 0 if you want
var pane = new zim.Pane(stage, 600, 200, null, "white", true, true, true, 20, .3);
button.on("click", function() {
// demonstrate the waiter
waiter.show();
setTimeout(function() {
waiter.hide();
pane.show();
}, 1500);
}); // clicking off pane will close it
// STEPPER
// use the zim.Stepper() class to step through numbers or string options
// stepper has two arrows that can be set above and below or next to the field
// see the docs for all the parameters including size, color, label, etc.
var stepper = new zim.Stepper([1,2,3,4,5]);
stage.addChild(stepper);
stepper.on("change", function(e) {
zog(e.target.currentIndex, e.target.currentValue);
});
// PARALLAX
// note:
// the parallax class has changed signature in ZIM 1.5
// this is to additionally handle window scroll input and custom input
// the old signature looked like this for the layers:
// var layers = [[person, 200, 0], [trees, 150, 0], [backing, 100, 0]];
// the new signature is below:
// use the zim.Parallax() class to set up a parallax scene with layers
// the parameters are stage, damp, layers, auto (allows custom input)
// Parallax can use the mouse position on the stage to change layer properties
// or it can use the window scroll to change layer properties
// any properties can be changed - common are x, y, alpha, scaleX, scaleY, rotation
// Parallax also gives two convenience properties: scale and frame
// for traditional mouse movement adjusting movement on layers
// things closer should move more so provide a larger layer distance
// things farther should move less so provide a smaller layer distance
// see the live example
// for window scroll adjusting properties, see http://zimjs.com/code/parallax.html
// use the dispose() method to stop the inner parallax events
// any objects you need, you must add to the stage and remove when not needed
// Parallax uses the zim.ProportionDamp() class
// and automatically adds damping (default=.1)
// assuming you have person, trees and backing objects
// this will move the person 200 pixels when the cursor moves from 0 to stageW
// the distance is automatically centered on the start x position (with mouseX input)
var layers = [
{obj:person, prop:"x", propChange:200},
{obj:trees, prop:"x", propChange:150},
{obj:backing, prop:"x", propChange:100}
];
var scene = new zim.Parallax(stage, .05, layers);
// alternatively, you can use the addLayer() method:
// there is also a removeLayer(index) method
scene.addLayer({obj:birds, property:"x", propChange:170});
// the above defaults to using the mouseX relative to the stageW
// here is an example that specifies all the layer properties
scene.addLayer({
obj:ufo,
prop:"y",
propChange:200,
input:"scrollY",
inMin:100,
inMax:200,
factor:-1,
integer:false
});
// this would move ufo 200 pixels in y between a window scroll in y of 100 and 200
// because the factor is -1 the ufo would start 200 from its initial position
// and then animate back to the initial position when the window scroll is 200
// very complex and wonderful animations can be created see http://danzen.com/holiday2015
// SCROLLER
// use the zim.Scroller() class to
// create a horizontal or vertical animated looping background
// dynamically set the speed and direction
// that is, if the scroller is horizontal you can set left or right
// if the scroller is vertical you can set up or down
// the parameters are backing1, backing2, speed, direction, horizontal
// backing1 and backing2 are copies of the same background object
// horizontal is a boolean that defaults to true
// once you create a Scroller you cannot change its orientation
// but you can use the dispose() method and make a new one
// assuming you have forest1 and forest2 objects that are exact copies
// (Scroller swaps the backgrounds so they need to be the same)
var scene = new zim.Scroller(forest1, forest2, 5, 1, true);
scene.speed = 10; // scroller goes faster (should ease - version 2 ;-)
scene.direction = -1 // scene reverses direction