// How to manage multiple images as a single group
// Create EaselJS Stage with canvas
var stage = new Stage($('canvas')[0]);
// Create bitmaps for player and item
var player = new Bitmap('https://s3.amazonaws.com/dxparker/blog/zolo/player.png');
var item = new Bitmap('https://s3.amazonaws.com/dxparker/blog/zolo/key.png');
// Add bitmaps to container
var container = new Container();
container.addChild(player);
container.addChild(item);
// Adjust the location of the item bitmap so it appears in the players hand
// This x & y is the offset from the container's origin
item.x = 50;
item.y = 72;
// Display container on screen
stage.addChild(container);
// Add click listener to move container around stage
stage.onMouseDown = function(event) {
container.x = event.stageX - (player.image.width / 2);
container.y = event.stageY - (player.image.height / 2);
};
// IMPORTANT: Remember to register the stage with the Ticker
// or you'll be staring at an empty canvas
Ticker.addListener(stage);
<!--
easeljs and jquery scripts have been included
using the framework and resources options of jsfiddle
-->
<canvas width="550" height="250"></canvas>
<p>Click on the canvas to move the player and key as a single unit</p>
canvas {
background-color: #cdc;
margin-bottom: 10px;
}
body {
font: normal normal 14px Arial, Tahoma, Helvetica, FreeSans, sans-serif;
}
External resources loaded into this fiddle: