VXAce Drawing a line from character to events

Hello! I'm looking for a way to draw a line or multiple lines from the player character to different events, as part of a hint system for my current project. Basically what I want to have happen is, the player presses a 'hint' key, and it will briefly draw lines from the player character to specified points of interest on the map, like a thread. The way I'm wording it in my head is like, the player character's map X and Y are set as the 'parent', and I want to set different events' X and Y coordinates as the 'children'.

Additional optional things would be allowing the player character to move and have the lines dynamically adjust based on their positioning, as well as a way to draw them with some amount of visual 'slack' or 'weight' to them to really sell the 'thread' motif, but I imagine those would be much more difficult to implement.

Including some visual mock-ups to better illustrate what I mean:

entangled_Room_CbnF2StrgE.png
entangled_Room_CbnF2StrgE (1).png


Not sure how feasible or even possible any of this is in Ruby, but I figured I would ask regardless.
How about highlighting a tile path from the player to the target events? Line drawing would be ludicrously expensive in the Ruby version Ace uses, so you'd have to drop down to C or C++ and engage in dll shenanigans, or see if mkxp-z has any kind of line-drawing function built-in.

If highlighting the tiles in a path from the player to the target events is an acceptable compromise, you can do that by frankensteining some pathfinding script and the default "flash_data" function from the Tilemap class (check the helpfile).
Thanks for the suggestion! I figured drawing lines would be a bit resource intensive, yeah, lol. I'll take a look through the mkxp-z github to see if there's anything there that's close to what I'm looking for, thank you!

The tiles would be an acceptable compromise, if it wasn't for the line/thread concept being more of a stylistic choice that, a tile path wouldn't quite carry the same relevance or meaning as.
You can create a continuous loop that always resets the position of a Picture, using variables to check the player's position:
1764376191745.png


It's also possible to create several small pictures in sequence, but working with events might not be worthwhile.

RGSS has drawing methods, but it requires some programming knowledge. Here's an excellent tutorial; at least I found it quite simple:

Edit:
I thought this API had been lost, but someone posted it here, see if it's possible to work with it:
You can create a continuous loop that always resets the position of a Picture, using variables to check the player's position:
View attachment 353862

It's also possible to create several small pictures in sequence, but working with events might not be worthwhile.

RGSS has drawing methods, but it requires some programming knowledge. Here's an excellent tutorial; at least I found it quite simple:

Edit:
I thought this API had been lost, but someone posted it here, see if it's possible to work with it:
Oh, so like, a sort of "pulse", moving the image from the player to the event? It could work, though I imagine using a bunch of pictures in sequence to simulate a line would be a) cumbersome and b) resource-intensive. It's an idea though, so thank you!

I've already taken a look at that RGSS tutorial, and while I managed to replicate the line draw, I haven't been able to figure out how to draw it from point a to point b, just from one side of the window to the other. And it hasn't been updated in quite a while, which is unfortunate.

I'll take a look at Whiteflute's API though. Thank you!
In the tutorial, I couldn't find exactly how to draw the line. Could you show me how you did it so I can guide you on how to use game variables?
In the tutorial, I couldn't find exactly how to draw the line. Could you show me how you did it so I can guide you on how to use game variables?
How I did what? I haven't actually tested the method you described yet, I was more just speculating and thinking aloud.
This is what I understood from here:
and while I managed to replicate the line draw, I haven't been able to figure out how to draw it from point a to point b

The only way I found was by drawing pixel by pixel and using the algorithm to calculate the distance between two coordinates:
1764620583489.png


However, I don't know how to clear the image before starting to draw again. This is necessary because the native renderer itself deletes the Sprite Bitmap after 1.5 seconds.
This is what I understood from here:


The only way I found was by drawing pixel by pixel and using the algorithm to calculate the distance between two coordinates:
View attachment 354063

However, I don't know how to clear the image before starting to draw again. This is necessary because the native renderer itself deletes the Sprite Bitmap after 1.5 seconds.
Ah, yeah, that's not what I did, I meant that I followed the tutorial and only figured out how to draw the line from one side of the window to the other, I haven't actually figured out how to actually assign its start or end points to anything. So, you're further along in figuring it out than I am, lol.
The mistake was entirely mine... I'm sorry... I interpreted the word "figure" as "discover" in this context. In other words, I understood that based on the tutorial you managed to achieve something new, not that you simply replicated what was already shown. This is due to the way these words are used in my first language.

Regarding the previous problem I mentioned, it's extremely cumbersome to do this with events and scripts mixed together.
It would end up creating a Frankenstein monster and would be difficult to reuse. Therefore, I created a basic class to use variables:
Ruby:
=begin
List of common colors:
Empty: White
Red: Color.new(255,0,0)
Green: Color.new(0,255,0)
Blue: Color.new(0,0,255)
Yellow: Color.new(255,255,0)
Fuchsia: Color.new(255,0,255)
Aqua: Color.new(0,255,255)

How to use:
Create a global variable defining the area of ??the screen where he can draw.
In the example, I covered the entire screen:
@myline = PAINT.new(544, 416)
Do not repeat the previous command; now call the same variable using the line drawing function.

In it, you should insert the IDs of the game variables and, in the last parameter, put the color you prefer.

White line:
@myline.draw_line(3,4,5,6)

Line with custom color and transparency:
@myline.draw_line(3,4,5,6, Color.new(255,0,0,100))
=end

