PDA

View Full Version : Delving into PowerDraw



fitzbean
10-04-2003, 06:22 PM
I must say, I'm very impressed with it so far. I'm going to convert what I can of a game I am making from using DelphiX to Powerdraw. I'm just doing the direct input now, and PowerDraw handles it with class! Of course, some questions are arising...

How do I clear the input buffer? I have a menu that the user can traverse with keys or joystick, but if the user holds down a key or joystick direction (or even just taps it), it flips thru a bunch of options at once; with DelphiX you could just do something like this:

DXInput1.States = DXInput.States - DXInput.States;

How can I accomplish the same thing with PowerDraw?

I tried PowerInput.Keys[DIK_UP] := False for instance, but it's a read-only property.

More questions to come for sure - and I will be writing some tips/howtos/tutorials along the way, since I've noticed a definate lack of such things for PowerDraw.

Thanks
Fitz

fitzbean
11-04-2003, 10:49 PM
Hmp, perhaps no one uses Powerdraw.. :)

LP
12-04-2003, 04:54 AM
Instead of Keys use on KeyPress and KeyRelease variables.

fitzbean
12-04-2003, 02:28 PM
Doh, silly me, how did I not see those? :) Thanks Lifepower.

Did I read somewhere that PowerDraw 3.0 is going to include a sprite engine component as well? It's the only reason I'm not switching completely over to it.

Another musing... is it posible to use the powerdraw font component on a DelphiX surface, and if so, how?

Useless Hacker
13-04-2003, 07:02 PM
So far as I know it is not possible to use a PowerDraw font component with a DelphiX surface. However, there is a similar component available for DelphiX, which is included with UnDelphiX (http://turbo.gamedev.net/undelphix.asp), though I can't find any reference to it on the site. I still have it if you can't get hold of it.

fitzbean
14-04-2003, 01:03 AM
is it TPowerFont ? Yeah I have it, and it's not bad actually, but it bares little resemblence to one included with PowerDraw. Thanks though.

fitzbean
30-04-2003, 09:36 PM
LifePower,

It would seem that my powerinput component isn't working unless I used the .Keys property - .KeyReleased and .KeyPressed don't seem to work. Any idea?

LP
01-05-2003, 02:33 AM
Greetz... remember to set DoKeyboard to true and use PowerInput.Update before you use any variables. If you still have problems, please give more information on how do you use PowerInput and maybe some code...

fitzbean
01-05-2003, 11:34 AM
hey Life,

the DOKeyboard is set to true, and I am polling and update right before I check the key... for instance..

Form1.PowerInput1.Update;
if (Form1.PowerInput1.KeyPressed[DIK_SPACE] = True) then ...

does not work, nor does

Form1.PowerInput1.Update;
if (Form1.PowerInput1.KeyReleased[DIK_SPACE] = True) then ...

but

Form1.PowerInput1.Update;
if (Form1.PowerInput1.Keys[DIK_SPACE] = True) then ...

does work..

but i'm looking for single key presses. I've done a work around which is rather ugly, but..

Form1.PowerInput1.Update;
if (Form1.PowerInput1.Keys[DIK_SPACE] = False) then SpaceLock = False;
if ((SpaceLock = false) AND (Form1.PowerInput1.Keys[DIK_SPACE] = True)) then SpaceLock := True;

that basically locks it after the first time it's pressed until it's released.

Any clue why those first 2 things arn't working though?

LP
02-05-2003, 01:09 AM
That's exactly how PowerDraw emulated KeyPress & KeyRelease events. It keeps two key buffers, the current and the previous one. If a key wasn't pressed in last buffer but is pressed in new one - KeyPressed will return true. The problem might occur if you call Update somewhere else in your code which will update the current buffer. You'd try to have only one Update call per frame or processing cycle.

fitzbean
03-05-2003, 07:38 AM
Hmm, i dont think that's the problem, i'm only calling it once. Donno, it just doesn't work as far as I can see.

Cataclysm
03-05-2003, 02:11 PM
Of course I don't know how your really code works, but we've also made some mistakes using the powerinput. I assume you're using both the PTimer.Onprocess and PTimer.OnRender events? Make sure you only call the Update-function in one of those functions. Preferably in the Onprocess event, because that way you can set the update speed to a constant rate (in the PowerTimer.FPS property) and don't have your character (or whatever you move with your Pinput-events) running like maniacs on higher framerates :wink:

Maybe an insight on our PTimer.OnProcess will help. Ours roughly works as follows:

- PInput.update; // Updates the input-events
- Handle the pressed keys
- do other stuff

This should work fine, the tricky part is in the part where we handle the keypressed events. For this procedure we use our own variable 'KeyPressed' that's set to true when the user presses a key for the first time. For example, when you want to catch a single space-bar key-event, it roughly works as follows:

if KeyPressed and (PInput.KeyReleased[DIK_SPACE]) then
Keypressed:=false; // The spacebar is released

if Pinput.keys[DIK_SPACE] and not Keypressed then
begin
KeyPressed:=true; // The spacebar key is pressed

// do something that should happen when you press the space-bar
end;

This is the way we handle our key-events using PowerInput, and it works for us... We also think it can be done in a more effecient way avoiding the use of an extra variable, but we haven't really figured out how.

I hope this helps for you. If anyone has any suggestions on doing this without using this extra variable, we hope hearing from you! :)

Coen