View Full Version : Problem with ScreenToClient()
Darhazer
09-02-2003, 07:52 PM
Hi
I wrote the "Towers of Hanoi" game, which you can download form
http://free.top.bg/darklight/hanoi.zip
In this game I use own drag-and-drop to allow moving the blocks together with Mouse cursor. I write my own function to convert the cursor coordinates to client ones. But now I tried to use the ScreenToClient method. When you start dragging the block, it begins to vibrate.
I use the onTimer() event
Is this bug or I'm using ScreenToClient wrong?
Alimonster
10-02-2003, 01:30 PM
I've tried to download it here at my work, with a super-fast connection. It's downloading from the site at 56 BYTES(!) a second. :pig: If you mail it to me (link should be at the bottom) then I'll upload it to my site tonight so that other people can have a look at it.
Alimonster
10-02-2003, 09:51 PM
I've uploaded the exe to my site: http://www.alistairkeys.co.uk/darhazer/hanoi.zip (214K). (Incidentally, Darhazer, if you have any other code/bits and bobs you want me to upload, just let me know.)
First question about the code: you're using a TTimer component to do stuff, you say. What's the interval? If it's less than 55 then *TTimer can't update that quickly!* It may sometimes, but a lot of the time it won't, because it's based on the Windows WM_TIMER message behind the scenes. This can cause jerkiness.
You might want to try a better timer (such as the ones from DelphiX, PowerDraw, or any of the other component sets -- maybe TRXTimer if you can find it somewhere).
That may or may not be the cause of the jerkiness - we'd need to see some code to know for sure. :cat:
Darhazer
13-02-2003, 06:55 PM
I know that 55 is the minimum interval and I use that interval
I use own code to convert screen koordinates to client:
I use object Mouse: TMouse
and I use
Left:=Mouse.CursorPos.X-Form1.Left-Form1.Width+Form1.ClientWidth;
Topy:=Mouse.CursorPos.Y-Form1.Top-Form1.Height+Form1.ClientHeight;
This code works perfect
But when i change it to
Left:=ScreenToClient(Mouse.CursorPos).X
Top:=ScreenToClient(Mouse.CursorPos).Y
It starts vibrate
Useless Hacker
15-02-2003, 09:25 PM
A wild stab in the dark, but try:
with ScreenToClient(Mouse.CursorPos) do begin
Left := X;
Top := Y;
end;
Failing that, try using the API ScreenToClient directly.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.