[QUESTION] Having a hard time solving this simple problem:

N

Nuno

Guest
Context

Hey! I'm new in the GM community :D. I joined today and installed GM some days ago.
I have 0 experience with any form of coding... but I am trying my best, although struggling, to learn GML, from videos and online content kindly shared from you and the GM Team through the Wiki, forums, etc... I'm familiar with some concepts already and if you can/are willing to help me I would like to ask you to not hold back in concepts or expressions, if i don't understand something like a function, it's my problem and I'll research about it before asking what it means/does. Thank you for your attention and let me apologize in advance for any linguistic mistake I may make.


Targeted concept

There's a game called Two Dots on the Google Pay Store, that consists in linking dots of the same color to make them disappear. Here's a GIF illustrating:


Problem :bash:


I want to make the exact same concept. Pressing an object and drag from it a line that you can link to other object, with the addition of making the line relatively thick with a glow effect. Attention: it is not clear from the animation above, however you don't have to connect the dots for the line to appear, by simply pressing a dot and dragging your finger away from it, a line becomes visible, connecting your finger location to the dot you've initially pressed and then locking up between two dots, as your finger location meets the second dot. Obviously I'm not looking for someone to send me the code for this, I just need some help conceptualizing how I could code this because i honestly have no clue and couldn't find anything related to this online either...

Hypothesis


  • Using the draw_line(Obj_x,Obj_y,Cursor_x,Cursor_y) in a step event with the initial object coordinates and my cursor/finger coordinates to make the game continuously draw a line? The problem with this hypothesis is the fact that i can't make the line thicker nor glowing :(
  • Since I would like to make a thick glowing line like the ones in the animation, perhaps i could make a line sprite with the thickness, glowing effect and maximum size I intend to use in-game and make it be pulled from the initial object, somehow camouflaging part of the actual sprite. I did an illustration to clarify this hypothesis:

Thank you so much for your time and attention! :D

 

Tthecreator

Your Creator!
What I would recommend is getting the mechanics down first.
What I would do is have every dot be a different object, then detect if I'm swiping over an object to create a line,
When a line has been created use global variables and a instance_position function to get if there's an instance at a certain place.
When that is true, let the first object connect a line from the first object to the second object, and make the second object the "selection" object which should draw the line from the object to your finger until a new object has come into place.

As for the glow, a sprite would work, but if you'd like to do this in code you can draw multiple lines with different alpha's over each other.
 
N

Nuno

Guest
What I would recommend is getting the mechanics down first.
What I would do is have every dot be a different object, then detect if I'm swiping over an object to create a line,
When a line has been created use global variables and a instance_position function to get if there's an instance at a certain place.
When that is true, let the first object connect a line from the first object to the second object, and make the second object the "selection" object which should draw the line from the object to your finger until a new object has come into place.

As for the glow, a sprite would work, but if you'd like to do this in code you can draw multiple lines with different alpha's over each other.
Hey! Thanks for answering :)

My problem are the mechanics exactly, i need help conceptualizing the problem, the coding is not core of the problem unfortunately...
The suggestion about multiple lines on top of each other with different alpha channels won't solve the problem the way i would like to, although it is interesting and creative!

Do you know if it is possible to execute my second hypothesis? (If it is possible to hide a sprite partially, for example?)
 
N

Nuno

Guest
you could learn from this http://www.yoyogames.com/news/ide/386 then look up draw_line functions
Thank you for answering! I'll give it a look and finish this reply once I've done that :D


*EDIT* Well this definitely approaches concepts that will be useful to create a game like the one I've mentioned, however it doesn't really help me with the problem about creating the lines sadly :(
 
Last edited by a moderator:

Tthecreator

Your Creator!
If you have a straight line, in which you can specify positions, you shouldn't need to use any dirty hiding techniques.
You can try use 2 lines separate lines instead.
Another few dirty hiding tricks that can be:
-using shaders
-doing some surface magic
-doing some blend mode magic.

But I'd still recommend using 2 lines.
I'm sorry, but I don't completely understand when exactly it is you want to hide the lines...
 
N

Nuno

Guest
If you have a straight line, in which you can specify positions, you shouldn't need to use any dirty hiding techniques.
You can try use 2 lines separate lines instead.
Another few dirty hiding tricks that can be:
-using shaders
-doing some surface magic
-doing some blend mode magic.

But I'd still recommend using 2 lines.
I'm sorry, but I don't completely understand when exactly it is you want to hide the lines...
Hi! Thanks for replying man :)

