Autor Beitrag
pigfacejoe
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 332
Erhaltene Danke: 1

Win 10, Ubuntu
Delphi,Javascript, PHP, Java, Python
BeitragVerfasst: Di 24.10.06 12:32 
Hallo ,
Nachdem ich im Forum gesucht habe , wie ich es hinbekomme nachdem Tasten gedrückt werden etwas zu tun, habe ich viel gefunden, allerdings sind die Lösungen nicht geeignet für mein Spiel:
Also wenn der Benutzer beispielsweise auf a drückt soll sich das Männchen nach links bewegen:
OnKeyPress und dann Prüfen ob key=#97 is zu langsam, das muss flüssig und schnell gehen .
Eine andere Lösung war while true do... das ist aber schlecht, da es dazu führ das alles hängt.
Jetzt Meine Frage: Wie kann ich , ohne die CPU stark auszulasten mein Männchen nach Tastendruck flüssig bewegen?
Vielen Dank!
Cu PigfaceJoe
Phantom1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 390



BeitragVerfasst: Di 24.10.06 13:11 
Dein Problem ist warscheinlich die Anschlagverzögerung, das kann man einfach umgehen:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
    Keys: Array[0..255] of Boolean;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  Keys[Key]:=True;
end;

procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  Keys[Key]:=False;
end;

end.


Jetzt kannst du die Tasten einfach abfragen:
ausblenden Delphi-Quelltext
1:
2:
if Keys[VK_LEFT] then
  // ..
pigfacejoe Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 332
Erhaltene Danke: 1

Win 10, Ubuntu
Delphi,Javascript, PHP, Java, Python
BeitragVerfasst: Di 24.10.06 13:27 
Vielen Herzlichen Dank!!