You don't rotate the boundaries of the object. PIXI has a getBounds() method - it returns the smallest area (rectangle) containing all the vertices of a given object (object, group of objects or scene).
Same in Matter.js. This area is modified every time you perform an operation on the object (rotation, adding a new object, which may change dimensions).
In your engine, in my opinion, it is enough to set this dimension once so that the object will always be within the limits after making any rotation around its axis.
Determining the boundaries for a given object is to avoid making very complicated collision calculations if it is unnecessary. With the AABB limits test, you are 99% sure that you will reject the possibility of a collision correctly.
In PIXI you don't draw objects (sprite) yourself - you just pass them to the graphics engine. Then you cyclically tell only the scene to be drawn and PIXI draws all the sprites in the scene.
If you want to change the Sprite position, you change the value of sprite.position.set( x, y ) . Same with turnover.
You do not use PIXI and methods from the screen object (e.g. screen.drawSprite()) at the same time - the exception is the screen.render() method. When you choose the PIXI engine, the screen object only has a render method.
Faster than filter - organize data so that you don't have to do the same work.
If QuadTree is too complicated, simply divide the space into 30x30 equal rectangles so that they cover the entire area where the game takes place.
Each object goes to a list of corresponding rectangles.
a = [ 0..29 ] [ 0..29 ]
a[ floor( obj.x / 100) ] [ floor(obj.y / 100) ] .push( obj )
As long as the objects are evenly distributed over the entire surface it will be as good as QuadTree.
I will take a look at the code to check what happens during restart.
I suspect that the error is related to the way you move the object during the restart.
In the Matter.js engine you should use:
Body.setPosition( obj, { x: 200, y: 150 });
If the position is changed differently, the engine recalculates the force values and the object starts moving very quickly. This also applies to its rotation angle.
draw() {
engine.draw();
engine.drawEnd();
screen.drawText("object count: " + this.level0.objects.length + " | objects processed: " + this.level0.enabledCount, 0, 0, 8, "red");
screen.drawText("FPS: " + system.fps + " | " + engine.tick, 0, 7, 8, "red");
screen.drawText("Decision: " + this.ship.decision, 0, 14, 8, "red");
screen.drawText( Math.round(this.ship.x) + " " +Math.round( this.ship.y ) , 0, 28, 8, "orange")
let count = 0
for( let s of this.ships){
screen.drawText( Math.round(s.x) + " " +Math.round( s.y ) , 0, 35+count, 8, "orange")
count += 7
}
}
Variables are not updated.
Edit 2
If you change the names of the objects so that they do not coincide with the names of the functions, when you change the screen size, the error with the disappearing asteroids
object will no longer appear.
asteroidsObj = new _a.Asteroids();
this.modsLib = function() { .... }
mods = modsLib();