ReadKey crash's application - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

ReadKey crash's application

maddog321maddog321 Posts: 4Member
I'm trying to make a sidescroller sort of thing, its the first application/game I'm attempting to make. I've got ReadKey to work when making a program, but i can't get it to move this object.

[code]implementation

{$R *.lfm}

{ TfrmMap }

procedure TfrmMap.Timer1Timer(Sender: TObject);
begin
c:=readkey;
if c=#0 then
begin
c:=readkey;
case c of
#75 : shpPlayer.left:= shpPlayer.left - 1;
#77 : shpPlayer.left:= shpPlayer.left + 1;
end;
end;

end; [/code]

Could anyone help please? Thanks

Comments

  • ActorActor Posts: 438Member
    : I'm trying to make a sidescroller sort of thing, its the first
    : application/game I'm attempting to make. I've got ReadKey to work
    : when making a program, but i can't get it to move this object.
    :
    : [code]: implementation
    :
    : {$R *.lfm}
    :
    : { TfrmMap }
    :
    : procedure TfrmMap.Timer1Timer(Sender: TObject);
    : begin
    : c:=readkey;
    : if c=#0 then
    : begin
    : c:=readkey;
    : case c of
    : #75 : shpPlayer.left:= shpPlayer.left - 1;
    : #77 : shpPlayer.left:= shpPlayer.left + 1;
    : end;
    : end;
    :
    : end; [/code]:
    :
    : Could anyone help please? Thanks
    :
    Why do you believe it's readkey that's crashing the program?

  • maddog321maddog321 Posts: 4Member
    It seemed logical, as I can get the ball to move left and right, but it only starts crashing when I turn it into a ReadKey to let me use the arrows to move

    It crash's when I click on the window, as too tab into it.

    I've been trying to work out a way to do it on the actual object, not the timer as that could be it as well, but I'm not that adept at it all yet.

    Any help is appreciated
  • _Atex__Atex_ Posts: 163Member
    Use WinAPI's to read the keyboard instead of "readkey"'s. Timers should be running independently from input related tasks BTW.
  • maddog321maddog321 Posts: 4Member
    without trying to sound like a retard, what exactly is a WINAPI and how do I start using them?
Sign In or Register to comment.