我是 Kinetic.js 的新手。我正在尝试创建一系列随机移动的组,每个组都包含一个星星和一个标题。这是当前的草图:http: //jsfiddle.net/dCw9e/。
我无法弄清楚为什么每个组对象在动画中都有一组独特的边界。任何人都可以阐明我在这里缺少什么吗?为什么每个组的边界不一样?即父容器的边界。
这是动画:
var anim = new Kinetic.Animation(function(frame) {
newtime = frame.time;
// Acceleration due to gravity via time delay (chunks miliseconds)
if((newtime - oldtime) > framerate) { // every N milliseconds... (this emulated a frame rate)
oldtime = newtime;
var angularSpeed = Math.PI / 2;
var angleDiff = [];
var stage = MilestonesGame.stage;
var stageKids = stage.getChildren();
var starsLayer = stageKids[1];
var stars = [];
stars = starsLayer.getChildren();
//console.log(stars[1].getX());
for(var n= 0; n < groups.length; n++){
angleDiff[n] = frame.timeDiff * angularSpeed / 10000 * rotDir[n];
}
for(var j = 0; j < groups.length; j++) {
/* Bounce stars off all stage parameter boundaries */
// floor boundary
if(groups[j].getY() > floor) {groups[j].setY(floor);}
if(groups[j].getY() == floor) {
$(window).resize(_.debounce(function(){
floor = MilestonesGame.stage.getHeight()-7;
}, 300));
yvel[j] *= -1;
}
//Ceiling boundary
if(groups[j].getY() < cieling){groups[j].setY(cieling);}
if(groups[j].getY() == cieling){
yvel[j] *= -1;
}
// right wall
if(groups[j].getX() > rightwall) {groups[j].setX(rightwall);}
if(groups[j].getX() == rightwall) {
$(window).resize(_.debounce(function(){
rightwall = MilestonesGame.stage.getWidth()-7;
}, 300));
xvel[j] *= -1;
}
// left wall
if(groups[j].getX() < leftwall) {groups[j].setX(leftwall);}
if(groups[j].getX() == leftwall) {
xvel[j] *= -1;
}
groups[j].setX(groups[j].getX() + xvel[j]);
groups[j].setY(groups[j].getY() + yvel[j]);
//stars[i].rotate(angleDiff[i]);
}
}
}, this.starsLayer); 动画.start();
谢谢,乔恩