bowlofrice

Members
  • Content Count

    5
  • Joined

  • Last visited

Posts posted by bowlofrice


  1. So I have tried a few more things:

    Now I'm not getting an undefined error, but immovable = true is still not working.

    I have added in a ingame timer to run to allow all the platforms in the array to be created. However, the platforms are still ignoring body.immovable = true;

     

    Quote

                  function createUniqueLocation(){

                         do{
                                var x = game.math.snapTo(game.world.randomX, 32) / 32;
                                var y = game.math.snapTo(game.world.randomY, 32) / 32;

                           if(y > 750){
                                 y = 500;
                         }
                               var idx = (y * 17) + x;

          }
                      while(locs.indexOf(idx) !== -1);
                      locs.push(idx)
                     platforms.create(x * 32, y * 32, 'platform', game.rnd.integerInRange(0,7))

                }        

                      function createPlatforms(){
                          //adding immovable to the array of platforms.
                            locs.forEach(function(e){
                    
                               e.body.immovable = true;
                           }, this);
                      }
            
                       function inGameTime(){
                         timeCheck = game.time.now; 
                     }    
    under

                  function update(){

                   if(game.time.now - timeCheck > 2000){
                     createPlatforms()
                      } else {
                      console.log(locs);
                   }

    }


     

     

     


  2. Hi,
    I am working on a phaser project in where the platforms are randomly generated. I followed: 

     

    but now I'm having an issue making the platforms immovable, getting an undefined error:

             

                   platforms = game.add.group();
                  platforms.enableBody = true;

                    for(var i = 0; i < 15; i++){
                   createUniqueLocation();

              }
                platforms.sort();

     

                    function createUniqueLocation(){

                              do{
                                    var x = game.math.snapTo(game.world.randomX, 32) / 32;
                                    var y = game.math.snapTo(game.world.randomY, 32) / 32;

                                if(y > 750){
                                      y = 500;
                                   }
                                     var idx = (y * 17) + x;

                                  }
                                    while(locs.indexOf(idx) !== -1);
                                   locs.push(idx);
                                platforms.create(x * 32, y * 32, 'platform', game.rnd.integerInRange(0,7));

                               }

     

    I saw something sort of similar where they made a function outside of the phaser canvas, whats the best way to make the platforms immovable?

     

    Thanks


  3. Hi,

    I am working on adding features to the tutorial game for phaser 2. 

    I am currently running into an issue where the scaling for the canvas isn't working. When the browser isn't in full screen mode, the canvas stretches correctly until you reach a certain point then it does this:

    https://imgur.com/a/Q5xX9RZ

    Also when you go into full screen mode the background breaks and sizing isn't correct.

    Looking at the console this is what it says about the console:

    <canvas width="2332" height="1288" style="display: block; touch-action: none; user-select: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); cursor: inherit; width: 885px; height: 489px; margin-left: 0px; margin-top: 150px; margin-bottom: -150px;"></canvas>

    I believe this second width

    width: 885px; height: 489px

     

    is the issue, but I have researched into this, and can't figure out a way to change this. 

                          var canvas_width =  window.innerWidth  * window.devicePixelRatio;
                          var canvas_height = window.innerHeight * window.devicePixelRatio;
                         var game = new Phaser.Game( canvas_width , canvas_height, Phaser.AUTO, 'game', { preload: preload, create: create,           update: update })
     

     

    * {
        margin: 0;
        padding: 0;
    }

    html body {
        width: 100%;
        height: 100%;
        background-color:#6ac1f7;
        margin: 0;

    }

    #game{
        width: 800px;
        
    }


    canvas {
        padding: 0;
        margin: 0 auto;
        width: 100%;
        height: 100%;


    }

     

    The rest of the code is here:

    https://embed.plnkr.co/gTKkhHfCgqoxI1BCQnnj/

     

    I would appreciate any help, thanks a lot!