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

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.