Jump to content

repeat tile sprite forever


skywalker
 Share

Recommended Posts

hi im building car game , i want my car move around with no limits look to attached file

 

the code is

this.preload = function(){
 

game.load.image('redCar', 'assets/images/redCar.png');
game.load.image('picture2', 'assets/images/policCar.png');
game.load.image('land','assets/images/scorched_earth.png')


};

 

 

    this.create = function(){

        game.world.setBounds(-3000, -3000, 4000, 4000);
        land = game.add.tileSprite(-3000, -3000, 4000, 4000, 'land');
        //land.fixedToCamera = true;
        redCar = game.add.sprite(300, 500, 'redCar');
        game.camera.follow(redCar);
        //redCar.anchor.setTo(0.5, 0.5);
        game.physics.enable(redCar, Phaser.Physics.ARCADE);
        redCar.body.drag.set(0.2);
        redCar.body.maxVelocity.setTo(400, 400);
        redCar.body.collideWorldBounds = true;
        redCar.body.allowRotation = false;
        redCar.anchor.setTo(0.5, 0.5);
        //redCar.body.drag.set(0.2);
        //redCar.body.maxAngular = 500;
        //redCar.body.angularDrag = 500;
        redCar.angle =90;

        cursors = game.input.keyboard.createCursorKeys();
        //redCar.body.angularAcceleration = 0;
    };

    this.update = function(){

        
        
            if (currentSpeed > 0)
    {
        game.physics.arcade.velocityFromRotation(redCar.rotation, currentSpeed, redCar.body.velocity);
    }

            if (cursors.up.isDown) {

                 currentSpeed += 5;

                 if (currentSpeed>=500) {currentSpeed = 500};
            }else{
                if (currentSpeed>0) {
                    currentSpeed -= 4;

                   // if (currentSpeed<0) {currentSpeed=0};
                };
            };


            if (cursors.right.isDown && currentSpeed >0) {

                redCar.angle += 2;
                //console.log(currentSpeed);
            }else if(cursors.left.isDown && currentSpeed >0) {

                redCar.angle -= 2;
            };

            
    };

 

post-9141-0-97748300-1402537034.jpg

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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