I am trying to use KineticJS to build a simple strategy game. I have one Kinetic.Stage resized to fit the entire screen. On that stage I intend to have three rendering layers in general. Top most the HUD layer showing the game stats - obviously not draggable. One layer below is the "Action Layer", where the game map an all the action is to be displayed. On the bottom is a static background layer, displaying some kind of a backdrop - uninteresting in this example. I intend to have my action layer draggable in order to scroll around the map. The problem is, it doesn't seem to work this way, the action layer can't be dragged. I must be missing something.
I have reproduced the problem in a fiddle here:
http://jsfiddle.net/shadowfire/2v9xS/22/
Also I have found out, that adding a shape to the root of the action layer allows dragging of the layer - but only if you drag that shape, which doesn't seem to be great solution.
The corresponding code:
var stage = new Kinetic.Stage({
container: 'myCanvas',
width: 400,
height: 400,
draggable: false,
listening: true
});
var backgroundLayer = new Kinetic.Layer({draggable: false});
var actionLayer = new Kinetic.Layer({draggable: true, listening: true});
var mapLayer = new Kinetic.Layer({draggable: true});
var foregroundLayer = new Kinetic.Layer({draggable: true, clearBeforeDraw: false});
var hudLayer = new Kinetic.Layer({draggable: false});
backgroundLayer.add(new Kinetic.Rect(
{
x:0,
y:0,
width: 400,
height: 400,
fill: 'grey'
}
));
mapLayer.add(new Kinetic.Rect(
{
x:100,
y:100,
width: 200,
height: 200,
fill: 'orange',
stroke: 'black',
draggable: true
}
));
foregroundLayer.add(new Kinetic.Circle(
{
x:200,
y:200,
radius: 30,
fill: 'yellow',
stroke: 'black',
draggable: true
}
));
actionLayer.add(mapLayer);
actionLayer.add(foregroundLayer);
actionLayer.add(new Kinetic.Text({text:"ActionLayer - draggable works only here", fill:'green', x:100, y:100}));
hudLayer.add(new Kinetic.Text(
{
fontSize: 30,
text: 'STATUS',
fill: 'green'
}
));
stage.add(backgroundLayer);
stage.add(actionLayer);
stage.add(hudLayer);