Keeping non-physics objects attached to physics objects

I’m working on a game where you hurl projectiles at enemies. I’m using the physics engine to simulate gravity on the projectiles and handle collisions with the bad guys. 

I’d like to add heath bars to the enemies, but have seen warnings about display groups and physics objects not doing so well together. What would happen if I did this though? I’d be taking the enemy (an animated sprite and physics body) and putting it inside a display group, then adding a health bar 10px over the enemy’s head, in the same display group. My game loop currently moves the enemy across the screen by modifying its x value, but I would theoretically want to move its display group instead. 

Testing this is my game will require a lot of rewriting, so I’m seeking the wisdom of the masses before I dive in. What’s the right way to accomplish this? Thanks!

I’d use the enterFrame listener and simply have the bar keep itself over the object you want to track.

I’ll see if I can work up an example.

Ditto to Ed’s comment. It’s easy enough to “pin” your display objects to the physical body through a Runtime/timer. something like:

 local function trackRuntime() testBody.x = testBody.hitBox.x testBody.y = testBody.hitBox.y-1 testBody.out.x = testBody.x testBody.out.y = testBody.hitBox.y-1 testBody.healthBar.x = testBody.hitBox.x testBody.healthBar.y = testBody.hitBox.y-18 testBody.gun.x = testBody.hitBox.x testBody.gun.y = testBody.hitBox.y-1 testBody.healthBar.width = (testBodyHitPoints\*testBodyL1) end Runtime:addEventListener("enterFrame", trackRuntime)

The hitBox would be the actual physical body to which all other display objects would be “pinned”.

Brilliant. Thanks guys!

I’d use the enterFrame listener and simply have the bar keep itself over the object you want to track.

I’ll see if I can work up an example.

Ditto to Ed’s comment. It’s easy enough to “pin” your display objects to the physical body through a Runtime/timer. something like:

 local function trackRuntime() testBody.x = testBody.hitBox.x testBody.y = testBody.hitBox.y-1 testBody.out.x = testBody.x testBody.out.y = testBody.hitBox.y-1 testBody.healthBar.x = testBody.hitBox.x testBody.healthBar.y = testBody.hitBox.y-18 testBody.gun.x = testBody.hitBox.x testBody.gun.y = testBody.hitBox.y-1 testBody.healthBar.width = (testBodyHitPoints\*testBodyL1) end Runtime:addEventListener("enterFrame", trackRuntime)

The hitBox would be the actual physical body to which all other display objects would be “pinned”.

Brilliant. Thanks guys!