Unity Drag and Drop Canvas Boundary
What I want is simple, I already have the drag and drop mechanic done. All I want to know is how I can set boundaries so that I can't drag and drop any UI images out of the canvas.
do you know?
how many words do you know
See also questions close to this topic
-
Access to a PhotonView component
I need to access the INT of this component.
I am using a Photon View, and I want to set a conditional if a GameObject has that "INT" value.This is the Component
-
How can I programmatically "step" through a scene playthrough for identical playback in Unity? (pixel perfect frame replay)
My objective is to take camera snapshots of the editor playmode every 150 frames. This is so that I can validate a test scene by comparing screenshots every test run to ensure they are identical. How can I ensure every 150th frame will look exactly the same?
I understand the physics / time / graphics updates all run on separate timings. Is there a way I can force the engine to sync all these timings to make sure every frame is identical during repeated playbacks?
-
error CS1061: 'Animator' does not contain a definition for 'SetInt' and no accessible extension method 'SetInt'
so I'm having this error above in Unity and I don't know how to solve it.
The error from what I understand is in the switch, it's probably not getting the animator and blocking me from setting the animation value.
I searched on google and ended up not understanding very well, if anyone can help me I would appreciate it
public class Pontos : MonoBehaviour { public static Animator BluePoint, RedPoint; public static int Score; void Start() { BluePoint = GameObject.Find("Azul_Icons").GetComponent<Animator>(); RedPoint = GameObject.Find("Vermelho_Icons").GetComponent<Animator>(); Teste(); } void Teste() { if (PlayerAzul.BlueShoot) { Score++; } } } public class Blue : Pontos { void Point() { switch (Score) { case (0): BluePoint.SetInt("AzulValor", 0); Debug.Log("Score = 0"); break; case (1): BluePoint.SetInt("AzulValor", 1); Debug.Log("Score = 1"); break; case (2): BluePoint.SetInt("AzulValor", 2); Debug.Log("Score = 2"); break; case (3): BluePoint.SetInt("AzulValor", 3); Debug.Log("Score = 3"); break; } } }
To give a better example, this code is my points table (it's not perfect because I'm still testing it).
In void Test, don't worry about "PlayerAzul" (class) and "BlueShoot" (bool) , they are from another script that is working fine.
-
How to use Tkinter after method to give the impression of a wheel spinning?
I'm trying to create three separate 'wheels' that change the starting position of the first arc in order to give the impression of the wheel spinning. Tkinter will draw the first wheel on the canvas and delete it after 1 second, but the subsequent wheels are never drawn.
from tkinter import Canvas, Tk tk = Tk() tk.geometry('500x500') canvas = Canvas(tk) canvas.pack(expand=True, fill='both') in_list = [1,1,1,1,1,1,1] arc_length = 360 / len(in_list) first_mvmt = arc_length / 3 second_mvmt = arc_length * 2 / 3 mvmt_list = [0, first_mvmt, second_mvmt] for mvmt in mvmt_list: for i in range(len(in_list)): start = i * arc_length extent = (i + 1) * arc_length arc = canvas.create_arc(5, 5, 495, 495, outline='white', start=start + mvmt, extent=extent) canvas.after(1000) canvas.delete('all') tk.mainloop()
Also please excuse my poor formatting, this is my first post on stackoverflow
-
Flutter: draw over image with CustomPainter with DrawnLines
A part of an application I am working on involves editing photos. I am attempting to include an option to draw on an image. I can not find any examples of how to do this on Github or with the documentation.
This is what I have so Far:
class Sketcher extends CustomPainter { final List<DrawnLine> lines; final ui.Image image; final BuildContext context; Sketcher({required this.lines, required this.image,}); @override void paint(Canvas canvas, Size size) { Paint paint = Paint() ..color = Colors.redAccent ..strokeCap = StrokeCap.round ..strokeWidth = 5.0; for (int i = 0; i < lines.length; ++i) { if (lines[i] == null) continue; for (int j = 0; j < lines[i].path.length - 1; ++j) { if (lines[i].path[j] != null && lines[i].path[j + 1] != null) { paint.color = lines[i].color; paint.strokeWidth = lines[i].width; canvas.drawLine(lines[i].path[j], lines[i].path[j + 1], paint); } } } // Add DrawnLine to image } @override bool shouldRepaint(Sketcher oldDelegate) { return true; } }
At the moment I am displaying the Drawn Lines over the Image in a
Stack
Widget.Is there a way to combine the canvas with the Image by amending the lines to the Image?
I already know about canvas.drawImage() however I haven't found any code that works and no one is having a similar issue anywhere online.
-
tkinter tab width incorrect
When creating text on a canvas using the
create_text
method the width of a tab is not what it should be, as indicated byfont.measure
.import tkinter as tk from tkinter.font import Font root = tk.Tk() canvas = tk.Canvas(root, width=300, height=300) canvas.pack() font = Font(family='Arial', size=12) s1 = "a\tb" s2 = "a c" print("Width:", s1, font.measure(s1)) # Width: a b 30 print("Width:", s2, font.measure(s2)) # Width: a c 33 canvas.create_text(10, 10, text=s1, font=font, anchor="nw") canvas.create_text(10, 50, text=s2, font=font, anchor="nw") root.mainloop()
The results of
font.measure
suggest that the line with spaces should be a little longer, but what it displays is:Showing that the width of the tab is significantly larger than the spaces. Using different fonts will result in differently sized tabs, but still inaccurate measurements. The measured width of the text without tabs is correct.
How can I get the correct tab width? Is this a bug?
-
Pinning a particular element using a drag and drop library in React
I am migrating from react-beautiful-dnd to dnd-kit which does not have customization to pin a particular HTML element and the others we can drag and drop.
Like in this image I can drag the Drag Me Item 2 but it can't go above Pinned Item 1.I want the Pinned Item 1 to remain fixed and it should not rearrange itself according to the other items if I drag them above it. It should always be at the 1st position.
With dnd-kit we have a disabled example like above but we still can drag 2 above 1 despite 1 being disabled.
My codesandbox. I was trying to keep the first card with Clauderic always pinned to the 1st position.
How can I solve this using dnd-kit or any other drag and drop library in React?
-
Javascript - Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'
I have this code in my vue component
<template> <div class="container-fluid p-0"> <div class="row m-0"> <div class="col-12 vh-100 p-0" @drop="drop($event)" @dragover.prevent id="camView"> <canvas class="position-absolute top-0 end-0" ref="targetImg" id="targetImg"></canvas> <div class="position-absolute" id="selection" draggable="true" @dragstart="drag($event)"></div> <img src="@/assets/lu.jpeg" class="img-fluid" id="srcImg" ref="srcImg"> </div> </div> </div> </template> <script> export default { name: 'DropView', data() { return { } }, mounted() { }, methods: { drag(e) { console.log(e) e.dataTransfer.setData('text', e.target.id); }, drop(e) { console.log(e) e.preventDefault(); let data = e.dataTransfer.getData('text'); console.log(data) let box = document.getElementById(data) console.log(box) e.target.appendChild(box); } } } </script> <!-- Add "scoped" attribute to limit CSS to this component only --> <style scoped lang="scss"> .col-12 { #selection { width: 360px; height: 240px; border-style: dashed; border-width: 1px; border-color: white; background-color: transparent; z-index: 1; } #target-img { overflow: hidden; width: 320px; height: 240px; z-index: 1; } #srcImg { height: 100%; display: block; width: 100%; object-fit: cover; } } </style>
I'm trying to use drag and drop to moove a div that is positioned on top of an image. I'm able to start the drag operation but when I release the div into another position I will get this error in console
Vue warn]: Unhandled error during execution of native event handler Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.
I've noticed that the div will disappear and is not mooved. Is there any fix?
-
Xamarin Drag and drop how to edit balloon icon and text see image
Using the drag drop sample https://github.com/xamarin/xamarin-forms-samples/tree/main/WorkingWithGestures/DragAndDropGesture I'm not sure its actually a notify balloon not sure of its correct terminology making it hard to search. In the image you can see when drop location is active it displays in the ballon the copy icon and copy as text. I want to change the icon and the text but not sure how. I have tried the following code but it doesn't do anything.
private void OnCorrectDragOver(object sender, DragEventArgs e) { e.Data.Text = "My text data goes here"; e.Data.Image = "plusicon.png"; }
-
how to run a config file for boundary by hashicorp
Tried this command boundary dev -config file name
encountered the following error: flag provided but not defined: -config
-
How can I use an SVM to seperate two classes in a 2D map?
I have 2d-numpy array of points defining a map with obstacles Image of the 2D Map of which I am trying to create an SVM with. The values of this 2d-array are either 0 for open space (grey) or 1,-1 for obstacles (black/white). The formatting of the map is shown below:
[[ 1. 1. 1. ... 1. 1. 1.] [ 1. 0. 0. ... 0. 0. 1.] [ 1. 0. 0. ... 0. 0. 1.] ... [ 1. 0. 0. ... 0. 0. 1.] [ 1. 0. 0. ... 0. 0. 1.] [ 1. 1. -1. ... 1. 1. 1.]]
My goal is to use a Support Vector Machine (SVM) to create a line/decision boundary between the obstacles. Since the obstacles are two separate classes, it should be possible to generate an SVM separating them. The ideal SVM boundary would look something like this.
What I am unsure of us how to transform my data to be in the format shown in the sklearn SVM example. I need to be able to specify the features,
X
and the target,y
, so I can train the SVM by calling something likesvm.SVC(kernel='linear', C=C).fit(X, y)
as shown in the example.In summary: how to convert my map (a 2-d array of either
-1, 1, 0
) into a set of features and targets?