in this demo,i get the circles BitmapColor, fill upCircle,no problem.
but i get the emitter BitmapColor,can't fill the downCircle,what the problem is?
You do not need to make the bitmaps inside the Ticker.
The Emitter does not really have anything in it - once it is added to the stage or a container, then the particles are in a special container accessed by the particles property - so emitter.particles. You will need to cache the particles (the cache for the Emitter means each individual particle is cached - not the particles container) and then pass the particles to the Bitmap(). Then update the cache for the particles in the Ticker.
Also, shift the bitmap matrix to the center of the stage where the particles are naturally and then shift x from there.
import zim from "https://zimjs.org/cdn/018/zim_physics.js";
new zim.Frame(FIT, 720, 720, black, dark, ready);
function ready() {
const circles = new Container(200, 200);
loop(10, () => {
new Circle(rand(100), [pink, green, blue, yellow, purple], dark)
.center(circles)
.ble();
});
const emitter = new Emitter({
obj: [
new Circle(100, red).sca(0.2),
new Rectangle(200, 200, null, darker, 2).sca(0.2),
new Triangle(250, 250, 250, null, darker, 2)
.reg("center", "center")
.sca(0.2)
],
random: { color: [blue, green, orange] },
interval: 0.02, // default
life: 2,
decayTime: 1, // default
//sink:sink,
//sinkForce:.5,
gravity: 0,
force: 2,
cache: true, // default
}).center();
emitter.particles.cache().vis(false);
var upCircle = new Circle(100, red).center().mov(0, -100);
var downCircle = new Circle(100, red).center().mov(0, 100);
var upMatrix = new createjs.Matrix2D();
upMatrix.translate(0,100)
var downMatrix = new createjs.Matrix2D();
downMatrix.translate(W/2,H/2)
var upBitmap = new Bitmap(circles);
var downBitmap = new Bitmap(emitter.particles,W,H);
Ticker.add(function () {
emitter.particles.updateCache();
// ------for upCircle--------
upMatrix.translate(rand(-200, 200, true), 0);
var upColor = new BitmapColor(upBitmap, "repeat", upMatrix);
upCircle.color = upColor;
//------for downCircle--------
downMatrix.translate(W/2+rand(-200, 200, true), H/2)
var downColor = new BitmapColor(downBitmap, "repeat", downMatrix);
downCircle.color = downColor;
});
}
1 Like