Archived

This topic is now archived and is closed to further replies.

First Time Isometric Tiling Engine Problem...

This topic is 5247 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a 22*22 "arena" with Civ II sytle control with the mouse. How can I *accurately* detect which tile has been clicked on? My solution is "somewhat jumbled" and is only 90% accurate. You could just ignore my code and point me to an article/website, any help will be gratefully recieved. Be nice, this is my first try! It does work. Cheers, Nop_90h Here is the delphi code: - ++++++++++++++++++++++++++ function TForm1.CalcYcoord(X,Y:Integer):Integer; var StartY:Integer; begin StartY := (DX.SurfaceHeight div 2); Result := StartY + (TileImages.Items.Items[0].Height*Y - TileImages.Items.Items[0].Height*X) div 2; end; function TForm1.CalcXcoord(X,Y:Integer):Integer; var StartX:Integer; begin StartX := 3 - TileImages.Items.Items[0].Width; Result := StartX + (TileImages.Items.Items[0].Width*X + TileImages.Items.Items[0].Width *Y) div 2; end; procedure TForm1.DXMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var XTile,YTile:Double; SuccessfulMove: Boolean; Temp: TCharacter; Str: String[32]; begin SuccessfulMove := False; YTile := (Y - (DX.SurfaceHeight div 2)- (TileImages.Items.Items[0].Height div 2)) / TileImages.Items.Items[0].Height; XTile := (X - (3-TileImages.Items.Items[0].Width)) / TileImages.Items.Items[0].Width; X := Trunc(XTile) - Trunc(YTile); Y := Trunc(XTile) + Trunc(YTile); If (Abs(YTile - Trunc(YTile)) < 0.70 ) AND (Abs(YTile - Trunc(YTile)) > 0.30 ) Then begin If (Abs(XTile - Trunc(XTile)) > 0.70 ) Then begin Temp.X := X; Temp.Y := Y; If YTile > 0 Then Temp.Y := Temp.Y + 1 else Temp.X := Temp.X + 1; SuccessfulMove := True; end else If (Abs(XTile - Trunc(XTile)) < 0.30 ) Then begin Temp.X := X; Temp.Y := Y; If YTile > 0 Then Temp.X := Temp.X - 1 else Temp.Y := Temp.Y - 1; SuccessfulMove := True; end; end else IF (Abs(XTile - Trunc(XTile)) < 0.70 ) AND (Abs(XTile - Trunc(XTile)) > 0.30 ) Then begin Temp.X := X; Temp.Y := Y; SuccessfulMove := True; end;

Share this post


Link to post
Share on other sites
Cheers for that, missed it :S. Funnily enough my current method (as far as I can see) pretty similar to that, except for step 3 which was a stroke of genius! Maybe I played on CivII too much when I was about 11 and something rubbed off? Such a *classic* game...


Cheers, Nop_90h

Share this post


Link to post
Share on other sites