Multiple images exchange

edited January 2017 in Programming Questions

Hey, I've been using processing for about a month now, and I'm working on making a basic maze game for fun. I've finished all the mechanism required to move the characters, prevent them from leaving the map and so on, but when I try to change the characters, it changes it once, but never back again... can any1 help? Here's the code that I'm having trouble with:

if (keyPressed) { if ((key == 'p') || (key == 'P')) { glow = fire; biden = madPepe; } }

if (keyPressed) { if ((key == 'b') || (key == 'B')) { fire = glow; madPepe = biden; } }

I know that the Biden variable has been changed to madPepe, and I can't reverse that...any way to reverse it or is that not possible? Thank you

Answers

  • edited January 2017 Answer ✓

    @Ahmed -- share your complete code. Also, please edit your original post and format your code snippet: https://forum.processing.org/two/discussion/15473/readme-how-to-format-code-and-text

    If you are trying to swap a value back and forth, it sounds like you need 3 variables.

    light = glow;
    light = fire;
    light = glow;
    character = biden;
    character = madPepe;
    character = biden;
    

    If you don't, watch what happens:

    int alpha = 1;
    int beta = 2;
    alpha = beta; // now both equal 2
    beta = alpha; // ...and both *still* equal 2
    
  • also, change the title - the contents have nothing to do with image loading.

Sign In or Register to comment.