Eli_phaser Posted March 25, 2015 Share Posted March 25, 2015 I need to make a game where dragging commands I give the path by which character will to move forward, left, right. I do not know how to remember the id command forward, left, right in a sequence/array komande, after which I can start the run and thrown such a way that the character moves ? var game = new Phaser.Game("100%","100%",Phaser.CANVAS,"",{preload:onPreload,create:onCreate,resize:onResize});var GlavniKarakter = {'X':4,'Y':2,'Sifra':2,'pravac':1 // 1 move, 2 right, 3 left};//matrixvar level = [[1,1,1,1,1,1,1,1],[1,0,0,1,1,1,1,1],[1,0,0,1,1,1,1,1],[1,0,0,0,0,0,0,1],[1,1,2,1,1,1,0,1],[1,0,0,0,1,0,0,1],[1,0,0,0,1,1,1,1],[1,1,1,1,1,1,1,1]];// array from runvar komande = [];function onPreload() {game.stage.backgroundColor = "#FDD267";game.load.spritesheet("polja","polja.png",40,40);game.load.spritesheet("zid","zid.png",40,40);game.load.spritesheet("igrac","igrac.png",40,40);game.load.spritesheet("move","move.png",53,23);//movegame.load.spritesheet("right","desno.png",53,43);//rightgame.load.spritesheet("left","levo.png",53,43);//leftgame.load.spritesheet("run","run.png",45,45);//run}function onCreate() {// copy command, when you drag and dropfor(var j = 0; j<3;j++){moveForward= game.add.sprite(350, 30*1,'move',1);moveForward.inputEnabled = true;moveForward.input.enableDrag();moveForward.input.enableSnap(350, 30, false, true);//komande.push(1);}this.game.time.events.add(350, function() {if (this.game.input.activePointer.isDown) {moveForward.input.startDrag(this.game.input.activePointer);}komande.push(1); // array from command}, this);for(var j = 0; j<3;j++){var moveRight = game.add.sprite(350, 30 * 2, 'right', 2);// moveRight-turn rughtmoveRight.inputEnabled = true;moveRight.input.enableDrag();moveRight.input.enableSnap(350, 30, false, true);this.game.time.events.add(350, function() {if (this.game.input.activePointer.isDown) {moveRight.input.startDrag(this.game.input.activePointer);} komande.push(2);}, this);}// moveLeft-turn Leftfor(var j = 0; j<3;j++){moveLeft = game.add.sprite(350, 30 * 3, 'left', 3);moveLeft.inputEnabled = true;moveLeft.input.enableDrag();moveLeft.input.enableSnap(350, 30, false, true);this.game.time.events.add(350, function() {if (this.game.input.activePointer.isDown) {moveLeft.input.startDrag(this.game.input.activePointer);} komande.push(3);}, this);}dgmRun=game.add.sprite(350,120,'run');dgmRun.inputEnabled = true;crtajLavirint();//moveForward.events.onInputDown.add(dada, this);//moveRight.events.onInputDown.add(okretDesno, this);//moveLeft.events.onInputDown.add(okretLevo, this);dgmRun.events.onInputDown.add(runKomande, this);igrac =game.add.sprite(40*GlavniKarakter.Y,40*GlavniKarakter.X,"igrac");}/* functions that are created but not to letters*///function runForward// function runLeft//functio runRight// function run, execute array komandefunction runKomande(){for(var k=0;k<komande.length;k++){if(komande[k]==1) runForward();if(komande[k]==2) runRight();if(komande[k]==3) runLeft();//crtajLavirint();}} Link to comment Share on other sites More sharing options...
Recommended Posts