Search the Community
Showing results for tags 'enable'.
-
So I am working on my just general knowledge of how phaser works, I have only done two tutorials. But I think I have a decent grasp on it so far. But I am running into a little problem, I am trying to use the Follower object, so that I don't have to create the vec2 and attach it, but I don't seem to understand the documentation or what it means by "If this Game Object is enabled for physics then this property will contain a reference to a Physics Body." I have scoured the docs for hours. I see how to 'enable' in arcade physics but I cannot find any reference to how with impact physics. I am able to create a body object, and assign it to the game object, as well as assign the the game object to the body, but they do not move in tandem. in fact the body does not move at all. P.S. This is not the only bug, when converting from matter.js to impact.js physics my logic on pausing player movement when the dialog modal broke. but one problem at a time.. P.P.S I know its not the best code //SHIVA path3 = new Phaser.Curves.Path(550, 450); path3.lineTo(450, 450); path3.lineTo(450, 505); path3.lineTo(550, 505); path3.lineTo(550, 450); path3.lineTo(450, 450); shiva = this.add.follower(path3, 550, 450, 'shiva'); //Phaser.GameObjects.BuildGameObject(this, Phaser.GameObjects.PathFollower) //this.game.physics.enable(shiva, impact); shivaBody = this.impact.add.body(550, 450, 16, 12); //TRYING DIFFERENT WAS TO SET BODY //shivaBody.setOffset(550, 450, 16, 12); shiva.body = shivaBody; shivaBody.setGameObject(shiva); shiva.name = "shiva"; shiva.setRotation(); shiva.depth = 30; //ALT WAY TO GET NAME //shiva.name = "shiva"; shiva.setData(npc, true); shiva.setData("name", "shiva"); npcBodies[2] = shivaBody; npcs.add(shiva); shiva.startFollow({ ease: 'Linear', duration:6000, yoyo:true, repeat: -1, _delay: 200, delay: 100 }); P.P.P.S I also tried this.physics.world.enable(shiva); this.impact.world.enable(shiva); dialog_plugin.js game.js index.html city.json
-
in this game i need physics for multiple objects for a group its fine to enable p2 bt whenever i tried to enable p2 for player with this line game.physics.p2.enable(player, false); my screen goes black why is this happening ??? var game = new Phaser.Game(window.innerWidth * window.devicePixelRatio, window.innerHeight * window.devicePixelRatio, Phaser.AUTO, '', { preload: preload, create: create, update: update}); var player; var world; var blink; var rocketangel; var rocketdirection; var rocketSpeedDelta; var rocketradius; var platforms; var scoreText; var playerangle; var scaleRatio; var score; var asteroid; scaleRatio = window.devicePixelRatio / 2; //load images or files before game starts function preload() { game.load.image('background', 'assets/game/background.png'); game.load.image('world', 'assets/game/world.png'); game.load.image('player', 'assets/game/player.png'); game.load.image('blink', 'assets/game/blink.png'); game.load.image('asteroid', 'assets/game/asteroid.png'); } //create all the images ans things on the screen function create() { score=0; rocketangel = 0; rocketdirection = 1; rocketSpeedDelta = 0.002; rocketradius = 170; playerangle=60; // A simple background for our game game.add.sprite(0, 0, 'background'); // We're going to be using physics, so enable the Arcade Physics system game.physics.startSystem(Phaser.Physics.P2JS); // Turn on impact events for the world, without this we get no collision callbacks game.physics.p2.setImpactEvents(true); game.physics.p2.restitution = 0.8; // Create our collision groups. One for the player, one for the pandas var playerCollisionGroup = game.physics.p2.createCollisionGroup(); var asteroidCollisionGroup = game.physics.p2.createCollisionGroup(); world=game.add.sprite(game.world.centerX-10, game.world.centerY-20, 'world'); world.anchor.setTo(0.5, 0.5); world.scale.setTo(scaleRatio, scaleRatio); platforms = game.add.group(); platforms .enableBody = true; platforms.physicsBodyType = Phaser.Physics.P2JS; for (var i = 0; i < 10; i++) { asteroid = platforms.create(game.world.height , game.world.width , 'asteroid'); asteroid.anchor.setTo(0.5, 0.5); asteroid.scale.setTo(scaleRatio, scaleRatio); game.physics.p2.enable(asteroid, false); asteroid.body.setRectangle(40, 40); // Tell the panda to use the pandaCollisionGroup asteroid.body.setCollisionGroup(asteroidCollisionGroup); // Pandas will collide against themselves and the player // If you don't set this they'll not collide with anything. // The first parameter is either an array or a single collision group. asteroid.body.collides([asteroidCollisionGroup, playerCollisionGroup]); } //adding player player = game.add.sprite(game.world.centerX, game.world.centerY, 'player'); player.anchor.setTo(0.5, 0.5); player.scale.setTo(scaleRatio, scaleRatio); //game.physics.p2.enable(player, false); //player.body.setCircle(28); // Set the ships collision group //player.body.setCollisionGroup(playerCollisionGroup); // The ship will collide with the pandas, and when it strikes one the hitPanda callback will fire, causing it to alpha out a bit // When pandas collide with each other, nothing happens to them. //player.body.collides( asteroidCollisionGroup, hitPanda, this); // The platforms group contains the ground and the 2 ledges we can jump on //asteroid.body.collideWorldBounds = true; // The score scoreText = game.add.text(16, 16, 'score: 0', { fontSize: '32px', fill: '#FFF' }); scoreText.scale.setTo(scaleRatio, scaleRatio); cursors = game.input.keyboard.createCursorKeys(); } function hitPanda(body1, body2) { // body1 is the space ship (as it's the body that owns the callback) // body2 is the body it impacted with, in this case our panda // As body2 is a Phaser.Physics.P2.Body object, you access its own (the sprite) via the sprite property: body2.sprite.alpha -= 0.1; } function update() { var playerangelchange; platforms.forEachAlive(moveBullets,this); platforms.forEach(function(asteroid) { game.physics.arcade.collide(player,asteroid,deathHandler, null, this); }, this); //keypress if (game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR)) { //it will speed up the rocket } else if (game.input.keyboard.isDown(Phaser.Keyboard.ENTER)) { //it will cause the blink blink= game.add.sprite(player.x, player.y, 'blink'); blink.anchor.setTo(0.5, 0.5); blink.scale.setTo(scaleRatio, scaleRatio); game.add.tween(blink).to( { alpha: 0 }, 20, Phaser.Easing.Linear.None, true); //blink.destroy(true); } else if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { rocketdirection=-1; //change the direction } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { rocketdirection=1; //change the direction } //speed of current rocket movement if (rocketdirection == 1) { rocketSpeedDelta = 1.14; playerangelchange=1.1; } else if (rocketdirection == -1) { rocketSpeedDelta = -1.14; playerangelchange=-1.1; } //for moving on a circular path scoreText.text = 'Score: ' + score; rocketangel += this.time.physicsElapsed * rocketSpeedDelta ; player.x = game.world.centerX+ Math.cos(rocketangel) * rocketradius ; player.y = game.world.centerY+Math.sin(rocketangel) * rocketradius ; playerangle+=playerangelchange; player.angle=playerangle; } function moveBullets (asteroid) { setTimeout(accelerateToObject(asteroid,world,30),50000); //start accelerateToObject on every bullet } function accelerateToObject(obj1, obj2, speed) { if (typeof speed === 'undefined') { speed = 60; } var angle = Math.atan2(obj2.y - obj1.y, obj2.x - obj1.x); //obj1.body.rotation = angle + game.math.degToRad(90); // correct angle of angry bullets (depends on the sprite used) obj1.body.force.x = Math.cos(angle) * speed; // accelerateToObject obj1.body.force.y = Math.sin(angle) * speed; } function deathHandler() { this.game.state.start("gameover"); }; </script> </body> </html>