how to implement quest pointer guide in godot 3? [closed] - godot

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed last year.
The community is reviewing whether to reopen this question as of last year.
Improve this question
I am making a 2d platformer.(using gdscript)
I have been trying to make a guide arrow that shows you where to go and have been failing. I far as I can see there is no godot tutorial for this yet.
I have however managed to find a unity tutorial but have been having a hard time converting the instructions to godot.
https://youtu.be/dHzeHh-3bp4
Thanks in advance :)

I'll assume the indicator is a Sprite with whatever icon you want to show.
By the way, you are going to need a reference to the Camera2D. Unlike in 3D where you can ask Godot for the current Camera, you will have to handle references to the current Camera2D yourself.
I'll assume you already have the reference to the Camera2D (perhaps you have the code in the Camera2D script) and the reference to the indicator Sprite (which is another possible place to have the code).
I'll also assume you don't have a rotated Camera2D.
First we need the center of the screen:
var center := camera.get_camera_screen_center()
Then we can get the vector to the position we want:
var vec := target - center
Where target is the position in global coordinates you want to point to. By the way, if vec is Vector2.ZERO, then the target at the center of the screen.
Let us clamp it by the size of the Viewport. We are going to use half the size since we are measuring from the center of the screen. I'll also add a margin, I'll come back to that, for now, assume margin = Vector2.ZERO.
var helf_size := (get_viewport().size - margin) * 0.5
var clamped_vec := Vector2 (
clamp(vec.x, -half_size.x, half_size.x),
clamp(vec.y, -half_size.y, half_size.x)
)
If those are equal, it means the target is on the screen (it didn't need to be clamped):
if clamped_vec == vec:
# target on screen
pass
else:
# target out of screen
pass
Now, to place the indicator we need two things: a rotation and a position, correct?
The rotation is easy. It is the angle of our vec:
sprite.global_rotation = vec.angle()
And for the position, well, it will be our clamped_vec except we need to place the indicator. So we need to add a... Margin! Aha! So, adjust the margin to the size of the indicator you have, and clampled_vec will give us the position, we just need to add center back:
sprite.global_position = clamped_vec + center
And that should do it.

Related

I want to make image sticky in Android Xamarin layout for native App.I am using axml for layout rendering [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I want to make the image sticky in the layout right end corner in axml.
EDIT
I Realize now OP needs Xamarin Android. This was written for Xamarin Forms. :)
Check this question as this is a possible duplicate:
Set the absolute position of a view
--
Try an absolute layout.
<AbsoluteLayout>
<!--If You have other content, like a stacklayout, put it before the image (like below)-->
<StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1">
<!--Content Here -->
</StackLayout
<Image Source="YOUR IMAGE SOURCE" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="1,1,0.2,0.2" />
</AbsoluteLayout>
Let me explain how absolute layout kinda works.
So an absolute layout allows you to place things on top of each other (Or just set a static position).
Absolute Layout Bounds work as follows:
(position X start, position Y start, Width, Height).
So by typing (0,0,1,1), I'm telling it to start at 0,0, and the width and height should be the same size as the window. If I were to do (0.5, 0.5, 0.2, 0.2), then I'd be telling it to start half way down and half way from the left, and make the object 0.2 of the total window size.
Ref Documentation:
https://developer.xamarin.com/guides/xamarin-forms/user-interface/layouts/absolute-layout/
Hope this helps

Anyone know if its possible draw to erase the picture on the top?

Scratch allows selection of the color using the set pen color. Does anyone know if its possible to program to set the color to transparent so that what ever is drawn can effectively be erased? What would the color number be for that?
Update
The idea was to cover a picture (background) with a colour drawn over the top. Now give the player a little creature that erases the colour on top, they have a certain amount of moves or time to guess what the picture is. The less moves/time they use the more points the player will be awarded.
But the problem seems to be that in the paint a sprite part of scratch erase is an option, but not in the pen programming.
If I cant solve it using erase apprach, my alternative is to make a lot of sprites covering the picture and hide them when the creature touches them. But it seems less fun for the player as the uncovered patterns will be more predictable.
Unfortunately, this isn't really possible. If you have a backdrop that's all one color, you could set the pen color to be the same as the backdrop and color over what you already have (giving the illusion of erasing), but other than that there really isn't a good way.
Your only other option is to use the clear block and then re-draw everything except the piece you want to erase.
If you want to give more context about your specific project, I might be able to help you work out a solution (I've done quite a lot with pen blocks over the years).
Like PullJosh said, it isn't really possible but you can make a sprite called Cover and make it a circle of any color you want. Then, it can clone it's sprite over the sprite you want to hide. Then you can attach a script to the clones:
https://i.stack.imgur.com/S6h4c.png (ctrl + click)

'Slider Control' kind of controls in Cocos2d help

I am making a game in Cocos2d. I want there to be a dotted line that follows the user's finger. I want the line to be straight. The problem is, how do I check to see how many 'dots' will fit in the distance between the ball and where the user is touching? And make it follow in a STRAIGHT line between the ball's position and the finger's position? So here's a re-clarification:
The ball sits still on the left side of the screen, and is halfway up the screen. The user drags their finger, and a dotted line is drawn between the ball's position and the touch's position. I have a 'dot' image to be used, and I would like it to be used as the dots in the line. So it will have to recreate the sprite as many times as it will fit in the area between the two points. Please tell me if you want me to clarify further, Thanks!!
I would make a CCNode object called dottedLine or something.
The dot image would be a sprite that gets added as a child of the node (multiple times).
I would work out the path from ball to finger touch using Trigonometry/Pythagoras theorem.
For creating the line:
From point 0, the ball, i would add 15-20 pixels towards the touch point along the path, and place a dot, I'd repeat this until I reached the end of the line.
Every dot that was placed I would increment a counter, and set that number as the integer tag of that sprite for use in an update method.
Every time the cctouchesmoved method gets called, i'd call an update method on the dottedLine object.
This method would check the distance between the ball and touch point, divide it by the number of dots currently children of the object and remove or add any that are needed. Recreating the sprites every time you move your finger would be messy and wasteful, so reusing your dots and just setting them new positions as the path between ball and touch point changes would probably be best.
I'm not going to provide you code, i think i've explained more than enough of the working out for you to do some googling and work this out.

How to cut a hole in an SVG rectangle [duplicate]

This question already has answers here:
How can I cut one shape inside another?
(4 answers)
Closed 6 years ago.
So basically as my title says, I want to "cut a hole" in a rect element.
I have two rect elements, one on top of the other. The one on the bottom has a fill colour of white, and the one on the top has a fill colour of grey.
What I want to do is cut a triangle out of the top rect element so that the rect element below shows through.
This svg element is going to be used as an audio button for a media player on a page. In other words, you'll be able to click (or drag) your mouse left/right and the change in audio level will be represented by a change in the width of the rect element on the bottom, which shows through the triangle cut out of the top rect element.
I hope that's not too confusing. :P
Here is a quick mockup of what it should look like: http://forboden.com/coding/s1.png
Here is my code: http://forboden.com/coding/svgClipTest.html
Where am I going wrong here?
You should be able to use the fill-rule: evenodd(default) property to achieve this effect, if you want to prevent the fill of the rectangle from painting where the circle is. See this example from the SVG specification:
The key point is draw outer shape and inner shapes(holes) in different direction (clockwise vs anti-clockwise).
Draw the outer shape clockwise and draw the inner(holes) shapes anti-clockwise.
Or conversely, draw the outer shape(holes) anti-clockwise and draw the inner shapes clockwise.
Concat the path datas of outer shape and inner shapes(holes).
You can cut more holes by concat more hole path data.
This image explain how to cut a hole:
I see that you have it solved already, just wanted to add that if you want something more advanced then it's often quite easy to use a <mask>, see http://dev.w3.org/SVG/profiles/1.1F2/test/svg/masking-path-11-b.svg for example.
However, if you can avoid masking and clipping (e.g by just drawing things on top) that usually leads to better performance/user-experience.
Easiest way is to use <path> with the hole, and set pointer-events to none so events can pass through to the <rect> under. Of course there are many other ways to handle events such as wrapping them with a <g> and handling events on it.
You don't need to limit yourself to the basic shapes and use complicated clipping. Make things felxible enough so you can copy&paste path data generated by tools like inkscape.

LaTeX \includegraphics and textline

Ok, I am beat. I tried a few things but I am unable to make this happen. I need some help now.
I want to be able to have some text and picture side by side (only one line, thus no need for wrapping or other fun. The picture is small enough to fit in a text line):
This is a text <temp.jpg placed center to the textline>
Problem is, when I use
This is a text \includegraphics{temp.jpg}
the pictures baseline is alligned with the text baseline. I want the picture (vertical) center to be aligned with the text baseline. How can I make this possible?
This is a text $\vcenter{\hbox{\includegraphics{temp.jpg}}}$
It sounds like you want \raisebox (see the raisebox section of the LaTeX wikibook), with a negative argument. Use dimensions ex (the notional height of an 'x' in the current font) or \baselineskip (the size between text baselines) as your units.
If you want to do more complicated things, such as move the graphics box down by half its height, you can, but it gets fiddly. If the graphic size isn't unpredictable, you're probably better off tuning this by hand anyway.
In my opinion, most simple answer \raisebox{-0.5\totalheight}{<your graphic here>}
This is a text \raisebox{-0.5\totalheight}{\includegraphics{temp.jpg}}
Explanation:
\raisebox moves vertically the whole text/picture given as second argument. The first argument is the vertical shift as a length. This command provides the length \totalheight which is, self-explanatory, the height of the whole text/picture that you want to raise. The factor -0.5 lowers exactly at the half of the length(as the question demands). For aesthetic adjustments just modify the factor's value.
By the way, with this method there is no need to get into math mode as in #AlexeiMalistov answer, and no need of double command \vcenter + \hbox

Resources