Jump to content

HElP with flappy bird development!


laddaniel
 Share

Recommended Posts

Hi guys! I am not very good at phaser. I am developing Flappy bird for Android with help of Intel XDK.  The problem is that i don't know how to change controls from spacebar to touchscreen. Here is the code example: 

var spaceKey = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
spaceKey.onDown.add(this.jump, this);

 

 

 

Thank you

Link to comment
Share on other sites

 

There's a generic onDown event for this which captures a pointer click or tap:

this.game.input.onDown.add(this.jump, this);

Sorry for many questions, but it lags on my smartphone. It updates 60 times a second and it is a problem. I don't know where i should fix it. I think it is written in phaser.min.js

Here is main.js code

 

 
var game = new Phaser.Game(400, 480, Phaser.AUTO, 'game_div');
 
var main_state = {
 
        preload: function() { 
        this.game.stage.backgroundColor = 'green';
        this.game.load.image('bird', 'assets/bird.png');  
        this.game.load.image('pipe', 'assets/pipe.png');      
    }, 
    create: function() { 
        this.bird = this.game.add.sprite(100, 245, 'bird');
        
        this.bird.body.gravity.y = 1000; 
        var space_key = this.game.input.onDown.add(this.jump, this); 
        this.pipes = game.add.group();
        this.pipes.createMultiple(20, 'pipe');  
        this.timer = this.game.time.events.loop(1500, this.add_row_of_pipes, this);           
        this.score = 0;
        var style = { font: "34px Arial", fill: "red" };
        this.label_score = this.game.add.text(20, 20, "0", style);  
    },
    update: function() {
            if (this.bird.inWorld === false)
            this.restart_game(); 
 
            this.game.physics.overlap(this.bird, this.pipes, this.restart_game, null, this);      
    },
 
    jump: function() {
        
        this.bird.body.velocity.y = -350;
    },
    restart_game: function() {
        
        this.game.time.events.remove(this.timer);
        this.game.state.start('main');
    },
 
        add_one_pipe: function(x, y) {
        var pipe = this.pipes.getFirstDead();
        pipe.reset(x, y);
 
         pipe.body.velocity.x = -200; 
               
        pipe.outOfBoundsKill = true;
    },
 
    
    add_row_of_pipes: function() {
        var hole = Math.floor(Math.random()*5)+1;
        
        for (var i = 0; i < 8; i++)
            if (i != hole && i != hole +1) 
                this.add_one_pipe(400, i*60+10);   
    
        this.score += 1;
        this.label_score.content = this.score;  
    },
};
 
game.state.add('main', main_state);  
game.state.start('main'); 
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...