SwiftUI programatically create grid of letter tiles - grid

I am new to SwiftUI and have been looking at a way to create a word tile game.
I have a tileView, and my contentView adds a number of tiles. My issue is I would like to programmatically build the tiles vertically as well as horizontally, in a grid. This makes me think that H-Stack and V-Stack are not appropriate for this use.
What I would like to do is:
The user taps on a tile
If the tile does not have a tile directly above, below or beside it it will present a new tile to fill those spaces. Hence the user can build the layout themselves.
Very naively I am assuming to do this I would check if there is a tileView a co-ordinate directly above the tile tapped. Then If the result is negative, I instantiate a tile in this new space. But I am guessing as this is in 2 dimensions, it cannot be in a H-Stack or V-Stack.
Here is the start of my code. tileView is basically drawing a rectangle with the character on it. This iterates through the array and adds the tiles in HStack. The issue here is this is for horizontal layout, not two dimensions. I am reading now that iOS 14 contains LazyVGrid and I am wondering if I could utilise this for what I want.
So the user selects any of these letters and directly above and below each tile appears another letter.
var str:[Character] = ["T", "E", "S", "T"]
var body: some View {
HStack {
ForEach((str), id: \.self) { Character in
tileView( letter: Character)
}
}
If anyone has some pointers or suggested reading material I would appreciate it, thanks.

Related

JavaFX - How to add array of MeshViews to group or scene

Update: I updated my code to loop through the list of meshviews and add each to the group using group.getChildren.add(meshview[i]) but still does not show up on screen. Thanks.
I am trying to add an array list of MeshView type to a scene in JavaFx based GUI. I was able to get an initial example to work where it was one MeshView, but now I have a case where the data that is read in from a file results in an array of MeshView type. I could not find a "add" or "addAll" type function on the Group type to let me loop through all of the elements and add them and I could not get the Group constructor to let me add the list at ones in the arguments. I am using a Group to contain them because the over all GUI makes use of a BorderLayout defined using an FXML file. So my initial version adds the meshview to a group along with some point lights and then that group is added to the center of the border layout using the set method of it. Any help would be appreciated. Thanks.
Ps. I think I may have just found an answer. I forgot the add method is under the get children:
group.getChildren().addAll(meshView, pointLight);
as the line above from another answer shows. But I would still be interested in hearing the best ways because I still am confused on how to deal with sitaution where you have say 20 meshviews that make up a part to be shown on screen and you want to combine those and appropriate lights etc and scale to fit in center or borderlayout. I'm guessin I can first all all meshviews using add and then add the lights but was not sure. Thanks again.
You can always add mesh views to any Node type object like Group or BorderLayout ex.
root.getChildren().add(meshView);
you can add as most as you can to this root object and translate the meshView in the scene
meshView.setTranslateX(200);
meshView.setTranslateY(200);
meshView.setTranslateZ(200);
and set the camera and lightpoints configuration and add them as well to the scene

JavaFX drag and drop to the 'white space' of a javafx.scene.Group

I'm trying to implement a drag'n'drop to a group containing several shapes and lines. Point is, the DragEvent is detected - but only on the children of the group.
Simple snippet:
addEventFilter(DragEvent.ANY, dragEvent -> {
dragEvent.acceptTransferModes(TransferMode.ANY);
System.out.println(dragEvent.getEventType());
dragEvent.consume();
});
Is there a way that the DragEvent is detected 'everywhere' inside the bounds of the group, especially the white space or do I have to manage the children with something different than a group, and what could that be?
Thanks in advance,
Tom

UWP maps, add 3D object

I would like to add 3D object in Windows 10 UWP map control.
This object would be "polygon with height", e.g. simple representation of a house - cuboid or cube.
Illustration image:
I know that I can add Xaml control (and inside it 3D object e.g. Cube) but then this Cube is not 'map object', only pinned to a certain Lat/Lon.
Any idea how to implement this?
Microsoft has added MapElement3D in Windows 10 Insider Preview v10.0.16257.0. - that's the falls creators update. It allows you to add objects, turn them, control their size, and direction. You can make them move too!
Example
How-To
Represents a 3D element displayed on a MapControl.
It's usage appears to be very similar to other MapElements, such as MapIcons and MapBillboards.
map3dSphereStreamReference = RandomAccessStreamReference.CreateFromUri
(new Uri("ms-appx:///Assets/trainengine.3mf"));
var myModel = await MapModel3D.CreateFrom3MFAsync(map3dSphereStreamReference,
MapModel3DShadingOption.Smooth);
var my3DElement = new MapElement3D();
my3DElement.Location = myMap.Center;
my3DElement.Model = myModel;
myMap.MapElements.Add(my3DElement);
Beware of two undocumented issues:
Attempting to add the same 3DMapElement to two different MapControls will result in System.AccessViolationException. This can happen if you cached the 3D model but not the page with the map control.
HResult=-2147467261 Message=Attempted to read or write protected
memory. This is often an indication that other memory is corrupt.
Attempting to call MapModel3D.CreateFrom3MFAsync() from a non-Ui thread will cause a crash. This must be called from a UI thread.

how to make sprites stick together in game maker?

I don't know how to get sprites to stick to each other so they become one big object instead of tiny little pieces, for example:
attaching a thruster to a box, then the thruster stays in that spot while pushing the box, and also is there a certain term for what I'm talking about?
You could also attach all parts to one of the objects, it would sort of look like:
//Main object
x = 5;
y = 20;
//other object step event
x = obj_main.x + <any value to put it where you want>;
y = obj_main.y + <any value to put it where you want>;
//This will force the parts to follow the main object.
`
`
You can use an array, defined in the 'main' object to use a sort of grid to define where each piece is and then either draw each individual sprite, based on its position in the array, originating from the 'main' object's coordinates. Or just create an individual instance of an object if you would like to have additional functionality by trading off some performance.
For more information on arrays and how to position sprites and objects based on set coordinates, check out the GML documentation provided below:
Arrays:
https://docs.yoyogames.com/source/dadiospice/002_reference/001_gml%20language%20overview/401_06_arrays.html
lengthdir:
https://docs.yoyogames.com/source/dadiospice/002_reference/maths/real%20valued%20functions/lengthdir_x.html
what I did was make the object disabled, so when I press left and right it doesn't go anywhere, only the other piece would move, but when it came into contact it allowed the other piece to move along with it, and set its speed to the corresponding objects speed, in simpler term, when I collide with it, it turns the movement on and goes in the same direction as the current object in the same speed, making it look like its sticking

Creating new objects with Game Maker GML

I'd like to know if there's a way to check if an object exists on a point, and if not, create a new one while snapping the new object to a grid? I know you can use this instance_create(x,y,obj_to_create); but that just places on a point no matter what and doesn't snap to a grid. Also, is there a global mouse click event in Game Maker?
Thanks!
well there are a few (almost similar) functions that allow you to do this... But most straight forward is to use position_meeting(x,y, obj)
so the could would become:
if (!position_meeting(x, y, obj_to_create)) {
instance_create(x,y,obj_to_create);
}
Now to snap to grid you'll have to create it at a snapped position:
instance_create(x div GRIDW, y div GRIDH, obj_to_create);

Resources