Results 1 to 3 of 3

Thread: Pixelchecking in delphi X

  1. #1

    Pixelchecking in delphi X

    I'm using delphiX to start learning about game building and up until now, i have just tred to replicate some of the samples that come with the component suite. I tried to build the basic sprite example with the orbiting balls except that created one class called Tdot and created 2 instances. The first instance moves with my mouse and the second stays stationary and i am tryng to create a beep when the two dots collide.

    This might seem trivial but when i turn the pixelcheck on each image to false and the rectangular areas collide, a collision is detected as soon as the objects collide. When i set the pixelcheck to true, i expect that the collision only register when the 2 dots collide but instead i get a collison when they are still far apart. thought the pixel check wasn't working but when in fact it was,except that the collision is detected when the transparent area of one object collides with the object of the second dot. Is there any settings that need to be in place in addition to pixelcheck to get this to work because i have scanned the sample application and i can't seem to spot it.

    I have also tried to download the undelphiX but i get no collision at all when i open any of the projects and the sample application that comes with delphiX runs really slowly.

    If anyone has seen this in their early work and you would like to help out i'd really appreciate it.

    Code:
    unit Unit1;
      
      interface
      
      uses
        Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
        DXClass,DXDraws, DXSprite;
      
      type
        TForm1 = class(TForm)
          DXDraw1: TDXDraw;
          DXImageList1: TDXImageList;
          DXSpriteEngine1: TDXSpriteEngine;
          DXTimer1: TDXTimer;
          procedure DXDraw1Initialize(Sender: TObject);
          procedure FormCreate(Sender: TObject);
          procedure DXTimer1Timer(Sender: TObject; LagCount: Integer);
          procedure DXTimer1Activate(Sender: TObject);
          procedure DXDraw1MouseMove(Sender: TObject; Shift: TShiftState; X,
            Y: Integer);
        private
          { Private declarations }
        public
          { Public declarations }
        end;
      
        tdot=class(timagesprite)
      
            public
                 procedure DoCollision(sprite:tsprite; var done:boolean); override;
                 procedure DoMove(count:integer);override;
            end;
      
      var
        Form1: TForm1;
        dot:array[1..2] of tdot;
      
      implementation
      
      
      {$R *.DFM}
      
      procedure TForm1.DXDraw1Initialize(Sender: TObject);
      begin
      dxtimer1.enabled:=true;
      dxdraw1.Surface.canvas.textout(1,1,'sdsdsd');
      end;
      
      procedure tdot.domove(count:integer);
      begin;
      collision;
      
      end;
      
      procedure tdot.docollision(sprite:tsprite; var done:boolean);
      begin;
          if (sprite is Tdot) and (z=-1) then
          begin;
          form1.dxdraw1.surface.canvas.font.color:=clwhite;
          form1.dxdraw1.surface.canvas.textout(300,300,'OOOPS');
          form1.dxdraw1.surface.canvas.release;
          windows.beep(500,60);
          done:=false;
          end;
      end;
      
      
      procedure TForm1.FormCreate(Sender: TObject);
      
      
      begin
        DXDraw1.ColorTable := dxImageList1.Items.ColorTable;
        DXDraw1.DefColorTable := dxImageList1.Items.ColorTable;
        DXDraw1.UpdatePalette;
      
          dot[1]:=tdot.create(dxspriteengine1.engine);
          dot[1].image:=dximagelist1.items.find('dot');
          dot[1].x:=200;
          dot[1].y:=10;
          dot[1].width:=dot[1].image.width;
          dot[1].height:=dot[1].image.height;
          dot[1].pixelcheck:=true;
      
          dot[2]:=tdot.create(dxspriteengine1.engine);
          dot[2].image:=dximagelist1.items.Find('dot');
          dot[2].x:=200;
          dot[2].y:=100;
          dot[2].height:=dot[2].image.height;
          dot[2].width:=dot[2].image.width;
          dot[2].z:=-1;
          dot[2].pixelcheck:=true;
      
      end;
      
      procedure TForm1.DXTimer1Timer(Sender: TObject; LagCount: Integer);
      begin;
      
      if not DXDraw1.CanDraw then exit;
      
      dxdraw1.update;
      dxdraw1.Surface.Canvas.Font.color:=clblue;
      dxdraw1.surface.fill(clblue);
      dxspriteengine1.Draw;
      
      dxdraw1.Surface.Canvas.TextOut(20,20,'jjjj');
      dxdraw1.surface.canvas.Release;
      dxdraw1.flip;
      end;
      
      procedure TForm1.DXTimer1Activate(Sender: TObject);
      begin
      dxdraw1.surface.fill(100);
      dxdraw1.flip;
      end;
      
      procedure TForm1.DXDraw1MouseMove(Sender: TObject; Shift: TShiftState; X,
        Y: Integer);
      begin
      dot[1].x:=x-dot[1].image.width div 2;
      dot[1].y:=y-dot[1].image.height div 2;
      dxspriteengine1.move(1);
      end;
      
      end.


    Thanks in advance
    Clinton Brits
    Last edited by WILL; 16-06-2011 at 06:55 AM. Reason: Put code into a code block...

  2. #2
    It's been far too long since I used delphix (I now even recommend against using it, because there are better engines out there: zengl, asphyre, svengine (previsouly known as Pyrogine or Hadron) ), so I don't have a proper answer ready. However, have a look here www.gameprogr(...)torials.list. These tutorials might help you solve your problem.

  3. #3
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,108
    Blog Entries
    25
    You might have an easier time of using JEDI-SDL to learn game programming instead actually. DelphiX and even UnDelphiX rely on the VCL and components, though this might have been convenient back in 2002, it's not realistic as to how games are made today. SDL is a much better library to work with when starting out anyhow. Plus it's so much more straight-forward than the old DelphiX component suite.

    I usually try not to knock a library or API in it's own forum, but seeing as you are just learning game programming, I'd rather you start off on the right foot and enjoy the learning process more so than having to wrap your head around a lot of nonsense from the early days that have nothing to do with game development. Try the JEDI-SDL library found here. And have a start on the Free Pascal meets SDL tutorial site to start learning how to work with graphics, game input, audio and the rest.

    Also if you would like to check out the Game Development section on the Tutorials page at the Pascal Programming for Schools project site you'll find a good wealth of knowledge there too.
    Jason McMillen
    Pascal Game Development
    Co-Founder





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
  •  
Comodo SSL