Hallo zusammen,
ich habe gestern KineticJS entdeckt und ein wenig herumgespielt link.
Nun wollte ich das man per Linksklick einen neuen Ball hinzufügt.
[src=javascript]$('#container').click(function(e) {
if (e.button === 0) {
circle[circleAmount] = new Kinetic.Circle({
x: event.pageX,
y: event.pageY,
radius: Math.floor((Math.random() * 20) + 5),
fill: '#' + Math.floor((Math.random() * 999999) + 100000),
stroke: 'black',
strokeWidth: border,
id: circleAmount
});
layer.add(circle[circleAmount]);
posx[circleAmount] = (Math.round(Math.random()) === 1 ? 1 : -1);
posy[circleAmount] = 1;
directionx[circleAmount] = (Math.random() * maxSpeed) + minSpeed;
directiony[circleAmount] = (Math.random() * maxSpeed) + minSpeed;
gravity[circleAmount] = 0;
circleAmount = circleAmount+1;
stage.add(layer);
}
});[/src]
Allerdings bleibt die Animation einfach hängen wenn ich einen neuen Ball hinzufüge. Ich denke es liegt daran, dass die Animation den neuen Ball "nicht kennt".
[src=javascript]var anim = new Kinetic.Animation(function(frame) {
for (var i = 0; i < circleAmount; i++) {
gravity = ((circle.getY()) + circle.getRadius()) * 0.02;[/src]
Der Fehler tritt in Zeile 3 bei circle.getY() auf.
lg Zuyas
ich habe gestern KineticJS entdeckt und ein wenig herumgespielt link.
Nun wollte ich das man per Linksklick einen neuen Ball hinzufügt.
[src=javascript]$('#container').click(function(e) {
if (e.button === 0) {
circle[circleAmount] = new Kinetic.Circle({
x: event.pageX,
y: event.pageY,
radius: Math.floor((Math.random() * 20) + 5),
fill: '#' + Math.floor((Math.random() * 999999) + 100000),
stroke: 'black',
strokeWidth: border,
id: circleAmount
});
layer.add(circle[circleAmount]);
posx[circleAmount] = (Math.round(Math.random()) === 1 ? 1 : -1);
posy[circleAmount] = 1;
directionx[circleAmount] = (Math.random() * maxSpeed) + minSpeed;
directiony[circleAmount] = (Math.random() * maxSpeed) + minSpeed;
gravity[circleAmount] = 0;
circleAmount = circleAmount+1;
stage.add(layer);
}
});[/src]
Allerdings bleibt die Animation einfach hängen wenn ich einen neuen Ball hinzufüge. Ich denke es liegt daran, dass die Animation den neuen Ball "nicht kennt".
[src=javascript]var anim = new Kinetic.Animation(function(frame) {
for (var i = 0; i < circleAmount; i++) {
gravity = ((circle.getY()) + circle.getRadius()) * 0.02;[/src]
Der Fehler tritt in Zeile 3 bei circle.getY() auf.
Jemand eine Idee?Uncaught TypeError: Cannot call method 'getY' of undefined ball.html:129
(anonymous function) ball.html:129
Kinetic.Animation._runFrames kinetic-v4.7.4.min.js:3
Kinetic.Animation._animationLoop kinetic-v4.7.4.min.js:3
(anonymous function)
lg Zuyas