This project is read-only.

How do I apply force to this object in the function?

Sep 27, 2012 at 4:23 AM

How do I apply force to this object(usercontrol) in the function?
I grabbed this function from Demo.Advanced sample.

public void AddAnItem(UserControl uc)
{
_soundAddItem.Play();

List<PhysicsSprite> spritesAdded = cnvGame.AddPhysicsUserControl(uc, _addPosX, 0, _collisionGroupNum);
_sprites.AddRange(spritesAdded);
_collisionGroupNum++;
_addPosX += 200;
if(_addPosX > 1100)
_addPosX = 0;

}

Sep 27, 2012 at 1:55 PM

After your sprites are loaded you can access the BodyObject for applying force, rotation, etc.

For example,

        cnvGame.PhysicsObjects["cnvBlock"].BodyObject.ApplyForce(new Vector2(x,y));

note that "cnvBlock" is the name of the PhysicsSprite element inside the user control.

Sep 28, 2012 at 1:47 AM
Edited Sep 28, 2012 at 1:47 AM

Getting this error when I try that.

An exception of type 'System.Collections.Generic.KeyNotFoundException' occurred in mscorlib.dll but was not handled in user code
Additional information: The given key was not present in the dictionary.

Anything else I can try?

Sep 28, 2012 at 2:37 PM

That means that you are not using a valid spritename in the PhysicsObjects["spriteName"] key value.

To get a list of all of your valid sprite keys in the PhysicsObjects dictionary:

first add a call to:

     PhysicsUtilities.DebugSpriteList(cnvGame.PhysicsObjects, false);

.... then run your app and look in the Output Window of the debugger. You will see all of your sprite names echoed out. These are the key values you can use to access the sprites.