Reputation: 39
I have a situation, the images moving left to right and viceversa, after a certain bound area the images have to hide(invisible) from the stage and when they return back it should be visible. My tween is like this :
var tween = new Kinetic.Tween({
node: puzzle,
duration: 22,
x: puzzle.getX()+700,
easing: Kinetic.Easings.Linear,
onFinish : function(){
this.reverse();
}
});
anyone please help me. Thanks in advance.
Upvotes: 1
Views: 92
Reputation: 105025
Use clipping regions
You can put your puzzle object on a group and set a clipping region on that group.
When your puzzle moves out of the group's clipping region it will not be displayed.
Demo: http://jsfiddle.net/m1erickson/hzTM7/
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Prototype</title>
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script src="http://d3lp1msu2r81bx.cloudfront.net/kjs/js/lib/kinetic-v4.7.2.min.js"></script>
<style>
body{padding:20px;}
#container{
border:solid 1px #ccc;
margin-top: 10px;
width:350px;
height:350px;
}
</style>
<script>
$(function(){
var stage = new Kinetic.Stage({
container: 'container',
width: 350,
height: 350
});
var layer = new Kinetic.Layer();
stage.add(layer);
var group=new Kinetic.Group({
clip:{x:50,y:50,width:100,height:100},
});
layer.add(group);
var bk=new Kinetic.Rect({
x:50,
y:50,
width:100,
height:100,
fill:"blue",
opacity:0.10,
});
group.add(bk);
var circle1 = new Kinetic.Circle({
x:70,
y:70,
radius: 15,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
});
group.add(circle1);
layer.draw();
var tween = new Kinetic.Tween({
node: circle1,
duration: 2,
x: circle1.getX()+120,
easing: Kinetic.Easings.Linear,
onFinish : function(){
this.reverse();
}
});
$("#myButton").click(function(){ tween.play(); });
}); // end $(function(){});
</script>
</head>
<body>
<button id="myButton">Tween</button>
<div id="container"></div>
</body>
</html>
Upvotes: 1