Results 1 to 10 of 10

Thread: Writting map editor from scratch tutorial (With Allegro)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Well with this being tilemap editor (think more RPG Maker than, say, The Games Factory) I would have most difficulties with snapping tiles to grid and showing grid cursor.

    How do I determine which "tile" user clicked as in snapping mouse to grid of certain size?
    How do I make showing "tile cursor" (small square of size according to tile's size) in proper place instead of always under mouse?

  2. #2
    Quote Originally Posted by Darkhog View Post
    How do I determine which "tile" user clicked as in snapping mouse to grid of certain size?
    Easy!
    GridXPosition := Mouse.X div GridCellWidth;
    And if your map is bigger than what you can render on the screen you have to take into acount your viewing position. So if your viewing position on X axis is at coordinates 145 the forumla would look like this:
    GridXPosition := (Mouse.X + ViewpoirtX) div GridCellWidth;

    Quote Originally Posted by Darkhog View Post
    How do I make showing "tile cursor" (small square of size according to tile's size) in proper place instead of always under mouse?
    Once you have grid position you can simply multiply it by grid size like this.
    SelectorSprite.X := GridXPosition * GridCellWidth;
    And if your map is larger than the screen
    SelectorSprite.X := (GridXPosition * GridCellWidth) - ViewportX;

  3. #3
    And if map's viewport is moved away from 0,0 (top-left corner) and occupy only part of screen (after all tile palette should go somewhere), equation would be:
    GridXPosition := OffsetX + ((Mouse.X + ViewpoirtX) div GridCellWidth);

    am I correct?

  4. #4
    No, you don't need 2 offset variables, ViewPointX already does that. If you wanted to also draw a tool panel (instead of using IDE components) on the left side, and always draw the entire map more to right, then you would use OffsetX. But then it would be
    GridXPosition := ((Mouse.X + ViewPointX - ToolPanelWidth) div GridCellWidth);
    Last edited by User137; 13-06-2013 at 04:30 PM.

  5. #5
    Well, allegro.pas don't mix well with Lazarus' forms and allegro gui library looks terrible (just look at ASEPRITE for example).

  6. #6
    Quote Originally Posted by Darkhog View Post
    Well, allegro.pas don't mix well with Lazarus' forms
    None of the game graphical engines doesn't mix wel with either VCL or LCL. The main reason for this is the technology that is used for each learegly differs from others.
    Most game graphical libraries use either DirectX or OpenGL as their main technology.
    VCL and LCL use default system GUI which is quite slow in comparison to DirectX or OpenGL. Also the biggest problem of default OS GUI is that it laregly depends on system messages which can also be quite slow. That is why it is much better to create your own internal game messaging system rather than using OS messaging system.

  7. #7
    I'm experimenting with forms based ui along with opengl scene rendering, so far so good

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
  •