I'm not familiar with those concepts (shaders,surface,blend mode) I'll investigate a bit about them, thank you.

My point was:
  • You touch a dot and drag your finger, say, 200 pixels in a 45º direction from the original dot. The intended result was a line going in diagonal, from the dot to the location of your finger.
  • Now suppose I drag the finger further apart from that dot, like another 200 pixels in the same direction (being your finger 400 pixels away from the dot this way now).
  • The problem is: a single line changes size as you move the finger away from the dot, the line's size is a variable. So if i make the line a sprite, i can resize the sprite's size to match the distance from the dot to the finger, but then I start messing with the line's sprite resolution (since it has a glow effect).
  • The solution: make a really big line sprite and only show 200 pixels of it, as you move the finger apart you let the game show more of the line's sprite, giving this way the idea the line is increasing in size, when it actually is just being revealed.
I hope I wasn't that confusing :(
 

Tthecreator

Your Creator!
No, you have a line, which should have the same texture at every position.
This means that your sprite only need to be 1 pixel wide and maybe 20 pixels orso tall.
Then you want draw that sprite, stretched in it's width, but not in it's height.
Maybe use draw_sprite_pos? Otherwise you can try primitives.
Or just use draw_sprite_ext, and rotate the sprite, and scale using scalex. Leave scaley.

I hope this can help you.
 
N

Nuno

Guest
No, you have a line, which should have the same texture at every position.
This means that your sprite only need to be 1 pixel wide and maybe 20 pixels orso tall.
Then you want draw that sprite, stretched in it's width, but not in it's height.
Maybe use draw_sprite_pos? Otherwise you can try primitives.
Or just use draw_sprite_ext, and rotate the sprite, and scale using scalex. Leave scaley.

I hope this can help you.
Ok, I understood what you suggested, are you sure it won't mess with the resolution?
I have no idea what you mean by primitives or what is scalex, but I'll go give it a look.
Do you know if I can use shaders to create a glow effect? (Not asking how, only if it is possible/works better than actually having a sprite simulating the glow already)

Thank you for your time and patience, I will probably follow your suggestion if I can't find anything else. :D
 

Tthecreator

Your Creator!
No' it shouldn't mess up the resolution.
With scalex I mean the argument scalex inside: draw_sprite_ext( sprite, subimg, x, y, xscale, yscale, rot, colour, alpha );
what you need to do is make a one wide sprite.
Then calculate the value of xscale which should be equal to the length of your line. leave yscale to 0.
Then calculate the rotation of your line by using "darctan2()" and fill in the y difference of your line and the x difference of your line.

You could definitely use shaders for your glow effect, but it might be unnecessary because your sprite is static, making something calculate this over and over again would be bad programming practice. Besides, not every device has compatibility (especially mobile devices).
 
N

Nuno

Guest
No' it shouldn't mess up the resolution.
With scalex I mean the argument scalex inside: draw_sprite_ext( sprite, subimg, x, y, xscale, yscale, rot, colour, alpha );
what you need to do is make a one wide sprite.
Then calculate the value of xscale which should be equal to the length of your line. leave yscale to 0.
Then calculate the rotation of your line by using "darctan2()" and fill in the y difference of your line and the x difference of your line.

You could definitely use shaders for your glow effect, but it might be unnecessary because your sprite is static, making something calculate this over and over again would be bad programming practice. Besides, not every device has compatibility (especially mobile devices).
Ok makes sense, I'm going to read a little about it to become comfortable using it and put it to practice. As for the shaders, well that's a pity, just when i was starting to understand them... Anyway, I can't thank you enough for your help! :)

I'm also reading about primitives, which you've mentioned, and they will be super useful for my project as well!
 
Top