jen Posted December 14, 2015 Share Posted December 14, 2015 I have some little squares with text being drawn with bitmapData to a sprite (very scrabble like). I am calling them tiles but they are not Phaser tiles. When dragging them, I want them to bump into each other instead of the dragged square going on top of the other squares. Here is a demo of my problem:http://phaser.io/sandbox/edit/HXZjATTw I am generating 3 draggable tiles in my example (they are stacked ontop of eachother). When you drag them around they only collide with the little Phaser man and not the platforms or the other tiles. Any thoughts on why my tiles wont bump into eachother? In the create() I am running this: var player;var platforms;var cursors;var jumpButton;var canvasZoom = 32;var tileHandGroup;var spriteWidth = 15;var spriteHeight = 15;var tiles = ["h", "j", "k"];function create() { function tiley(i){ game.physics.startSystem(Phaser.Physics.ARCADE); var bmd = game.add.bitmapData(canvasZoom, canvasZoom); // draw to the canvas context bmd.ctx.beginPath(); bmd.ctx.rect(0, 0, canvasZoom, canvasZoom); bmd.ctx.fillStyle = '#efefef'; bmd.ctx.fill(); bmd.ctx.fillStyle = '#234234'; bmd.ctx.font="20px Georgia"; bmd.ctx.fillText(tiles[i], 7,23); var tileSprite = game.make.sprite(32, 32, bmd); game.physics.arcade.enable(tileSprite); tileHandGroup.add(tileSprite); console.log(tileHandGroup); tileSprite.inputEnabled = true; tileSprite.input.enableDrag(true); } tileHandGroup = game.add.physicsGroup(Phaser.Physics.ARCADE); game.physics.enable(tileHandGroup, Phaser.Physics.ARCADE); for (var i = 0; i < tiles.length; i++) { tiley(i); } tileHandGroup.setAll('body.immovable', true); tileHandGroup.setAll('body.moves', false); tileHandGroup.setAll('body.collideWorldBounds', true); /// player = game.add.sprite(100, 200, 'player'); game.physics.arcade.enable(player); player.body.collideWorldBounds = true; player.body.gravity.y = 500; platforms = game.add.physicsGroup(); platforms.create(500, 150, 'platform'); platforms.create(-200, 300, 'platform'); platforms.create(400, 450, 'platform'); platforms.setAll('body.immovable', true); cursors = game.input.keyboard.createCursorKeys(); jumpButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);}function update () { game.physics.arcade.collide(tileHandGroup, tileHandGroup); game.physics.arcade.collide(player, platforms); game.physics.arcade.collide(player, tileHandGroup); game.physics.arcade.collide(platforms, tileHandGroup); player.body.velocity.x = 0; if (cursors.left.isDown) { player.body.velocity.x = -250; } else if (cursors.right.isDown) { player.body.velocity.x = 250; } if (jumpButton.isDown && (player.body.onFloor() || player.body.touching.down)) { player.body.velocity.y = -400; }} Link to comment Share on other sites More sharing options...
Skeptron Posted December 15, 2015 Share Posted December 15, 2015 So first of all, any object that is immovable will not move due to collisions. Try to remove the 'immovables' lines of code and see the change. Then there seems to be an issue with the letter boxes colliding with each other. It's not because of the drag, because they collide with the platforms or the player fine. And collide inside group works fine as well as platforms collide well with each other. My sandbox : http://phaser.io/sandbox/edit/yAtsRwLO jen 1 Link to comment Share on other sites More sharing options...
jen Posted December 15, 2015 Author Share Posted December 15, 2015 Thanks @Skeptron. I see why the platforms were not colliding now, thanks! Regarding the tile squares, I thought that it had something to do with using bitmapData as a texture, but if i change var tileSprite = game.make.sprite(32, 32, bmd); to var tileSprite = game.make.sprite(32, 32, 'player'); the issues persists Link to comment Share on other sites More sharing options...
Recommended Posts