Trying to add a bounding box around the sprite

52 views
Skip to first unread message

cubixpix

unread,
Jul 20, 2015, 11:14:54 AM7/20/15
to haxef...@googlegroups.com
Hello,

I'm trying to add a rectangle for showing bounding box limits around a sprite.

Unfortunately, the bounding box is displayed only at the first frame of the sprite animation, and disappears when the rest of the animation is played.

Then, when the sprite comes back to idle state (first frame), the rectangle is visible again.

I've modified the «Revenge» demo to show you the problem.

You can find the demo here : flixel-demos/1,1,2/Platformers/Revenge

I've did the modification in "PlayState.hx", and put it just before the super.update() of the update() function.


    // add this at the beginning : using flixel.util.FlxSpriteUtil;
    var org_x = _player.offset.x;
    var org_y = _player.offset.y;
    var ls:LineStyle = {thickness:1, color:0xffffffff};
    _player.drawLine( org_x,org_y, _player.width+org_x, org_y, ls);
    _player.drawLine( org_x,org_y, org_x, _player.height+org_y,ls);
    _player.drawLine( _player.width+org_x, org_y, _player.width+org_x, _player.height+org_y,ls);
    _player.drawLine( org_x,_player.height+org_y-1, _player.width+org_x, _player.height+org_y-1,ls);



Thank you for your help.

SruloArt

unread,
Jul 20, 2015, 11:32:40 AM7/20/15
to haxef...@googlegroups.com
If you have several frames then you should draw lines on all of them. However, I don't think that's a good idea because:
* If you're trying to show the bounding box for debugging purposes, just use the debug mode (you have a small box symbol in the upper (your) right corner of the debugger).
* If that's part of the game (which I doubt) then use another sprite instead of messing with the sprite's bitmapData.  

cubixpix

unread,
Jul 20, 2015, 12:48:44 PM7/20/15
to haxef...@googlegroups.com
Thank you for this quick answer!

You're right, it's for debugging purpose.

I had searched in the flixel.system.debug classes without success, but didn't thought it was part of the interface!

Thank you again.
Reply all
Reply to author
Forward
0 new messages