fisica question: shapes infinitely created in class FContact
in
Contributed Library Questions
•
1 year ago
I used the function contactStarted() to add FCircle objects at the point where a glyph "touch" the world's edge or one another. When it does, the FCircle objects keep being created until it crashes, sending message:
AssertionError: Too many pairs (16384 shape AABB overlaps) - this usually means you have too many bodies, or you need to increase Settings.maxPairs.
Here is my code, adapted from Ricard Marxer's
Letters and also using the geomerative library to create the fonts. (a .ttf font file is needed in a data folder for it to work and change the name in red according to the font's name.)
I tried to reset the frameCount and hence setting the FCircle objects' lifetime and remove them after but it didn't work.
- import fisica.*;
- import geomerative.*;
- FWorld world;
- FChar chr;
- FCircle ball;
- float posX = 0;
- RFont font;
- char[] characters;
- void setup() {
- size(400, 400, JAVA2D);
- smooth();
- frameRate(60);
- Fisica.init(this);
- Fisica.setScale(4);
- RG.init(this);
- RG.setPolygonizer(RG.ADAPTATIVE);
- world = new FWorld();
- world.setGravity(0, 500);
- world.setEdges(this, color(255));
- world.remove(world.top);
- font = RG.loadFont("LiberationSerif-Bold.ttf");
- }
- void draw() {
- background(255);
- fill(0);
- stroke(0);
- world.draw(this);
- world.step();
- chr = new FChar(key);
- ball = new FCircle(random(2, 20));
- ball.setNoStroke();
- ball.setFill(random(255), random(255), random(255));
- }
- void keyPressed() {
- if (chr.bodyCreated()) {
- world.setEdges(this, color(255));
- world.add(chr);
- }
- if (key == ' ') {
- world.clear();
- // world.setEdges(this, color(255));
- // world.remove(world.top);
- posX = 0;
- }
- }
- void contactStarted(FContact contact) {
- ball.setPosition(contact.getX(), contact.getY());
- if (contact.getBody1() == world.getBody(contact.getX(), contact.getY())) {
- world.add(ball);
- frameCount = 0;
- if (frameCount == 30) {
- world.remove(ball);
- }
- }
- }
1