I'm trying to make sure that when the pause button or menu button are pressed during game play that all the moving objects stop properly. And then they should continue doing what they were doing when the unpause button or 'continue game' menu item are selected.
I've been able to get everything but the revolute joint objects to behave.
This is the setup code:
// we need a hidden sprite to have the physics set on it
// it doesn't need an image
h_sid = CreateSprite(0)
// place it at center of target
SetSpritePosition(h_sid, t_x#, t_y#)
// set its depth and size
SetSpriteDepth(h_sid, i_dep+10)
SetSpriteSize(h_sid,2.0,2.0)
// set its physics to static, not moving
SetSpritePhysicsOn(h_sid,3)
// create the visible sprite (i_ind has image number of loaded image)
i_sid = CreateSprite(i_ind)
// apply everything (this sets the depth, scale, offsets, angles, color, alpha, physics and position, all values are in a UDT in g_spr1)
processTheSprite(g_spr1)
// set the shape of the object
// despite what the documentation says, the width value is the diameter, not radius
wid# = GetSpriteWidth(i_sid)
SetSpriteShapeCircle(i_sid,x#,y#,wid#)
// create the joint and store it in the target
i_jnt = CreateRevoluteJoint(h_sid,i_sid,t_x#,t_y#,0)
// start it moving (speed# and force# are set from file)
SetJointMotorOn(i_jnt,speed#,force#)
// store the relevant information
g_RO.i_jnt = i_jnt
g_RO.i_sid = i_sid
g_RO.h_sid = h_sid
g_RO.speed = speed#
g_RO.force = force#
The code to pause the bits:
// store information
g_RO.x_vel_v = GetSpritePhysicsVelocityX(g_RO.i_sid)
g_RO.y_vel_v = GetSpritePhysicsVelocityY(g_RO.i_sid)
g_RO.x_vel_h = GetSpritePhysicsVelocityX(g_RO.h_sid)
g_RO.y_vel_h = GetSpritePhysicsVelocityY(g_RO.h_sid)
g_RO.ang_h = GetSpritePhysicsAngularVelocity(g_RO.h_sid)
// stop everything
SetJointMotorOff(g_RO.i_jnt)
SetSpritePhysicsVelocity(g_RO.i_sid, 0.0, 0.0)
SetSpritePhysicsVelocity(g_RO.h_sid, 0.0, 0.0)
SetSpritePhysicsAngularVelocity(g_RO.h_sid,0.0)
The code to restart it:
SetJointMotorOn(g_RO.i_jnt, g_RO.speed, g_RO.force)
SetSpritePhysicsVelocity(g_RO.i_sid, g_RO.x_vel_v, g_RO.y_vel_v)
SetSpritePhysicsVelocity(g_RO.h_sid, g_RO.x_vel_h, g_RO.y_vel_h)
SetSpritePhysicsAngularVelocity(g_RO.h_sid,g_RO.ang_h)
When I do the pause, the visible revolving sprite slows down a lot, but does not stop.
When I restart it, if I leave it paused long enough, the visible sprite goes backwards for a bit before getting back up to speed. If it is a short pause, the saved vector is still in the general forward direction of the sprite, it just gets back up to speed.
But in any case, the sprite does not stop completely.
Can anyone help me figure out the right way to pause/restart the sprites involved with a revolute joint?
Or tell me what I am doing wrong?
I do not know if this would have behaved differently in v1065. I just created the code for this piece today, with v1070.
Thank you.
Cheers,
Ancient Lady