Dang_Khoa Posted September 16, 2013 Share Posted September 16, 2013 Hello, I want to set a bounding box of a sprite which is smaller or bigger than it, is that possible? darcys22 1 Link to comment Share on other sites More sharing options...
rich Posted September 16, 2013 Share Posted September 16, 2013 Yes for sure You can use:sprite.body.setSize(width, height, offsetX, offsetY)Here is a full example showing how to use it:<?php $title = "Offset bounding box"; require('../head.php');?><script type="text/javascript">(function () { var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render }); function preload() { game.load.image('atari', 'assets/sprites/atari130xe.png'); game.load.image('mushroom', 'assets/sprites/mushroom2.png'); } var sprite1; var sprite2; function create() { game.stage.backgroundColor = '#2d2d2d'; sprite1 = game.add.sprite(50, 200, 'atari'); sprite1.name = 'atari'; sprite1.body.velocity.x = 100; // This adjusts the collision body size. // 100x50 is the new width/height. // 50, 25 is the X and Y offset of the newly sized box. // In this case the box is 50px in and 25px down. sprite1.body.setSize(100, 50, 50, 25); sprite2 = game.add.sprite(700, 220, 'mushroom'); sprite2.name = 'mushroom'; sprite2.body.velocity.x = -100; } function update() { // object1, object2, collideCallback, processCallback, callbackContext game.physics.collide(sprite1, sprite2, collisionHandler, null, this); } function collisionHandler (obj1, obj2) { game.stage.backgroundColor = '#992d2d'; console.log(obj1.name + ' collided with ' + obj2.name); } function render() { game.debug.renderRectangle(sprite1.body); game.debug.renderRectangle(sprite2.body); }})();</script><?php require('../foot.php');?> Dang_Khoa and darcys22 2 Link to comment Share on other sites More sharing options...
Dang_Khoa Posted September 16, 2013 Author Share Posted September 16, 2013 Wow, you supported so fast, thanks you very much, rich Link to comment Share on other sites More sharing options...
Rouman Posted November 6, 2013 Share Posted November 6, 2013 Sorry to revive thread, but the solution changes the body size, which doesn't affect input behaviour, just collision. I've tried changing the bounds rectangle, with no visible result, since it seems to be recalculated each time. Is it possible? Link to comment Share on other sites More sharing options...
rich Posted November 7, 2013 Share Posted November 7, 2013 No it's not possible to define a specific input hit area right now I'm afraid, it will always extend to the full bounds of the object + rotation. If you want you could always re-enable the Pixi InteractionManager and use that, although this is just a guess and I've no idea if it would work properly - but should be very fast to test out. Link to comment Share on other sites More sharing options...
lukaMis Posted November 2, 2014 Share Posted November 2, 2014 No it's not possible to define a specific input hit area right nowHiHas that maybe changed in one of the newer versions of Phaser or is input still ful sprite image regardless of its body size?TnxHave a nice dayLuka Link to comment Share on other sites More sharing options...
emp751 Posted February 15, 2017 Share Posted February 15, 2017 Any update on this? Is it possible to define a specific input hit area yet? Link to comment Share on other sites More sharing options...
samme Posted February 15, 2017 Share Posted February 15, 2017 15 hours ago, emp751 said: Is it possible to define a specific input hit area yet? Try adding and sizing a child sprite, and listening for input on that. drhayes 1 Link to comment Share on other sites More sharing options...
Recommended Posts