Page 29 of 30 FirstFirst ... 1927282930 LastLast
Results 281 to 290 of 300

Thread: Writing a better 2D engine. (Phoenix 2D Game Engine)

  1. #281

    Writing a better 2D engine. (Phoenix 2D Game Engine)

    Quote Originally Posted by Robert Kosek
    Quote Originally Posted by Andreaz
    There's a spread and direction variable for just that
    Yeah, but that's in the effect "template" and not the system. Say I want a meteor trail that looks the same but I want it to emit in a different direction each time. Right now there's no way I can say
    [pascal]ParticleSystem.Direction := -90;[/pascal]
    or
    [pascal]ParticleSystem := ParticleManager.Emit('bang',x,y,angle);[/pascal]
    so I can "trail" the meteor object. Or at least not that I've found. I'm still reading your source code to learn everything.

    I really look forward to the next version!
    No that is true, it's per effect, but its possible to circumvent that by changing the particle effect parameters before calling the particlesystems update function, it always uses the parameters stored in the effect, and you can change the effect at any time.

    The particles only inherits the position of the parent system, i'm not really shure how to handle inheriting a direction aswell, theres no clear way of interpolating the spread or the direction of the effect to the one in the system.

    Maybe some kind of vector that can be used to add to the resulting velocity vector for the particle could solve that;
    Code:
    Particle.velocity.X:= Particle.Velocity.X + System.EmitVector.X;
    jdarling, that could be a quite nice way to do it, if it's necessary, most phx objects handles the memory already, sprites, images, fonts, events and such, only the components themselves that doesnt. So only stuff that needs freeing is the imagelists, fontlists inputs and so forth.
    Amnoxx

    Oh, and this code appears to be an approximate replacement for return(random() & 0x01);

    Phoenix Wiki
    http://www.phoenixlib.net/

    Phoenix Forum
    http://www.pascalgamedevelopment.com/viewforum.php?f=71

  2. #282

    Writing a better 2D engine. (Phoenix 2D Game Engine)

    Hey Andreaz, would you test the following code for me and tell me if it works? In Turbo Delphi the game crashes as though the window isn't even shown. Only the particle system appears to do this, yet no error is raised! You can use a placeholder image for the sprite; it is just a round glow particle.

    When I comment out the effect the application runs. Turn the effect addition code on and when it closes there's an invalid pointer operation error pointing nowhere. But as soon as I turn on the random additions of particles the application crashes like a rock! :s

    Maybe you can find something I can't. (Also, the colors aren't object oriented like the particle example, so you might've weeded it out already. I can't tell with this past version.)

    Edit
    This exception seems to be the killer right here:
    Code:
    10:51:07 AM Error!: Access violation at address 00430230 in module 'GravityBombs.exe'. Read of address 00000004
    The problem is right here (last line):
    Code:
    //------------------------------------------------------------------------------
    function TPHXParticleManager.AddSystem(Effect: String; X, Y: Single): TPHXParticleSystem;
    var System: TPHXParticleSystem;
    begin
      System:= TPHXParticleSystem.Create(Self);
      System.Effect := Effects.Find(Effect);
    And traced to (the for loop declaration):
    Code:
    function TPHXImageList.IndexOf(const Name: String): Integer;
    var Index: Integer;
    begin
      for Index:=0 to FImages.Count - 1 do begin
        if TPHXImage(FImages[Index]).Name = Name then begin
          Result:=Index;
          Exit;
        end;
      end;
      Result:=-1;
    end;
    Andreas!! The error is that you aren't creating an imagelist! Searching a nil pointer for a string is a painful crash. Goodness, there isn't even a parameter to pass one to the particle manager's constructor. I hope you've got an updated copy on hand. :lol:


    I've updated the sourcecode and it is semistable now, but it still closes with that invalid pointer op message. :s At least I can see the effect now.
    Code:
    unit Main;
    
    {$IFDEF FPC}
    {$mode objfpc}{$H+}
    {$ENDIF}    
    
    interface
    
    uses
      Classes, SysUtils,
      phxBase,
      phxImages,
      phxParticles,
      phxInput,
      phxTimer,
      phxMath,
      phxClasses,
      phxLogger,
      phxScreen;
    
    const
      Gravity: TVector2f = (x: 0; y: -9.81); // Gravitic Constant of Earth in M/Sec^2 (Velocity)
    
    
    procedure MainLoop;
    
    implementation
    
    //------------------------------------------------------------------------------
    procedure MainLoop;
    var Screen: TPHXScreen;
        Particles: TPHXParticleManager;
        Mouse: TPHXMouse;
        Keyboard: TPHXKeyboard;
        Timer: TPHXTimer;
    
        i,l: Word;
    begin
      // Get the window
      Screen    := TPHXScreen.getInstance;
      Particles := TPHXParticleManager.Create;
      Mouse     := TPHXMouse.Create;
      Timer     := TPHXTimer.Create;
      Keyboard  := TPHXKeyboard.Create;
    
      Screen.VSync := True;
      Screen.DepthBits := 32;
      // Open the window
      if not Screen.Open('Gravity Bombs', -1, -1, 800, 600) then begin
        TPHXLogger.getInstance.Log(logSevere, 'Main', 'Unable to initialize form.');
        Exit;
      end;
    
    //  with Particles.Effects.Add do begin
    //    TPHXLogger.getInstance.Log(logInfo, 'Main', 'Loading comet particle...');
    //    LoadFromFile('comet.phxpar');
    //    Name := 'Comet';
    //    GrowthMin := -16;
    //    GrowthMax := -16;
    //    Texture := 'particle.png';
    //  end;
    
      if not Assigned(Particles.Images) then begin
        Particles.Images := TPHXImageList.Create;
        TPHXLogger.getInstance.Log(logWarning, 'Main', 'Imagelist is nil; initializing.');
      end;
      Particles.Images.LoadImage('particle.png').UpdatePatterns;
    
      l := 0;
    
      with Particles.Effects.Add do begin
        Name := 'Comet';
        Quota := 500;
        EmissionRate:= 100;
        Texture := 'particle.png';
        Blending := bmAdd;
        DurationMin := 0.50;
        DurationMax := 0.75;
        Direction := -90;
        SpreadMin := 360;
        SpreadMax := 360;
        VelocityMin := 72;
        VelocityMax := 84;
        TimeToLiveMin := 0.5;
        TimeToLiveMax := 0.5;
        SizeMin := 32;
        SizeMax := 32;
        GrowthMin := -12;
        GrowthMax := -16;
        NumColors := 3;
        Colors[0] := Color4f(0.7,0.8,1.0,0.6);
        Colors[1] := Color4f(0.6,0.7,0.9,0.6);
        Colors[2] := Color4f(0.1,0.2,0.5,0.6);
      end;
    
      Randomize;
    
      repeat
        Timer.Update;
        Mouse.Update;
        Keyboard.Update;
    
        if Random&#40;200&#41; <100> 0 then
          for I &#58;= 0 to Particles.Count - 1 do
            with Particles.Systems&#91;i&#93; do begin
              Position &#58;= VectorSub&#40;Position,VectorMul&#40;Gravity,Timer.FrameTime&#41;&#41;;
              if Position.Y > 650 then
                Particles.RemoveSystem&#40;Particles.Systems&#91;i&#93;&#41;;
            end;
    
        Particles.Move&#40;Timer.FrameTime&#41;;
    
        if l <> Particles.Count then begin
          l &#58;= particles.Count;
          Screen.Title &#58;= Format&#40;'Gravity Bombs &#91;%d active particle systems&#93;',&#91;l&#93;&#41;;
        end;
    
        // Clear the window
        Screen.Clear;
    
        Particles.Render;
    
        // Flip the buffers
        Screen.Flip;
      until &#40;Screen.Visible = False&#41;;
    
      Particles.Images.Free;
      Particles.Free;
      Keyboard.Free;
      Mouse.Free;
      Timer.Free;
      Screen.Free;
    end;
    
    end.

  3. #283

    Writing a better 2D engine. (Phoenix 2D Game Engine)

    Quote Originally Posted by Robert Kosek
    Andreas!! The error is that you aren't creating an imagelist! Searching a nil pointer for a string is a painful crash. Goodness, there isn't even a parameter to pass one to the particle manager's constructor. I hope you've got an updated copy on hand. :lol:
    Me ?

    Hehe, anyway in the particle demo i have the following (not shure its changed alot since the april version either)
    Code:
     Images&#58;= TPHXImageList.Create;
      Images.LoadImage&#40;'Circle.png'&#41;;
      Images.LoadImage&#40;'Spark.png'&#41;;
      Images.LoadImage&#40;'Fire.png'&#41;;
    
    
      ParticleManager&#58;= TPHXParticleManager.Create;
      ParticleManager.Images&#58;= Images;
    There, imagelist assigned to the particle manager and ready

    And to note, all components that uses imagelists, fonts or any other resource requires the user to bind the list to the component, so you may run into the same thing again.

    Quote Originally Posted by Robert Kosek
    Code:
    unit Main;
    
    &#123;$IFDEF FPC&#125;
    &#123;$mode objfpc&#125;&#123;$H+&#125;
    &#123;$ENDIF&#125;    
    
    interface
    
    uses
      Classes, SysUtils,
      phxBase,
      phxImages,
      phxParticles,
      phxInput,
      phxTimer,
      phxMath,
      phxClasses,
      phxLogger,
      phxScreen;
    
    const
      Gravity&#58; TVector2f = &#40;x&#58; 0; y&#58; -9.81&#41;; // Gravitic Constant of Earth in M/Sec^2 &#40;Velocity&#41;
    
    
    procedure MainLoop;
    
    implementation
    
    //------------------------------------------------------------------------------
    procedure MainLoop;
    var Screen&#58; TPHXScreen;
        Particles&#58; TPHXParticleManager;
        Mouse&#58; TPHXMouse;
        Keyboard&#58; TPHXKeyboard;
        Timer&#58; TPHXTimer;
    
        i,l&#58; Word;
    begin
      // Get the window
      Screen    &#58;= TPHXScreen.getInstance;
      Particles &#58;= TPHXParticleManager.Create;
      Mouse     &#58;= TPHXMouse.Create;
      Timer     &#58;= TPHXTimer.Create;
      Keyboard  &#58;= TPHXKeyboard.Create;
    
      Screen.VSync &#58;= True;
      Screen.DepthBits &#58;= 32;
      // Open the window
      if not Screen.Open&#40;'Gravity Bombs', -1, -1, 800, 600&#41; then begin
        TPHXLogger.getInstance.Log&#40;logSevere, 'Main', 'Unable to initialize form.'&#41;;
        Exit;
      end;
    
    //  with Particles.Effects.Add do begin
    //    TPHXLogger.getInstance.Log&#40;logInfo, 'Main', 'Loading comet particle...'&#41;;
    //    LoadFromFile&#40;'comet.phxpar'&#41;;
    //    Name &#58;= 'Comet';
    //    GrowthMin &#58;= -16;
    //    GrowthMax &#58;= -16;
    //    Texture &#58;= 'particle.png';
    //  end;
    
      if not Assigned&#40;Particles.Images&#41; then begin
        Particles.Images &#58;= TPHXImageList.Create;
        TPHXLogger.getInstance.Log&#40;logWarning, 'Main', 'Imagelist is nil; initializing.'&#41;;
      end;
      Particles.Images.LoadImage&#40;'particle.png'&#41;.UpdatePatterns;
    
      l &#58;= 0;
    
      with Particles.Effects.Add do begin
        Name &#58;= 'Comet';
        Quota &#58;= 500;
        EmissionRate&#58;= 100;
        Texture &#58;= 'particle.png';
        Blending &#58;= bmAdd;
        DurationMin &#58;= 0.50;
        DurationMax &#58;= 0.75;
        Direction &#58;= -90;
        SpreadMin &#58;= 360;
        SpreadMax &#58;= 360;
        VelocityMin &#58;= 72;
        VelocityMax &#58;= 84;
        TimeToLiveMin &#58;= 0.5;
        TimeToLiveMax &#58;= 0.5;
        SizeMin &#58;= 32;
        SizeMax &#58;= 32;
        GrowthMin &#58;= -12;
        GrowthMax &#58;= -16;
        NumColors &#58;= 3;
        Colors&#91;0&#93; &#58;= Color4f&#40;0.7,0.8,1.0,0.6&#41;;
        Colors&#91;1&#93; &#58;= Color4f&#40;0.6,0.7,0.9,0.6&#41;;
        Colors&#91;2&#93; &#58;= Color4f&#40;0.1,0.2,0.5,0.6&#41;;
      end;
    
      Randomize;
    
      repeat
        Timer.Update;
        Mouse.Update;
        Keyboard.Update;
    
        if Random&#40;200&#41; <100> 0 then
          for I &#58;= 0 to Particles.Count - 1 do
            with Particles.Systems&#91;i&#93; do begin
              Position &#58;= VectorSub&#40;Position,VectorMul&#40;Gravity,Timer.FrameTime&#41;&#41;;
              if Position.Y > 650 then
                Particles.RemoveSystem&#40;Particles.Systems&#91;i&#93;&#41;;
            end;
    
        Particles.Move&#40;Timer.FrameTime&#41;;
    
        if l <> Particles.Count then begin
          l &#58;= particles.Count;
          Screen.Title &#58;= Format&#40;'Gravity Bombs &#91;%d active particle systems&#93;',&#91;l&#93;&#41;;
        end;
    
        // Clear the window
        Screen.Clear;
    
        Particles.Render;
    
        // Flip the buffers
        Screen.Flip;
      until &#40;Screen.Visible = False&#41;;
    
      Particles.Images.Free;
      Particles.Free;
      Keyboard.Free;
      Mouse.Free;
      Timer.Free;
      Screen.Free;
    end;
    
    end.
    I've changed how the particle systems is managed by the manager, uses a standard TList now instead, should help on that error.


    Oh, and theres no need to call UpdatePatterns when loading an image, it's done automatically Only needed if you change the patterns manually!
    Amnoxx

    Oh, and this code appears to be an approximate replacement for return(random() & 0x01);

    Phoenix Wiki
    http://www.phoenixlib.net/

    Phoenix Forum
    http://www.pascalgamedevelopment.com/viewforum.php?f=71

  4. #284

    Writing a better 2D engine. (Phoenix 2D Game Engine)

    Okay. I didn't expect all that in the beginning, so I had to work and troubleshoot my way through the whole thing. Other than the annoyance at being lost for a little bit, I looked right past the imagelist creation in the sample, it works pretty well.

    You need to regen the documentation though, since I noticed that the particle system has documentation but not in what is generated.

    Here's a template contribution for you. I don't know how FPC handles exceptions, but this forces all exceptions to be logged via Phoneix's internal logger. However if FPC/Lazarus supports exception catching along these lines then this will work just fine and dandy.

    Code:
    program Template;
    
    &#123;$APPTYPE CONSOLE&#125;
    
    uses
      SysUtils,
      Main,
      &#123;$IFNDEF FPC&#125;
        &#123;$IFDEF WINDOWS&#125;
      Windows,
        &#123;$ENDIF&#125;
      &#123;$ENDIF&#125;
      phxLogger;
    
    &#123;$IFNDEF FPC&#125;
    procedure CustomExceptions&#40;ExceptObject&#58; TObject; ExceptAddr&#58; Pointer&#41;; far;
    var
      Buffer&#58; array&#91;0..1023&#93; of Char;
    begin
      ExceptionErrorMessage&#40;ExceptObject, ExceptAddr, Buffer, SizeOf&#40;Buffer&#41;&#41;;
      &#123;$IFDEF WINDOWS&#125;
      CharToOemA&#40;Buffer, Buffer&#41;; //Necessary ANSI Conversion
      &#123;$ENDIF&#125;
      with TPHXLogger.getInstance do begin
        Log&#40;logSevere, 'phxError', Buffer&#41;;
      end;
      Halt&#40;1&#41;;
    end;
    &#123;$ENDIF&#125;
    
    begin
      &#123;$IFNDEF FPC&#125;
      ExceptProc &#58;= @CustomExceptions;
      &#123;$ENDIF&#125;
      MainLoop;
    end.

  5. #285

    Writing a better 2D engine. (Phoenix 2D Game Engine)

    Quote Originally Posted by Robert Kosek
    You need to regen the documentation though, since I noticed that the particle system has documentation but not in what is generated.
    I'm not using the documentation in the source for the doc generation anymore, it's just leftovers from before, the source gets to clustered with docs and tags to be really usefull. Im' writing it from scratch using the fpdoc tool instead, but it takes alot of time to complete through.

    Thanks for the exception code, could prove helpfull
    Amnoxx

    Oh, and this code appears to be an approximate replacement for return(random() & 0x01);

    Phoenix Wiki
    http://www.phoenixlib.net/

    Phoenix Forum
    http://www.pascalgamedevelopment.com/viewforum.php?f=71

  6. #286

    Writing a better 2D engine. (Phoenix 2D Game Engine)

    I've glanced at FPC's error catching methodry but it seems more arcane and less friendly. We'll see though. Might be able to extract something useful for FPC users too.

  7. #287

    Writing a better 2D engine. (Phoenix 2D Game Engine)

    Hey Andreaz, if I want to make a particle system that I attach to ships (IE, an exhaust trail) that doesn't die except when their engines are off, what should I do? I set the duration to 0 and it doesn't die, but how should I go about making it so that the system peters out instead of continues to spawn particles? Should I just set duration to 0.00001?

  8. #288

    Writing a better 2D engine. (Phoenix 2D Game Engine)

    Quote Originally Posted by Robert Kosek
    Hey Andreaz, if I want to make a particle system that I attach to ships (IE, an exhaust trail) that doesn't die except when their engines are off, what should I do? I set the duration to 0 and it doesn't die, but how should I go about making it so that the system peters out instead of continues to spawn particles? Should I just set duration to 0.00001?
    As of now you have to change the effect of the system to a effect with Quota=0 when you dont want any more particles to be spawned and then change back when you need new ones
    Amnoxx

    Oh, and this code appears to be an approximate replacement for return(random() & 0x01);

    Phoenix Wiki
    http://www.phoenixlib.net/

    Phoenix Forum
    http://www.pascalgamedevelopment.com/viewforum.php?f=71

  9. #289

    Writing a better 2D engine. (Phoenix 2D Game Engine)

    This is my xx attempt to start making a game =), and i would like to see an example where a sprite collides with a background. I read that there is a tile engine in the pipe, is there anything usable in it yet for a simple Jump'n'Run ?

  10. #290

    Writing a better 2D engine. (Phoenix 2D Game Engine)

    sry if this has been asked before:
    is it possible that there might be a TPHXDraw in the future? as the current TDXDraw? cuz I find it hard to make the UI for my map-editor and character-editor with the system as it is now (i would much rather just use normal forms for this. atleast for the map-editor)

Page 29 of 30 FirstFirst ... 1927282930 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •