skywalker Posted June 12, 2014 Share Posted June 12, 2014 hi im building car game , i want my car move around with no limits look to attached file the code isthis.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; }; }; Link to comment Share on other sites More sharing options...
Recommended Posts