I've got a Simulation built and need to add a GUI onto it to choose x amounts of steps to simulate. The program right now only shows me the end result and I need it to show the simulation.
I can see in the command window its running, but just wont show movement of characters.
The simulation is a 2d grid of a room and people moving around based on who they are next and how happy they would be. Without the GUI the program works fine so I assumed if putting the code from the main arg in the non GUI code into the action performed for my simulate button it would work.
Right now this is the actionPerformed method:
private void simButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Simulator simulator = new Simulator(50, 50, 43);
// simulate the project for 10 rounds
simulator.simulate(10);
// simulator.setVisible(true);
}
Related
My code is supposed to use the mouse coordinates to draw a road when the mouse is clicked. Then, a car will drive continuously on it. The issue with my code is that the delay to have the car move on the road does not work properly. This piece of code:
var startTime = parseInt(new Date().getTime())
while (parseInt(new Date().getTime()) - startTime < 5000) {
print("waiting...")
}
drawCar(points[i][0],points[i][1])
is supposed to add a delay between the movements of the car so that the car movement can be visible to the user. The issue is that running the code will crash the page. I have already tried setTimeout() but this does not work properly for my needs. This function successfully adds a delay at the first time it is run but does not add a delay afterwards.
Code: https://editor.p5js.org/emanuele.saladini/sketches/SgcNhZjQS
i'm making a simple processing app for a presentation which currently does one thing : it listens to a microphone and emulates a right arrow key down event when it hears sound. I'm using it to synchronize a synth with the OSX finder, so when i play music it iterates through the files of a folder, as if i was pressing repeatedly on the right arrow on my keyboard.
my problem is that the app gets stuck when it hits the last file in a folder. The app needs to be aware of that so it can emulate a left arrow keydown event & a down arrow keydown event to go up a directory and carry on iterating.
I've tried calling applescript from processing to do that, which kind of works, but it's too slow and takes the focus away from the finder, then gives it back, which just looks glitchy (which is important as i'm making this app for a presentation).
I'm guessing i could maybe use a daemon polling which element is currently being selected in the finder, and sending that path to the processing app, and taking action if the path doesn't change after a keypress ; but then i'm not sure how to do that. Can python or bash poll that kind of info from the finder?
thank you!
import processing.sound.*;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
Amplitude amp;
AudioIn in;
Robot robot;
void setup() {
size(1, 1);
try {
robot = new Robot();
} catch (AWTException e) {
e.printStackTrace();
exit();
}
Sound s = new Sound(this);
s.inputDevice(3);
// select audio device ; if not available will fall back to default input
amp = new Amplitude(this);
in = new AudioIn(this, 0);
in.start();
amp.input(in);
in.play();
// playback of audio input : will larsen if you use computer's mic
}
void draw() {
// println(amp.analyze());
if(amp.analyze()>0.3){
println("go");
// if sound is louder than 0.3 press right key
robot.keyPress(KeyEvent.VK_RIGHT);
robot.keyRelease(KeyEvent.VK_RIGHT);
delay(200);
// prob not the right delay
}
}
I have been working on figuring out what is going on with my game's UI for at least two days now, and no progress.
Note that this is a mobile game, but I was asked to build for Windows for visualization and presentation purpose.
So the problem is that when I run my game on the Unity Editor, Android, iOS and Mac platforms the UI works just perfect, but then when I run the game on Windows the UI still works fine UNTIL I load a specific scene.
This specific scene is a loading screen (between main menu and a level) when the level finished async loading, a method called MoveObjects is called in a script in the loading screen, to move some objects that where spawned in the loading screen scene into the level scene (this is not the issue though, since I already try without this method and the problem on the UI persist).
Once the logic of this MoveObjects method is done, a start button is enabled in the loading screen, for the player to click and start playing (I did try moving the start button to the level scene, since maybe it not been a child of the currently active scene could be the issue, but the problem still persist). Is at this point that the UI is partially broken, what I mean with this is, that I can see buttons (and some other UI elements like a scrollbar) changing color/state when the mouse moves over them, but I cannot click on them anymore (the button wont even change to the pressed state).
Also note that I tried creating a development build to see if there was any errors in the console, and I notice that this problem is also affecting the old UI system, so I was not able to interact with the development console anymore.
Also also, note that if I grab and drag the scrollbar before this issue appear, and I keep holding down on the scrollbar until this happens, the mouse gets stuck on the scrollbar, meaning that I cannot interact with the UI anymore, but the scrollbar will still move with the mouse.
I already check that this things are not the source of the problem:
Missing EventSystem, GraphicRaycaster or InputModule.
Another UI element blocking the rest of the UI.
Canvas is Screen Space - Overlay so there is no need for a camera reference.
I only have one EventSystem.
Time.timeScale is 1.
I am not sure what else I could try, so if anyone has any suggestions, I would appreciate it. Thanks.
P.S: I am sorry to say that I cannot share any code or visual material or examples due to the confidentiality.
A major source for a non-working UI for me has always been another (invisible) UI object blocking the raycast (a transparent Image, or a large Text object with raycast on).
Here's a snippet I put together based on info found elsewhere, I often use it to track objects that are masking the raycast in complex UI situations. Place the component on a text object, make sure it's at least few lines tall, as the results will be displayed one under another.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
[RequireComponent(typeof(Text))]
public class DebugShowUnderCursor : MonoBehaviour
{
Text text;
EventSystem eventSystem;
List<RaycastResult> list;
void Start()
{
eventSystem = EventSystem.current;
text = GetComponent<Text>();
text.raycastTarget=false;
}
public List<RaycastResult> RaycastMouse(){
PointerEventData pointerData = new PointerEventData (EventSystem.current) { pointerId = -1, };
pointerData.position = Input.mousePosition;
List<RaycastResult> results = new List<RaycastResult>();
EventSystem.current.RaycastAll(pointerData, results);
return results;
}
void Update()
{
list= RaycastMouse();
string objects="";
foreach ( RaycastResult result in list)
objects+=result.gameObject.name+"\n";
text.text = objects;
}
}
I'm going around in circles trying to solve this.
Basically I have a tab control on my Firemonkey android app and can swipe left or right to change tabs and it works fine.
I would like to enhance the swiping so it behaves more like the android app drawer. What I mean by that is if you longtap and slowly slide your finger left or right the screen contents moves left/right with your finger as opposed to what I have now where it only moves a whole screen at a time and not slowly underneath your finger.
A THorzScrollBox is close to the effect I want but it doesn't "snap" onto a single screen but instead can leave your screen half and half on two pages.
Am I making sense here?
I'm using XE8 but I couldn't get it working on earlier versions either!
Many thanks,
Ian.
If someone is interested i just created a new TTabcontrol who enhance the swiping
you can see the code source here
(svn) https://svn.code.sf.net/p/alcinoe/code/
and the demo is here :
(svn) https://svn.code.sf.net/p/alcinoe/code/demos/ALFmxControls
any remark will be welcome :)
i continue also my logic: create a suite of firemonkey control who are very fast to draw, independant of OpenGL and that don't work with the style (i find the style in firemonkey very inefficient and horribly complicated to maintain), so i create this tabcontrol as a descendant of Tcontrol and not as a descendant of TStyleControl.
i think it much (much) more simple to create the title (ie: button) of the tab myself with basic component like trectangle + ttext than updating the so complicated Stylebook for each plateform (ioe, android, windows, macos, etc)
if you compare the unit of my Tabcontrol (ALFmxTabControl.pas) with the unit of the delphi TabControl (Fmx.TabControl.pas) then you will see that i use 3.5x less line of code (1018 vs 3550), and less line of code = always better
please vote for this feature request here :
https://quality.embarcadero.com/browse/RSP-15576
Trying the THorzScrollBox.AniCalculations.SetTargets(...).
eg.
1.Open FMX.HorizontalScroll Sample : CPP\Mobile Snippets\HorizontalScroll
2.Add Form Event : OnResize
3.Write the code :
#include <FMX.InertialMovement.hpp>
void __fastcall THorizontalScrollForm::FormResize(TObject *Sender)
{
TAniCalculations::TTarget target[4];
// Set ths size and position of your slides.
Image1->SetBounds(0, 0, HorzScrollBox1->Width, HorzScrollBox1->Height);
Image2->SetBounds(HorzScrollBox1->Width, 0, HorzScrollBox1->Width, HorzScrollBox1->Height);
Image3->SetBounds(HorzScrollBox1->Width*2, 0, HorzScrollBox1->Width, HorzScrollBox1->Height);
Image4->SetBounds(HorzScrollBox1->Width*3, 0, HorzScrollBox1->Width, HorzScrollBox1->Height);
// Assign the check point(your slides' top-left conner).
target[0].TargetType = TAniCalculations::TTargetType::Other;
target[0].Point = TPointD(1, 0);
target[1].TargetType = TAniCalculations::TTargetType::Other;
target[1].Point = TPointD(HorzScrollBox1->Width, 0);
target[2].TargetType = TAniCalculations::TTargetType::Other;
target[2].Point = TPointD(HorzScrollBox1->Width*2, 0);
target[3].TargetType = TAniCalculations::TTargetType::Other;
target[3].Point = TPointD(HorzScrollBox1->Width*3, 0);
HorzScrollBox1->AniCalculations->SetTargets(target, 3);
}
I implemented another version of this project with Java Swing, but because it could not support multi-touch functionality, I am rewriting it using JavaFX.
So I want the program to wait either for a user clicks a Button object or for a timeout, say 5 seconds - this means that the program would present a Button on the screen at one point and does not proceed to the next phase until either the Button is pressed or 5 seconds pass without it being pressed.
Clearly, detecting a click is elementary because adding ActionEvent would solve it. The tricky part is measuring the time. When implementing with Swing objects, I would have a while loop and have Thread.sleep(very_short_time_interval) inside to periodically check the elapsed time:
lastUpdate = System.currentTimeMillis();
while ((!pressed) && (System.currentTimeMillis() - lastUpdate <= timeout)) {
Thread.sleep(50);
}
The purpose of the Thread.sleep() in the pseudo-code above was to prevent the while loop from executing too often. Though it does not seem like the best practice, this trick apparently worked when used with Swing objects. But I realized after trying out the same thing with JavaFX Button objects, it turns the shape of the mouse pointer to a circulating ring, indicating the process is busy on Windows. What is worse is the button would not recognize mouse inputs during this busy phase. I am guessing JavaFX objects are heavier than Swing objects and is causing this problem as a result.
So my question is, would there be another way, possibly native function in JavaFX to make a Button expire without requiring a while loop? Or would there be some lighter weight objects than Button that works in a similar manner (listening to mouse clicks) that could work with the original while approach?
You can use a PauseTransition to wait for n-seconds. On its setOnFinished you can add an action to be performed. If the button has been pressed, you can cancel the transition on its action.
final PauseTransition pt = new PauseTransition(Duration.millis(5000));
pt.setOnFinished( ( ActionEvent event ) -> {
doSomething();
});
button.setOnAction( (ActionEvent event) -> {
doSomething();
pt.stop(); // If the button has been pressed, stop the Transition
});
pt.play();