Use of FlxObject.Floor for Collision without a tilemap

43 views
Skip to first unread message

Matthew Brandenburg

unread,
Mar 29, 2015, 8:53:35 AM3/29/15
to haxef...@googlegroups.com
Is there a way to use FlxObject.Floor for collision if you don't have a tile map?  I want to check to see if an object is touching the floor and if so I want the object to move.  I don't have a tile map, so I'm not sure if that is the problem.  I'll add the code below...

//if ((this.y + this.height) > FlxG.stage.stageHeight) {
if (justTouched(FlxObject.FLOOR)){
this._isTouchingFloor = true;
FlxG.log.add("Y: " +  this.y);
} else {
this._isTouchingFloor = false;
}

As you can see I commented out the one way I know how to do it, just wanted to see if there was a better way to do it, because then this code is redundant and I can just use isTouching() or justTouched().  I've tested both of these and neither one works, hence the above code and flag.


Sebastian Fernandez

unread,
Apr 1, 2015, 11:02:03 AM4/1/15
to haxef...@googlegroups.com
I used a FlxSprite which represents the floor. Then you can use FlxG.collide(this,floor) and check this.isTouching(FlxObject.Floor). If true then move your object.
Collide also separate the object from the floor, so you should set floor.immovible=true to avoid the floor from gain any velocity in case of collision.
Reply all
Reply to author
Forward
0 new messages