Results 1 to 3 of 3

Thread: Pixelchecking in delphi X

Threaded View

Previous Post Previous Post   Next Post Next Post
  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...

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
  •