Menu

Create an object with a behavior at runtime

Help
M.a.
2020-04-05
2020-04-08
  • M.a.

    M.a. - 2020-04-05

    Hi,
    In order to detect collisions of objects that created at runtime in the scene, I want to use a GLDCEManager. so I I think I need to define behavior for any objects that are created at runtime. How to add a Behavior for an object such as Freeform at runtime?
    If you have a better solution, please tell. (My objects are immobile and fixed).
    thank you.

     
  • Jerome.D (BeanzMaster)

    Hi M.a
    First put a TGLDCEManager on you form after you can use GetOrCreateDCEDynamic method
    Ex :

    Sphere.Scale.Assign(GetOrCreateDCEDynamic(Sphere).Size);
      GetOrCreateDCEDynamic(Sphere).OnCollision := PlayerBehaviours0Collision;
    
      procedure TFormShoot.PlayerBehaviours0Collision(Sender: TObject;
      ObjectCollided: TGLBaseSceneObject; CollisionInfo: TDCECollision);
    var
      v: TAffineVector;
    begin
    
      if ObjectCollided.Tag = 20 then
      begin
        Label2.Caption := 'Столкнулись         ';
        Actor.Tag := 0;
    
        if Actor.CurrentAnimation <> 'stand' then
        begin
          Actor.SwitchToAnimation('stand');
        end;
    
      end;
    
    end;
    

    See the the demo in Branches/Examples/path/Findpath3D

     
  • M.a.

    M.a. - 2020-04-07

    Hi Jerome.D,
    Thank you for your answer. In this example ( Branches/Examples/path/Findpath3D), a behavior has already been defined (at design time) for each object, such as the sphere. But my objects are created at Run time, and I want to know when they are created whether they have collision with other objects in my scene or not. (My objects are FreeForm) How can I define a behavior for objects that are generated at Run time and how can I assign a Manager (such as DCEManager1) to each behavior I define at runtime?

     
  • Jerome.D (BeanzMaster)

    Hi like i said use GetOrCreateDCEDynamic or GetOrCreateDCEStatic

    Var
       MyDynamicDCEBehaviour  :  TGLDCEDynamic;
       //MyStaticDCEBehaviour  :  TGLDCEStatic;
    begin   
      MyDynamicDCEBehaviour := GetOrCreateDCEDynamic(MySphere); // or GetOrCreateDCEStatic(MySphere.behaviour);
      MyDynamicDCEBehaviour.Manager := MyDCEManager;
      MyDynamicDCEBehaviour.OnColission := MyDynamicSphereCollisionMethod;
    end;
    
     

    Last edit: Jerome.D (BeanzMaster) 2020-04-08

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.