Results 1 to 6 of 6

Thread: Need some help with map editor (drawing cursor rects).

  1. #1

    Need some help with map editor (drawing cursor rects).

    I am trying to calculate and draw rectangles under the cursor at the appropriate size (as the map is 1024x768 and tiles are 32x32).

    I created myself a little record TMouse with x and y as integer which I update in my TPanel's (where I output Asphyre drawing routines) OnMouseMove event.

    I then have another basic record with X, Y for drawing the rectangle which I try to calculate in the processing event (I may put this in the OnMouseMove event seen as I don't need to calculate until the mouse moves really).

    So far I do it like this:

    [pascal]
    if (sMouse.x > 0) AND
    (sMouse.x <32>= 0) AND
    (sMouse.y <32> 32) AND
    (sMouse.x <64>= 0) AND
    (sMouse.y <32> 64) AND
    (sMouse.x <96>= 0) AND
    (sMouse.y <= 32) then
    begin
    sRect.x := 64;
    sRect.y := 0;
    end;
    [/pascal]

    This obviously only covers 3 tiles.... out of the possible 768 tiles, it would be a rather large conditional branch lol.

    I am constantly trying to think of ideas to shorten this up, so by the time somebody replies I may have figured out a solution, but any help is definitely and greatly appreciated.

    I'm sure I will have plenty more to come haha![/code]

  2. #2

    Need some help with map editor (drawing cursor rects).

    Wow maybe the site is a bit broken... it just will note take all of my code in either the code or pascal tags.

    I wonder if it will take it straight:

    if (sMouse.x > 0) AND
    (sMouse.x <32>= 0) AND
    (sMouse.y <32> 32) AND
    (sMouse.x <64>= 0) AND
    (sMouse.y <32> 64) AND
    (sMouse.x <96>= 0) AND
    (sMouse.y <= 32) then
    begin
    sRect.x := 64;
    sRect.y := 0;
    end;


    What the hell...... lol, umm hmm can attachments be done I wonder sheesh....

  3. #3

    Need some help with map editor (drawing cursor rects).

    Hmm, if I understand you correctly than you are looking for something like this:

    [pascal]pos.x := sMouse.x div 32;
    pos.y := sMouse.y div 32;

    drawRect ( pos.x*32, pos.y*32, (pos.x*32)+32, (pos.y*32)+32)
    [/pascal]

  4. #4

    Need some help with map editor (drawing cursor rects).

    there are of course several solutions to this.

    personally, in one of my last projects i created a class 'ttile' and stored the coordinates in it (very useful if you haven't rects as tiles) and with this very helpful function i tested if my mouse was in a tile:
    http://swissdelphicenter.ch/de/showcode.php?id=1778

    so the used code lookes something like this:
    Code:
    point.x&#58;= mousex;
    point.y&#58;= mousey;
    
    for i&#58;= low&#40;tiles&#41; to high&#40;tiles&#41; do begin
      if PtInRgn&#40;tiles&#91;i&#93;.poly, point&#41; then begin
        //tile&#91;i&#93; is hovered
        //do the hovering thing
        break;
      end;
    end;
    i'm quite sure it's not the fastest way to do that but it's quite simple and effective.

  5. #5

    Need some help with map editor (drawing cursor rects).

    Holy crap.... to think it's that simple.....

    I adjusted a bit and placed most of it in the OnMouseMove event like so:

    [pascal]
    sRect.x := (x Div 32) * 32;
    sRect.y := (y Div 32) * 32;
    [/pascal]

    And yeah it works great now. I really must learn these little math functions, very handy.

    It just leaves me with one issue I think, how to actually know the tile I am on (some sort of reference, like a numbering of 1 to 768 or something like that), for the purpose of knowing where the tiles are being placed (so internal records can be modified on the fly).

    Well I will have a muck about and see what I can do about it anyway. Thank you very much for the assistance so far!!!

  6. #6

    Need some help with map editor (drawing cursor rects).

    Just saw your post there elf.

    Yes I see what you mean there, that would effectively knock both of my issues out in one foul swoop.

    The thing is, my tTile record does not actually have any X or Y information, the engine automatically calculates (with a basic function) the X and Y of each tile for my 4 layers at this stage, so all the map has specified (well what I have planned at least) is the tile number.

    Well I could just as easily push this function over and have it setup on run so it's all ready to go.

    But what kind of function is there, or will I have to create to check if the mouse X and Y is within the set boundaries (PtInRgn isn't a real delphi function is it? lol).


    EDIT: I think I have the right idea (just testing something out).

    You guys are awesome, I think I have it all sorted out now:

    [pascal]
    rocedure TfrmMain.mapMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    var
    i: Integer;
    begin

    for i := LOW(layer1) to HIGH(layer1) do
    begin
    if (x >= layer1[i].x) AND
    (x <layer1>= layer1[i].y) AND
    (y <= layer1[i].y +32) then
    begin
    sRect.x := layer1[i].x;
    sRect.y := layer1[i].y;
    sRect.tile := i;
    exit;
    end;
    end;

    end;
    [/pascal]

    Ok so some of the code still seems to get garbled when I post, but you get the idea, it's mostly completely shown.

    Hopefully the above code all shows properly, it's working great now ^_^.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •