create: function() { // Display this.background = this.game.add.sprite(0,0, 'background'); this.elements = game.add.group(); //this.o = game.add.group(); this.fe=this.elements.createMultiple(20, 'hierro'); //buscar como seleccionar de varios sprites this.ox=this.elements.createMultiple(20,'oxigeno'); /*for (var i = 0; i < 10; i++) { var tempSprite=game.add.sprite(game.world.randomX, game.world.randomY, 'hierro'); tempSprite.name = 'element' + i; tempSprite.inputEnabled = true; tempSprite.input.enableDrag(false, true); this.elements.add(tempSprite); tempSprite.kill(); } for (var i = 10; i < 20; i++) { this.tempSprite=game.add.sprite(game.world.randomX, game.world.randomY, 'oxigeno'); this.tempSprite.name = 'element' + i; this.tempSprite.inputEnabled = true; this.tempSprite.input.enableDrag(false, true); //this.tempSprite.events.onInputDown.add(this.listener, this); this.elements.add(tempSprite); this.tempSprite.kill(); }*/ this.timer = this.game.time.events.loop(1500, this.add_request, this); this.Index=0; this.score = 0; var style = { font: "30px Arial", fill: "#ffffff" }; this.label_score = this.game.add.text(20, 20, "0", style); this.text = this.game.add.text(250, 16, '', { fill: '#ffffff' }); }, // This function is called 60 times per second update: function() { }, // Restart the game restart_game: function() { // Remove the timer this.game.time.events.remove(this.timer); // Start the 'main' state, which restarts the game this.game.state.start('main'); }, // Add a element on the screen add_one_element: function(x, y, Element_Index) { this.Element_Index = this.elements.getRandom(); if(!this.Element_Index.alive){ // Set the new position of the pipe this.Element_Index.reset(x, y); this.Element_Index.name = 'element' + Pipe_Index; // Add velocity to the pipe to make it move left this.Element_Index.body.velocity.y = -200; // Kill the pipe when it's no longer visible this.Element_Index.outOfBoundsKill = true; this.Element_Index.inputEnabled = true; this.Element_Index.input.enableDrag(true); this.go=1; } else { this.add_one_element(20, 600); } }, action: function() { this.Elemente_Index.events.onInputDown.add(this.listener, this); }, // Add an element with a hole somewhere in the middle add_request: function() { this.Index += 1; this.add_one_element(20, 600, this.Index); //if(this.data==1) //this.add_one_oxigen(20, 600); /*var hole = Math.floor(Math.random()*400)+1; //buscar como funciona math random var hole2 = Math.floor(Math.random()*500)+1; for (var i = 0; i < 1; i++) if (i != hole && i != hole +1) this.add_one_pipe(20, 600); this.score += 1; this.label_score.content = this.score; */ }, listener: function() { this..body.velocity.y = 0; //Agarra el ultimo que se crea y eso no es tan usefull. mejorar this.text.content = "You clicked"+this.data+ "times!"; },