Schludi Posted June 10, 2015 Share Posted June 10, 2015 Hello! Can so. explain me why my beer sprite is not colliding with the ground? https://phaser-schludi.c9.io/beer-througher/beerThrougher.html The code is this:var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update });var sprite;var cursors;var headline;var platforms;var ground;// Start and End of Mouse Dragvar startX, startY, endX, endY;function preload() {game.load.image('bier', 'images/Beer_klein.png');game.load.image('ground', 'images/grasunten.png');}function create() {game.stage.backgroundColor = '#00BEF2';// Enable Box2d physicsgame.physics.startSystem(Phaser.Physics.BOX2D);game.physics.box2d.friction = 0.5;game.physics.box2d.setBoundsToWorld();game.physics.box2d.restitution = 0.7;game.physics.box2d.gravity.y = 500;// Add a spritesprite = game.add.sprite(200, 400, 'bier');//sprite.body.immovable=false;//sprite.setZeroVelocity();//sprite.body.gravity=0;// The platforms group contains the ground and the 2 ledges we can jump onplatforms = game.add.group();//game.physics.box2d.enable(platforms);//platforms.body.static = true;// We will enable physics for any object that is created in this groupplatforms.enableBody = true;// Here we create the ground.var ground = platforms.create(0, game.world.height - 29, 'ground');// Scale it to fit the width of the game (the original sprite is 400x32 in size)//ground.scale.setTo(2, 2);// Enable for physics. This creates a default rectangular body.game.physics.box2d.enable(sprite);game.physics.box2d.enable(ground);// This stops it from falling away when you jump on itground.body.static=true;ground.body.immovable = true;// Modify a few body propertiessprite.body.fixedRotation = true;headline=game.add.text(5, 5, 'Drag Object.', { fill: '#ffffff', font: '14pt Arial' });cursors = game.input.keyboard.createCursorKeys();game.input.onDown.add(mouseDragStart, this);game.input.addMoveCallback(mouseDragMove, this);game.input.onUp.add(mouseDragEnd, this);}function mouseDragStart() {game.physics.box2d.mouseDragStart(game.input.mousePointer);startX=Math.round(sprite.x);startY=Math.round(sprite.y);headline.text='Start Point: (' + startX + ','+ startY +')';}function mouseDragMove() {game.physics.box2d.mouseDragMove(game.input.mousePointer);}function mouseDragEnd() {game.physics.box2d.mouseDragEnd();endX=Math.round(sprite.x);endY=Math.round(sprite.y);var distance= Math.sqrt((endX-startX)*(endX-startX)+(endY-startY)*(endY-startY));var angel = Math.atan2(endY-startY, endX-startX) * 180 / Math.PI;headline.text='Start Point: (' + startX + ','+ startY +') / End Point: (' + endX + ','+ endY +') / Distance: '+distance+' / Angel: '+angel;}function update() {//sprite.body.setZeroVelocity();// Prüfe ob die Sterne auf die Plattform treffen//game.physics.box2d.col} Link to comment Share on other sites More sharing options...
Schludi Posted June 10, 2015 Author Share Posted June 10, 2015 Hello! I solved it by myself after positioning a sprite at the bottom (without group()) and just enable the body physik. https://phaser-schludi.c9.io/beer-througher/beerThrougher.1.html Next question:I am using the Mouse Drag and Drop with follow camera. In the example above it is possible to through the beer to the right side, but when the camera is not docked at the right side, the problem is that the drag position is wrong. How can i calculate the offset when the beer is on the right side and i want to through it again? Link to comment Share on other sites More sharing options...
sombriks Posted June 13, 2015 Share Posted June 13, 2015 Hello, did you tried to add/subtract camera x,y values from sprite x,y? haven't played that much with your example, but game.camera have x,y values and you should take them on account Link to comment Share on other sites More sharing options...
Schludi Posted June 14, 2015 Author Share Posted June 14, 2015 Hi yes i did it now this way: http://www.html5gamedevs.com/topic/15116-add-camera-offset-to-mouse-pointer-when-dragging-sprite/ Thanks Link to comment Share on other sites More sharing options...
Recommended Posts