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

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

parent d28c495c
...@@ -26,7 +26,7 @@ class WordObject ...@@ -26,7 +26,7 @@ class WordObject
//alert("wordTyping : " + this.wordTyping + '\n' + "wordGrade : " + this.wordGrade + '\n' + "wordWeight : " + this.wordWeight + '\n'); //alert("wordTyping : " + this.wordTyping + '\n' + "wordGrade : " + this.wordGrade + '\n' + "wordWeight : " + this.wordWeight + '\n');
} }
generate(scene) instantiate(scene)
{ {
var randomX = Phaser.Math.Between(100, 700); var randomX = Phaser.Math.Between(100, 700);
this.physicsObj = scene.physics.add.sprite(randomX, 100, 'wordBackground').setScale(0.3); this.physicsObj = scene.physics.add.sprite(randomX, 100, 'wordBackground').setScale(0.3);
......
...@@ -2,7 +2,8 @@ var WordSpace = WordSpace || {}; ...@@ -2,7 +2,8 @@ var WordSpace = WordSpace || {};
WordSpace.isImageLoaded = false; WordSpace.isImageLoaded = false;
WordSpace.wordGroup = null; WordSpace.wordGroup = [];
WordSpace.wordForcedGroup = [];
WordSpace.wordPhysicsGroup = null; WordSpace.wordPhysicsGroup = null;
WordSpace.gravityPoint = {x: 400, y: 300}; WordSpace.gravityPoint = {x: 400, y: 300};
...@@ -10,42 +11,23 @@ WordSpace.gravityPoint = {x: 400, y: 300}; ...@@ -10,42 +11,23 @@ WordSpace.gravityPoint = {x: 400, y: 300};
WordSpace.wordCycle = null; WordSpace.wordCycle = null;
WordSpace.resetCycle = function(scene, _delay) WordSpace.resetCycle = function(scene, _delay)
{ {
if (this.wordCycle != null) var option =
{
this.wordCycle = this.wordCycle.reset(
{ {
delay: _delay, delay: _delay,
callback: function() callback: function()
{ {
word = new WordObject("솽젠커"); WordSpace.generateWord(this)
word.generate(this);
WordSpace.wordGroup.push(word);
this.physics.add.collider(word.physicsObj, WordSpace.wordPhysicsGroup);
WordSpace.wordPhysicsGroup.add(word.physicsObj);
}, },
callbackScope: scene, callbackScope: scene,
loop: true loop: true
} };
); if (this.wordCycle != null)
{
this.wordCycle = this.wordCycle.reset(option);
} }
else else
{ {
this.wordCycle = scene.time.addEvent( this.wordCycle = scene.time.addEvent(option);
{
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
}
);
} }
} }
...@@ -56,3 +38,14 @@ WordSpace.loadImage = function(scene) ...@@ -56,3 +38,14 @@ WordSpace.loadImage = function(scene)
scene.load.image('wordBackground', 'assets/wordBackground.png'); 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() ...@@ -30,17 +30,16 @@ function preload()
function create() function create()
{ {
BackGround.drawBrain(this); BackGround.drawBrain(this);
WordSpace.wordGroup = [];
WordSpace.wordPhysicsGroup = this.physics.add.group(); WordSpace.wordPhysicsGroup = this.physics.add.group();
WordSpace.resetCycle(this, 2000); WordSpace.resetCycle(this, 2000);
} }
function update() 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(); 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