Skip to content

Commit c55713e

Browse files
authored
[Reviewed] [Boids] Fix a movement issue after a scene change (#704)
1 parent 2a0fac6 commit c55713e

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

extensions/reviewed/BoidsMovement.json

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
"name": "BoidsMovement",
99
"previewIconUrl": "https://resources.gdevelop-app.com/assets/Icons/Glyphster Pack/Master/SVG/Restaurant/Restaurant_restaurant_seafood_animal_fish.svg",
1010
"shortDescription": "Simulates flocks movement.",
11-
"version": "0.1.5",
12-
"description": "Simulates swarms or flocks movement following the separation, alignment, cohesion principles. The flock can be attracted to a location or avoid some obstacles.\n\nThe [Fish School example](https://editor.gdevelop.io/?project=example://fish-school) shows how properties impact on the movement.",
13-
11+
"version": "0.1.6",
12+
"description": [
13+
"Simulates swarms or flocks movement following the separation, alignment, cohesion principles. The flock can be attracted to a location or avoid some obstacles.",
14+
"",
15+
"The [Fish School example](https://editor.gdevelop.io/?project=example://fish-school) shows how properties impact on the movement."
16+
],
1417
"origin": {
1518
"identifier": "BoidsMovement",
1619
"name": "gdevelop-extension-store"
@@ -211,6 +214,7 @@
211214
" * @parameter {gdjs.RuntimeBehavior} behavior",
212215
" */",
213216
" function Boid(behavior) {",
217+
" /** @type {gdjs.RuntimeBehavior} */",
214218
" this.behavior = behavior;",
215219
" this.acceleration = new gdjs.__boidsExtension.Vector(0, 0);",
216220
" this.velocity = new gdjs.__boidsExtension.Vector(gdjs.randomFloatInRange(-1, 1), gdjs.randomFloatInRange(-1, 1));",
@@ -280,7 +284,7 @@
280284
" */",
281285
" Boid.prototype.move = function () {",
282286
" const object = this.behavior.owner;",
283-
" const timeDelta = object.getElapsedTime(runtimeScene) / 1000;",
287+
" const timeDelta = object.getElapsedTime(object.getInstanceContainer()) / 1000;",
284288
" this.acceleration.multiply(timeDelta);",
285289
"",
286290
" const previousVelocityX = this.velocity.x;",
@@ -317,7 +321,8 @@
317321
" * @return {Vector} separation direction",
318322
" */",
319323
" Boid.prototype.separate = function () {",
320-
" /** @type {BoidsManager} */",
324+
" const runtimeScene = this.behavior.owner.getInstanceContainer();",
325+
" /** @type {gdjs.__boidsExtension.BoidsManager} */",
321326
" const manager = runtimeScene.__boidsExtension.boidsManager;",
322327
" const separationRadius = this.behavior.SeparationRadius();",
323328
" this.separationDirection.set(0, 0);",
@@ -347,7 +352,8 @@
347352
" * @return {Vector} alignment direction",
348353
" */",
349354
" Boid.prototype.align = function () {",
350-
" /** @type {BoidsManager} */",
355+
" const runtimeScene = this.behavior.owner.getInstanceContainer();",
356+
" /** @type {gdjs.__boidsExtension.BoidsManager} */",
351357
" const manager = runtimeScene.__boidsExtension.boidsManager;",
352358
" const alignmentRadius = this.behavior.AlignmentRadius();",
353359
" this.alignmentDirection.set(0, 0);",
@@ -371,7 +377,8 @@
371377
" * @return {Vector} cohesion direction",
372378
" */",
373379
" Boid.prototype.cohesion = function () {",
374-
" /** @type {BoidsManager} */",
380+
" const runtimeScene = this.behavior.owner.getInstanceContainer();",
381+
" /** @type {gdjs.__boidsExtension.BoidsManager} */",
375382
" const manager = runtimeScene.__boidsExtension.boidsManager;",
376383
" const cohesionRadius = this.behavior.CohesionRadius();",
377384
" let count = 0;",
@@ -412,7 +419,7 @@
412419
" */",
413420
" function BoidsManager() {",
414421
" /**",
415-
" * @type {Map<string, Boid>}",
422+
" * @type {Map<string, gdjs.__boidsExtension.Boid>}",
416423
" */",
417424
" this.boids = new Map();",
418425
" this.boidsRBush = new rbush();",

0 commit comments

Comments
 (0)