Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You want to give your custom shapes a <code>name</code> like this:</p> <pre><code>this.celestialBody = new Kinetic.Circle({ name: cb.name, // &lt;-- This works like a CSS Class and can be selected with "." 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 }); </code></pre> <p>In this case I would give your custom shapes a meaningful name that groups the shapes together, something like "asteroids" and add that inside your loop:</p> <pre><code>for (var i = 0; i &lt; 20;i++){ var asteroidID = 'asteroid' + i; var name = 'asteroids'; var asteroid = new addCelestial({name: name, 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>You can then select all asteroids by using <strong>[container].get('.asteroids')</strong> for example:</p> <p><code>var asteroids = layer.get('.asteroids')</code> or <code>var asteroids = stage.get('.asteroids')</code></p> <p>Returned is an array of the Kinetic objects that have the name <strong>asteroids</strong>.</p> <p>See here for more information: <a href="http://www.html5canvastutorials.com/kineticjs/html5-canvas-select-shapes-by-name-with-kineticjs/" rel="nofollow noreferrer">http://www.html5canvastutorials.com/kineticjs/html5-canvas-select-shapes-by-name-with-kineticjs/</a></p> <p><strong>UPDATE:</strong></p> <p>Perhaps you should try to extend the Kinetic.Shape with your custom object (celestials). Then you would have access to all of KineticJS methods along with your custom methods. Ideally this is what you would want as you don't want to lose out on the functionality of KineticJS, while using KineticJS to create objects.</p> <p>See this link as a reference: <a href="https://stackoverflow.com/questions/14892827/how-to-extend-kineticjs-shape">How to extend KineticJS shape</a></p>
    singulars
    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.
    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