Commit f460d811 authored by 18신대성's avatar 18신대성 Committed by 16이지혜

word destroy 구현, 각 wordObj마다 개별 code를 가지게됨

parent 6a317860
...@@ -2,6 +2,8 @@ class WordObject ...@@ -2,6 +2,8 @@ class WordObject
{ {
constructor(text) constructor(text)
{ {
this.generationCode = WordSpace.nextWordCode++;
this.wordText = text; this.wordText = text;
this.wordTyping = (function(_wordText) this.wordTyping = (function(_wordText)
{ {
...@@ -34,6 +36,17 @@ class WordObject ...@@ -34,6 +36,17 @@ class WordObject
this.wordObj.setOrigin(0.5,0.5); this.wordObj.setOrigin(0.5,0.5);
} }
destroy()
{
this.wordObj.destroy();
const groupIdx = WordSpace.wordGroup.findIndex(function(item) {return this.isEqualObject(item.generationCode)}, this);
if (groupIdx > -1) WordSpace.wordGroup.splice(groupIdx, 1);
const forceIdx = WordSpace.wordForcedGroup.findIndex(function(item) {return this.isEqualObject(item.generationCode)}, this);
if (forceIdx > -1) WordSpace.wordForcedGroup.splice(forceIdx, 1);
WordSpace.wordPhysicsGroup.remove(this.physicsObj, true, true);
}
attract(wordSpeed) attract(wordSpeed)
{ {
var dist = Phaser.Math.Distance.Between(this.physicsObj.x, this.physicsObj.y, WordSpace.gravityPoint.x, WordSpace.gravityPoint.y); var dist = Phaser.Math.Distance.Between(this.physicsObj.x, this.physicsObj.y, WordSpace.gravityPoint.x, WordSpace.gravityPoint.y);
...@@ -47,6 +60,11 @@ class WordObject ...@@ -47,6 +60,11 @@ class WordObject
return this.wordWeight; return this.wordWeight;
} }
isEqualObject(_generationCode)
{
return _generationCode === this._generationCode;
}
//***********ToDo************* //***********ToDo*************
isEqual(inputWord) isEqual(inputWord)
{ {
......
...@@ -2,6 +2,8 @@ var WordSpace = WordSpace || {}; ...@@ -2,6 +2,8 @@ var WordSpace = WordSpace || {};
WordSpace.isImageLoaded = false; WordSpace.isImageLoaded = false;
WordSpace.nextWordCode = 0;
WordSpace.wordGroup = []; WordSpace.wordGroup = [];
WordSpace.wordForcedGroup = []; WordSpace.wordForcedGroup = [];
WordSpace.wordPhysicsGroup = null; WordSpace.wordPhysicsGroup = null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment