DelegateInstruction
Introduction
Example Code
// Assuming emitter is a valid Emitter
// Notice we use "emitter.Emit" and not "emitter.Emit()" - there are no parenthesis
// This code will make Emitter call Emit in 2 seconds.
DelegateInstruction instruction = new DelegateInstruction(emitter.Emit);
double timeToWait = 2;
instruction.TimeToExecute = TimeManager.CurrentTime + timeToWait;
emitter.Instructions.Add(instruction);Calling Custom Methods
if (InputManager.Keyboard.KeyPushed(Microsoft.Xna.Framework.Input.Keys.Space))
{
// Assumes Destroy is a 0-argument method
DelegateInstruction delegateInstruction = new DelegateInstruction(Destroy);
delegateInstruction.TimeToExecute = TimeManager.CurrentTime + 1;
// If this is an IInstructable (all Entities in Glue are):
this.Instructions.Add(delegateInstruction);
// If it's not, you can use the InstructionManager:
InstructionManager.Instructions.Add(delegateInstruction);
}DelegateInstructions and lambda expressions
Last updated
Was this helpful?