class PAINT
  def initialize(w, h, c=Color.new(255,255,255))
    @spr = Sprite.new()
    @spr.bitmap = Bitmap.new(w, h)
    @color = c
    #p "#{w},#{h}, #{c}"
  end

  def draw_line(x1, y1, x2, y2)
    @spr.bitmap.clear
    dx = $game_variables[x2] - $game_variables[x1]
    dy = $game_variables[y2] - $game_variables[y1]
    steps = [dx.abs, dy.abs].max
    (0..steps).each do |i|
      t = i.to_f / steps
      x = ($game_variables[x1] + dx * t).round
      y = ($game_variables[y1] + dy * t).round
      @spr.bitmap.set_pixel(x, y, @color)
    end
    #p "#{dx}, #{dy}, #{@color}"
  end
end

Example:
PAINTClass-Example.png


I only added that minimum Wait time to ensure it wouldn't cause lag due to too many events on the screen.

This script, because it uses global variables, is limited to only one line at a time. I understand almost nothing about RGSS, but I assume that if I created an array, I could insert as many lines as the memory or processor could handle.

The problem is that I would need to create other functions, such as deleting a specific line.

So in this case you can create an event-based alternation of the same variables to select other events so quickly that the player wouldn't even notice it's the same line, but it would probably look like those NES games from the 80s where the graphics glitched to save memory.
The mistake was entirely mine... I'm sorry... I interpreted the word "figure" as "discover" in this context. In other words, I understood that based on the tutorial you managed to achieve something new, not that you simply replicated what was already shown. This is due to the way these words are used in my first language.

Regarding the previous problem I mentioned, it's extremely cumbersome to do this with events and scripts mixed together.
It would end up creating a Frankenstein monster and would be difficult to reuse. Therefore, I created a basic class to use variables:
Ruby:
=begin
List of common colors:
Empty: White
Red: Color.new(255,0,0)
Green: Color.new(0,255,0)
Blue: Color.new(0,0,255)
Yellow: Color.new(255,255,0)
Fuchsia: Color.new(255,0,255)
Aqua: Color.new(0,255,255)

How to use:
Create a global variable defining the area of ??the screen where he can draw.
In the example, I covered the entire screen:
@myline = PAINT.new(544, 416)
Do not repeat the previous command; now call the same variable using the line drawing function.

In it, you should insert the IDs of the game variables and, in the last parameter, put the color you prefer.

White line:
@myline.draw_line(3,4,5,6)

Line with custom color and transparency:
@myline.draw_line(3,4,5,6, Color.new(255,0,0,100))
=end

class PAINT
  def initialize(w, h, c=Color.new(255,255,255))
    @spr = Sprite.new()
    @spr.bitmap = Bitmap.new(w, h)
    @color = c
    #p "#{w},#{h}, #{c}"
  end

  # Desenha uma linha de (x1, y1) até (x2, y2) com determinada cor
  def draw_line(x1, y1, x2, y2)
    @spr.bitmap.clear
    dx = $game_variables[x2] - $game_variables[x1]
    dy = $game_variables[y2] - $game_variables[y1]
    steps = [dx.abs, dy.abs].max
    (0..steps).each do |i|
      t = i.to_f / steps
      x = ($game_variables[x1] + dx * t).round
      y = ($game_variables[y1] + dy * t).round
      @spr.bitmap.set_pixel(x, y, @color)
    end
    #p "#{dx}, #{dy}, #{@color}"
  end
end

Example:
View attachment 354073

I only added that minimum Wait time to ensure it wouldn't cause lag due to too many events on the screen.

This script, because it uses global variables, is limited to only one line at a time. I understand almost nothing about RGSS, but I assume that if I created an array, I could insert as many lines as the memory or processor could handle.

The problem is that I would need to create other functions, such as deleting a specific line.

So in this case you can create an event-based alternation of the same variables to select other events so quickly that the player wouldn't even notice it's the same line, but it would probably look like those NES games from the 80s where the graphics glitched to save memory.
No worries at all! 😀 Thank you for writing the script, it works really well, I'll likely be testing it out to see the extent to which it can be pushed but it's almost exactly what I was looking for! Thank you!
You can do it like this:
1764639072129.png



The problem is that you'll have to wait for the lines to disappear automatically when you no longer need them.
You can do it like this:
View attachment 354076


The problem is that you'll have to wait for the lines to disappear automatically when you no longer need them.
Yep, I learned those methods on my own through testing, though I haven't figured out how to actually get rid of them yet, aside from leaving the map entirely.

EDIT: After a bit more testing, turns out turning it off is fairly simple, basically the parallel processing needs to be in an event page that checks if a switch is on, and turning the switch off will also erase the lines. I'm not sure if this may cause a memory leak issue or anything, just since there's no actual code to erase the bitmap, but I haven't run into any issues with this method as of yet.
@DerVVulfman showed me this topic, and it has all the useful tools for creating drawings on the screen:
I couldn't analyze everything, but because I'm using native methods (Lib), the processing is almost instantaneous compared to what I did.

The script I was working on creates points between map events without needing a parallel process, but because it's pixel-by-pixel, I limited it to 8 lines, which can still slow down the game due to the distance.
But if you want to check it out:

Original thread: https://forums.rpgmakerweb.com/threads/drawing-a-line-from-character-to-events.181219/