Results 1 to 6 of 6

Thread: Problem with DXInput

  1. #1

    Problem with DXInput

    "You'll never really learn to swear until you get a computer."
    -- Unknown

    Guys, this quote applies to me!!! :x

    I have a background sprite with a sprite on top of it which is supposed to move but I can't seem to get it right. Help please :-)

    Code:
    unit GameU;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, DXDraws, DXClass, DXSprite, DXInput, GifImage;
    
    
    
    type
      TForm1 = class(TDXForm)
        DXDraw1: TDXDraw;
        DXImageList1: TDXImageList;
        DXTimer1: TDXTimer;
        DXSpriteEngine1: TDXSpriteEngine;
        DXInput1: TDXInput;
        procedure DXDraw1Initialize(Sender: TObject);
        procedure DXTimer1Timer(Sender: TObject; LagCount: Integer);
        procedure DXDraw1Finalize(Sender: TObject);
        procedure DXDraw1KeyDown(Sender: TObject; var Key: Word;
          Shift: TShiftState);
        procedure DXDraw1KeyUp(Sender: TObject; var Key: Word;
          Shift: TShiftState);
      private
       procedure BackGround;
       procedure BallCreate;
        { Private declarations }
      public
    
        { Public declarations }
      end;
    
       // The BackGroundClass
     TBackground = class(TBackgroundSprite)
     end;
    
      //This is the ball class
     TBall = class(TImageSprite)
      private
      public
      procedure DoMove(MoveCount: Integer); override;
      end;
    
    var
      Form1: TForm1;
      Ball : TBall;
      SBackground : TBackground;
      BallisDead : Boolean;
      MoveLeft, MoveRight : boolean;
    
    implementation
    
    {$R *.dfm}
    
    Procedure TForm1.BackGround;
    begin
      SBackground := TBackground.Create (form1.DXSpriteEngine1.Engine);
      with SBackground do
      begin
      image := form1.DXImageList1.Items.Find('skytree');
      image.Transparent := false;
      SetMapSize(1,1);
      Z := -10;
      Tile := false;
      end;
    end;
    
    procedure TForm1.BallCreate;
    begin
      Ball := TBall.Create(DXSpriteEngine1.Engine);
      ball.Image := DXImageList1.Items.Find('Test');
      ball.X := 30;
      Ball.Y := 130;
      Ball.Width := Ball.Image.Width;
      Ball.Height := Ball.Image.Height;
      Ball.PixelCheck := False;
    end;
    
    procedure TBall.DoMove(MoveCount : integer);
    begin
      if MoveRight then
      x := x + 50;
      if MoveLeft then
      x := x - 50;
    end;
    
    procedure TForm1.DXDraw1Initialize(Sender: TObject);
    begin
      BallCreate;
      background;
      dxTimer1.Enabled := true;
    end;
    
    procedure TForm1.DXTimer1Timer(Sender: TObject; LagCount: Integer);
    begin
      if not DXDraw1.CanDraw then Exit;
      DXInput1.Update;
      DXSpriteEngine1.Move(1);
      DXSpriteEngine1.Draw;
      DXDraw1.Flip;
    end;
    
    
    procedure TForm1.DXDraw1Finalize(Sender: TObject);
    begin
      dxTimer1.Enabled := false;
    end;
    
    procedure TForm1.DXDraw1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      if Key = vk_Left then MoveLeft := true;
      if Key = vk_Right then MoveRight := True;
    end;
    
    procedure TForm1.DXDraw1KeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      if key=VK_LEFT then moveleft := False;
      if key=VK_RIGHT then moveright := False;
    end;
    
    end.
    Wake up from the dream and live your life to the full

  2. #2

    Problem with DXInput

    From what I can see, you are not using dxinput properly. Check the supplied demos and look at the input demo.

    I don't have delphix installed on my current pc but IIRC your TBall.doMove procedure should look something like
    [pascal]
    procedure TBall.DoMove(MoveCount: Integer);
    begin
    if (isLeft in form1.DXInput1.states) then x:=x-2;
    if (isright in form1.DXInput1.states) then x:=x+2;
    if (isup in form1.DXInput1.states) then y:=y-2;
    if (isdown in form1.DXInput1.states) then y:=y+2;
    end
    [/pascal]

    Alternatively, check the space shooter tutorial on my site. That should get you on your way too.

  3. #3

    Problem with DXInput

    Hello Wizard,
    first i suggest you to follow a good tutorial for delphix, there're plenty of
    them around, just google for delphix and you'll see.

    Now, there's nothing wrong in asking on this forum but this kind of things
    were posted thousand times and that is why a few people reply. Also
    reading a good tutorial (traveler has very good ones for instance) may
    help you in learn how to set up a basic engine.
    Last suggestion is to use a sample provided in delphix package, modify
    it until you know exactly what happen by changing any var or value or
    param, trust me, it helps!


    Keep on studing
    <center>
    <br />Federico &quot;FNX&quot; Nisoli
    <br />Lead Programmer - FNX Games
    <br />http://www.fnxgames.com
    <br /><img src="http://www.fnxgames.com/imgs/banners/fnxban.gif">
    <br /></center>

  4. #4

    Problem with DXInput

    Thanks Traveler, the onmove code you suggested works :-) I still don't know why the dxdraw1.onkeydown event was not working but I'll keep on working and learning as FNX suggested :-)

    I've almost finished my own starfighter game and I went through some of the tutorials, the onkeydown event works in my starfighter game but there I don't have an image displayed over a bitmap so i suppose stuff works different when using code as above.

    I'm programming on a part-time basis and it gives me the stimulation I need....my full time job is very boring :-( I've only been programming for about 2 years and created a database app, which I sold to my employer. But Game programming seems much more interesting and challenging :-)

    Anyway thanks very much for your help :-)
    Wake up from the dream and live your life to the full

  5. #5

    Problem with DXInput

    Hi Wizard,
    you'd better avoid using OnKeyDown event because you're not sure
    which control on your game form is active. I had the same problem when
    i got started, now i only use DXInput.States. If you still want to use
    that event then place some DXDraw.Textout in your timer event and
    see which component has the focus (for example) or any info you might need during tests.
    <center>
    <br />Federico &quot;FNX&quot; Nisoli
    <br />Lead Programmer - FNX Games
    <br />http://www.fnxgames.com
    <br /><img src="http://www.fnxgames.com/imgs/banners/fnxban.gif">
    <br /></center>

  6. #6

    Problem with DXInput

    Hi FNX, thanks for your help and for the explanation
    Wake up from the dream and live your life to the full

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
  •