MXPain Posted August 14, 2014 Share Posted August 14, 2014 Hi guys. Object does not collide with the boundaries of the world in my mobile project. Please tell me what could be the case, for example, I wrote a short code, but the sprite passes through the boundaries of the world without collide with them./** * Created by Buggy on 14.08.14. */var hero;var cursors;BasicGame.GameTest = function (game) { // When a State is added to Phaser it automatically has the following properties set on it, even if they already exist: this.game; // a reference to the currently running game this.add; // used to add sprites, text, groups, etc this.camera; // a reference to the game camera this.cache; // the game cache this.input; // the global input manager (you can access this.input.keyboard, this.input.mouse, as well from it) this.load; // for preloading assets this.math; // lots of useful common math operations this.sound; // the sound manager - add a sound, play one, set-up markers, etc this.stage; // the game stage this.time; // the clock this.tweens; // the tween manager this.state; // the state manager this.world; // the game world this.particles; // the particle manager this.physics; // the physics manager this.rnd; // the repeatable random number generator};BasicGame.GameTest.prototype = { create: function () { var back = this.add.sprite(0, 0, 'game', 'back.png'); this.physics.startSystem(Phaser.Physics.P2JS); this.physics.p2.restitution = 0.8; hero = this.add.sprite(200, 200, 'game'); hero.anchor.setTo(0.5, 0.5); hero.pivot.y = 10; hero.animations.add('idle', Phaser.Animation.generateFrameNames('tomato_idle/', 0, 11, '', 4), 15, true); hero.animations.play('idle'); // Create our physics body. A circle assigned the playerCollisionGroup game.physics.p2.enable(hero); // This boolean controls if the player should collide with the world bounds or not hero.body.collideWorldBounds = true; cursors = game.input.keyboard.createCursorKeys(); }, update: function () { hero.body.setZeroVelocity(); if (cursors.left.isDown) { hero.body.moveLeft(200); } else if (cursors.right.isDown) { hero.body.moveRight(200); } if (cursors.up.isDown) { hero.body.moveUp(200); } else if (cursors.down.isDown) { hero.body.moveDown(200); } }}; Link to comment Share on other sites More sharing options...
Recommended Posts