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

cycle관련해서 함수 압축하고, word에서 generate -> instantiate로 바꿈

parent d28c495c
......@@ -26,14 +26,14 @@ class WordObject
//alert("wordTyping : " + this.wordTyping + '\n' + "wordGrade : " + this.wordGrade + '\n' + "wordWeight : " + this.wordWeight + '\n');
}
generate(scene)
instantiate(scene)
{
var randomX = Phaser.Math.Between(100, 700);
this.physicsObj = scene.physics.add.sprite(randomX, 100, 'wordBackground').setScale(0.3);
this.wordObj = scene.add.text(randomX, 100, this.wordText, {fontFamily: '"궁서", 궁서체, serif'}).setColor('#000000');
this.wordObj.setOrigin(0.5,0.5);
}
attract(wordSpeed)
{
var dist = Phaser.Math.Distance.Between(this.physicsObj.x, this.physicsObj.y, WordSpace.gravityPoint.x, WordSpace.gravityPoint.y);
......
......@@ -2,7 +2,8 @@ var WordSpace = WordSpace || {};
WordSpace.isImageLoaded = false;
WordSpace.wordGroup = null;
WordSpace.wordGroup = [];
WordSpace.wordForcedGroup = [];
WordSpace.wordPhysicsGroup = null;
WordSpace.gravityPoint = {x: 400, y: 300};
......@@ -10,42 +11,23 @@ WordSpace.gravityPoint = {x: 400, y: 300};
WordSpace.wordCycle = null;
WordSpace.resetCycle = function(scene, _delay)
{
var option =
{
delay: _delay,
callback: function()
{
WordSpace.generateWord(this)
},
callbackScope: scene,
loop: true
};
if (this.wordCycle != null)
{
this.wordCycle = this.wordCycle.reset(
{
delay: _delay,
callback: function()
{
word = new WordObject("솽젠커");
word.generate(this);
WordSpace.wordGroup.push(word);
this.physics.add.collider(word.physicsObj, WordSpace.wordPhysicsGroup);
WordSpace.wordPhysicsGroup.add(word.physicsObj);
},
callbackScope: scene,
loop: true
}
);
this.wordCycle = this.wordCycle.reset(option);
}
else
{
this.wordCycle = scene.time.addEvent(
{
delay: _delay,
callback: function()
{
word = new WordObject("솽젠커");
word.generate(this);
WordSpace.wordGroup.push(word);
this.physics.add.collider(word.physicsObj, WordSpace.wordPhysicsGroup);
this.physics.add.collider(word.physicsObj, BackGround.brainGroup);
WordSpace.wordPhysicsGroup.add(word.physicsObj);
},
callbackScope: scene,
loop: true
}
);
this.wordCycle = scene.time.addEvent(option);
}
}
......@@ -55,4 +37,15 @@ WordSpace.loadImage = function(scene)
{
scene.load.image('wordBackground', 'assets/wordBackground.png');
}
}
WordSpace.generateWord = function(scene)
{
word = new WordObject("솽젠커");
word.instantiate(scene);
WordSpace.wordGroup.push(word);
WordSpace.wordForcedGroup.push(word);
scene.physics.add.collider(word.physicsObj, WordSpace.wordPhysicsGroup);
scene.physics.add.collider(word.physicsObj, BackGround.brainGroup);
WordSpace.wordPhysicsGroup.add(word.physicsObj);
}
\ No newline at end of file
......@@ -30,17 +30,16 @@ function preload()
function create()
{
BackGround.drawBrain(this);
WordSpace.wordGroup = [];
WordSpace.wordPhysicsGroup = this.physics.add.group();
WordSpace.resetCycle(this, 2000);
}
function update()
{
for(i = 0; i < WordSpace.wordGroup.length; i++)
WordSpace.wordForcedGroup.forEach(function(element)
{
WordSpace.wordGroup[i].attract(0.3);
}
element.attract(0.3);
});
}
var socket = io.connect();
......
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