bip
@@ -811,6 +811,8 @@ class Scene
811
811
obj.scene = this;
812
812
813
813
obj.addedToScene && obj.addedToScene();
814
815
return obj;
814
816
}
815
817
816
818
removeObject (obj)
@@ -811,6 +811,8 @@ class Scene811
obj.scene = this;811
obj.scene = this;812
812
813
obj.addedToScene && obj.addedToScene();813
obj.addedToScene && obj.addedToScene();814
815
return obj;814
}816
}815
817
816
removeObject (obj)818
removeObject (obj)@@ -20,15 +20,6 @@ class FrogScene extends Scene
20
20
this.fruitSpawnTimer = this.fruitSpawnRateMax;
21
21
}
22
22
23
onLoad ()
24
{
25
while (this.fruitPool.length < this.fruitMax)
26
{
27
let fruit = new Fruit(0, 0, this.game.images.fruit, 0);
28
this.fruitPool.push(fruit);
29
}
30
}
31
32
23
update (deltaTime)
33
24
{
34
25
super.update(deltaTime);
@@ -44,10 +35,8 @@ class FrogScene extends Scene
44
35
if (this.shouldSpawn() || this.fruitSpawnTimer < 0)
45
36
{
46
37
let fruit = this.getFromFruitPoolOrCreate();
47
fruit.destroyed = false;
48
38
fruit.transform.position = this.getRandomVectorPosition(fruit);
49
39
this.setRandomSubImage(fruit);
50
this.addObject(fruit);
51
40
this.fruits.push(fruit);
52
41
53
42
this.fruitSpawnTimer = this.fruitSpawnRateMax;
@@ -57,14 +46,17 @@ class FrogScene extends Scene
57
46
58
47
destroyFruit (fruit)
59
48
{
60
this.fruits.remove(fruit);
61
this.fruitPool.push(fruit);
62
fruit.destroy();
49
if (this.fruits.contains(fruit))
50
{
51
this.fruits.remove(fruit);
52
this.fruitPool.push(fruit);
53
fruit.transform.position.x = 50000;
54
}
63
55
}
64
56
65
57
getFromFruitPoolOrCreate ()
66
58
{
67
return this.fruitPool.length > 0 ? this.fruitPool.pop() : new Fruit(0, 0, this.game.images.fruit, 0);
59
return this.fruitPool.length > 0 ? this.fruitPool.pop() : this.addObject(new Fruit(0, 0, this.game.images.fruit, 0));
68
60
}
69
61
70
62
setRandomSubImage (fruit)
@@ -20,15 +20,6 @@ class FrogScene extends Scene20
this.fruitSpawnTimer = this.fruitSpawnRateMax;20
this.fruitSpawnTimer = this.fruitSpawnRateMax;21
}21
}22
22
23
onLoad ()24
{25
while (this.fruitPool.length < this.fruitMax)26
{27
let fruit = new Fruit(0, 0, this.game.images.fruit, 0);28
this.fruitPool.push(fruit);29
}30
}31
32
update (deltaTime)23
update (deltaTime)33
{24
{34
super.update(deltaTime);25
super.update(deltaTime);@@ -44,10 +35,8 @@ class FrogScene extends Scene44
if (this.shouldSpawn() || this.fruitSpawnTimer < 0)35
if (this.shouldSpawn() || this.fruitSpawnTimer < 0)45
{36
{46
let fruit = this.getFromFruitPoolOrCreate();37
let fruit = this.getFromFruitPoolOrCreate();47
fruit.destroyed = false;48
fruit.transform.position = this.getRandomVectorPosition(fruit);38
fruit.transform.position = this.getRandomVectorPosition(fruit);49
this.setRandomSubImage(fruit);39
this.setRandomSubImage(fruit);50
this.addObject(fruit);51
this.fruits.push(fruit);40
this.fruits.push(fruit);52
41
53
this.fruitSpawnTimer = this.fruitSpawnRateMax;42
this.fruitSpawnTimer = this.fruitSpawnRateMax;@@ -57,14 +46,17 @@ class FrogScene extends Scene57
46
58
destroyFruit (fruit)47
destroyFruit (fruit)59
{48
{60
this.fruits.remove(fruit);49
if (this.fruits.contains(fruit))61
this.fruitPool.push(fruit);50
{62
fruit.destroy();51
this.fruits.remove(fruit);52
this.fruitPool.push(fruit);53
fruit.transform.position.x = 50000;54
}63
}55
}64
56
65
getFromFruitPoolOrCreate ()57
getFromFruitPoolOrCreate ()66
{58
{67
return this.fruitPool.length > 0 ? this.fruitPool.pop() : new Fruit(0, 0, this.game.images.fruit, 0);59
return this.fruitPool.length > 0 ? this.fruitPool.pop() : this.addObject(new Fruit(0, 0, this.game.images.fruit, 0));68
}60
}69
61
70
setRandomSubImage (fruit)62
setRandomSubImage (fruit)