Menu

Creating HUDSprites at runtime

Help
Kevin Bond
2021-09-05
2021-09-06
  • Kevin Bond

    Kevin Bond - 2021-09-05

    I would appreciate some advice on how to overcome the issue that is described in the comments in the code below:

    Procedure TForm1.FormCreate(Sender: TObject);
     Var i : Integer;
      Begin
        Form1.WindowState := wsMaximized;
        //Create NoOfSprites; the speed of each is chosen at random, X and Y positions likewise
        //This application simulates the random movement of single atoms. Collisions with the walls are handled explicitly.
        // Can the CollisionManager component be used to handle collisoon between atoms? I assume that it can but
        //I have made various attempts at doing this without success - from list out of bounds to access violation errors
        //I have removed my various unssuccesful attempts from the code that follows. Why have I not attempted to rely on Design time HUDSprites?
        // The answer to this question is that the number of sprites in the simulation does not make it practical to do this.
        For i := 0 To NoOfSprites
            Do
              Begin
                SpriteArray[i].GLHudSprite := TGLHudSprite.Create(Form1);
                SpriteArray[i].GLHudSprite.Width := 4;
                SpriteArray[i].GLHudSprite.Height := 4;
                // Need to create a behaviour item index 0 at runtime but
                //so far I have been unsuccessful - I am unable to get to grips with TXCollections!
                TGLBCollision(SpriteArray[i].GLHudSprite.Behaviours[0]).Manager := GLCollisionManager1;
                SpriteArray[i].GLHudSprite.Material.BlendingMode := bmAdditive;
                SpriteArray[i].GLHudSprite.Material.Texture.TextureMode := tmModulate;
                SpriteArray[i].GLHudSprite.Material.Texture.Disabled := True;
                SpriteArray[i].GLHudSprite.Material.FrontProperties.Emission.Red := 65000;
                SpriteArray[i].GLHudSprite.Material.FrontProperties.Emission.Blue := 0;
                SpriteArray[i].GLHudSprite.Material.FrontProperties.Emission.Green := 0;
                SpriteArray[i].GLHudSprite.Material.FrontProperties.Diffuse.Alpha := 1;
                SpriteArray[i].GLHudSprite.Material.FrontProperties.Diffuse.Red := 0;
                SpriteArray[i].GLHudSprite.Material.FrontProperties.Diffuse.Green := 0;
                SpriteArray[i].GLHudSprite.Material.FrontProperties.Diffuse.Blue := 0;
                SpriteArray[i].GLHudSprite.Position.X := Random(Screen.Width);
                SpriteArray[i].GLHudSprite.Position.Y := Random(Screen.Height);
                SpriteArray[i].SpeedX := Random(200);
                SpriteArray[i].SpeedY := Random(200);
                If (i Mod 2 = 0)
                  Then
                    Begin
                      SpriteArray[i].DirectionX := -1;
                      SpriteArray[i].DirectionY := 1;
                    End
                  Else
                    Begin
                      SpriteArray[i].DirectionX := 1;
                      SpriteArray[i].DirectionY := -1;
                    End;
                SpriteArray[i].GLHudSprite.Parent := GLDummyCube1;
              End;
      End;
    
     
  • Daniel

    Daniel - 2021-09-06

    Hi!
    Have you managed to make to sprites collide if you create them at design time?

    I do like this to create collision behaviour at runtime:

    With GetOrCreateCollision(SpriteArray[i].GLHudSprite) Do
          begin
          Manager:=GLCollisionManager1;
          end;
    

    I never tried on a sprite though.

     

    Last edit: Daniel 2021-09-06

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.