Hi all,
I've got a system compatibility problem with a program I made that gives a view of a virtual arcade joystick controled with the arrow keys. Here's the code :
- Joystick stick;
- void setup() {
- size(50, 50);
- frameRate(50);
- stick = new Joystick();
- }
- void draw() {
- background(0);
- stick.check_input();
- stick.draw_joystick();
- }
- class Joystick {
- //Variables de classes
- int a;
- int b;
- boolean[] keys;
- //Constructeur
- Joystick(){
- keys = new boolean[526];
- }
- //Méthodes de classes
- boolean checkKey(int k){
- if (keys.length >= k){
- return keys[k];
- }
- return false;
- }
- void check_key_pressed(){
- keys[keyCode] = true;
- }
- void check_key_released(){
- keys[keyCode] = false;
- }
- void check_input() {
- a = 0;
- b = 0;
- if (checkKey(UP)) b++;
- if (checkKey(DOWN)) b--;
- if (checkKey(RIGHT)) a++;
- if (checkKey(LEFT)) a--;
- }
- void draw_joystick() {
- ellipse(width/2*(1 + a), height/2*(1 - b), 10, 10);
- }
- }
- void keyPressed() {
- stick.check_key_pressed();
- }
- void keyReleased() {
- stick.check_key_released();
- }
And sorry if there's any spelling mistake, I'm french and also trying to improve my english writing skills.
1