Note that there are some explanatory texts on larger screens.

plurals
  1. POSelect multiple custom objects on KineticJS and Javascript
    primarykey
    data
    text
    <p>Good Evening for everyone. I create a object on KineticJS that has this methods:</p> <pre><code> function addCelestial(cb){ this.celestialBody = new Kinetic.Circle({ id: cb.id, x:cb.x, y:cb.y, fill:cb.color, radius:cb.radius, shadowColor: cb.glow, shadowBlur: cb.glowBlur, shadowOffset: 0, shadowOpacity: cb.glowOpacity }); this.xpos = function(value){ if (typeof value === "undefined") { return this.celestialBody.getX(); } else { this.celestialBody.setX(value); } }; this.ypos = function(value){ if (typeof value === "undefined") { return this.celestialBody.getY(); } else { this.celestialBody.setY(value); } }; this.xvel = function(value){ if (typeof value === "undefined") { return this.xvel_v; } else { this.xvel_v = value; } }; this.yvel = function(value){ if (typeof value === "undefined") { return this.yvel_v; } else { this.yvel_v = value; } }; this.xacc = function(value){ if (typeof value === "undefined") { return this.xacc_v; } else { this.xacc_v = value; } }; this.yacc = function(value){ if (typeof value === "undefined") { return this.yacc_v; } else { this.yacc_v = value; } }; this.mass = function(value){ if (typeof value === "undefined") { return this.mass_v; } else { this.mass_v = value; } }; this.radius = function(value){ if (typeof value === "undefined") { return this.celestialBody.getRadius(); } else { this.celestialBody.setRadius(value); } }; this.resetForce = function(){ this.xacc(0); this.yacc(0); }; this.calcNewState = function(){ this.xvel(this.xvel() + this.xacc() * timestep); this.yvel(this.yvel() + this.yacc() * timestep); this.xpos(this.xpos() + timestep + this.xvel()); this.ypos(this.ypos() + timestep + this.yvel()); }; this.addForce = function(otherbody){ var radius = Math.pow(Math.pow(otherbody.ypos()-this.ypos(),2)+Math.pow(otherbody.xpos()-this.xpos(),2),0.5); var Gacc = otherbody.mass()/(Math.pow(radius,2)); var angle = Math.atan2((otherbody.ypos()-this.ypos()),(otherbody.xpos()-this.xpos())); this.xacc(this.xacc()+Gacc*Math.cos(angle)); this.yacc(this.yacc()+Gacc*Math.sin(angle)); }; this.logStatus = function(name){ console.log(name+' xpos:'+this.xpos()+' ypos'+this.ypos()+' xacc:'+this.xacc()+' yacc:'+this.yacc()+' xvel:'+this.xvel()+' yvel:'+this.yvel()); }; this.getChildren = function(){ return this; }; cb.layer.add(this.celestialBody); </code></pre> <p>}</p> <p>Then, i create a loop to create this objects:</p> <pre><code>for (var i = 0; i &lt; 20;i++){ var asteroidID = 'asteroid' + i; var asteroid = new addCelestial({color: 'rgb(255,255,255)',layer:layer0, id: asteroidID}); asteroid.radius(1); asteroid.xpos((Math.random()*300)+200); asteroid.ypos((Math.random()*5)+document.height/2); asteroid.xvel(0); asteroid.yvel(-5); asteroid.mass(1000); asteroid.xacc(0); asteroid.yacc(0); } </code></pre> <p>I'm trying everything to select all the 20 asteroids so i can run the methods addForce, calcNewState and resetForce but i fail miserably. Can someone please help-me with this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload