making my way through the processing book and got to the client server chapter which is fantastic.
I haven’t gone as far as Daniel has suggested by creating a pong game but close enough. I am moving a rect around the client from the server. However, my question is I have code to move the rect, but what is the best course of action for stopping the box once a key is released? As it stands, the box continues to move.
I have tried keyReleased() to send a ‘stop’ int but clearly this is called after I release a button, meaning the rect doesn’t move :).
i am not sure your question has anything to do with client server projects
for a keyboard operation you can use
while https://processing.org/reference/keyPressed.html move
What does your server code look like? It is unclear from your description if you are trying to add keyReleased to your client or server sketch. Client can use IO functions, server receives signals.
I did a quick exploration of this.
In the Processing examples…
Modify “SharedCanvasServer” as follows:
s.write(0 + " " + 1 + " " + 2 + " " + count + “\n”);
// text(“keyReleased”, 100, 100);
Modify “SharedCanvasClient” as follows:
if (data==0 &data==1&data==2)
line(data, data, data, data);
When you release a key it will increment count and display on console:
Only one console is active so this is why “keyReleased Server” shows up on same console as client.
You must start “server” and then “client” for this to work.
The server draw window must be “active” to accept a keypress and release.
The client and server examples worked for me using localhost IP of 127.0.0.1