How to add mouse scroll action to my horizontal sliding text?

edited April 2016 in Questions about Code

Anybody can help me? Or what do u advice me? I got stuck

Answers

  • If you show code that you use it would be easier to give you advice. You can for example use mouseWheel to scroll the text.

  • **Alright. This is the code below i use. This is automatically sliding. But i need manually sliding with mause scroll. Also I need to know how to do some actions (like as fading screen out) when the screen come up to the word i choose. Finally this will be interactive book. Puff, so difficult for me :(( ** ps: Why doesn't the code work when i post the message here...?!

    String[] headlines = { "Aniden yerimden fırladım ve üzerine atladım. Ayağım takıldı ve düşmemle birlikte kafamı yere çarptım.", };

    PFont f; // Global font variable float x; // horizontal location of headline int index = 0;

    void setup() { size(800,450); f = createFont("calibri",16,true);
    // Initialize headline offscreen to the right x = width; }

    void draw() { background(245); fill(0);

    // Display headline at x location textFont(f,16);
    textAlign(LEFT); text(headlines[index],x,180);

    // Decrement x x = x - 1;

    // If x is less than the negative width, // then it is off the screen float w = textWidth(headlines[index]); if (x < -w) { x = width; index = (index + 1) % headlines.length; } }

  • I hightlighted the code and pressed CTRL+o. But it runs the comment "File/Open File" in Browser. What is the problem !?

  • edited April 2016

    I did format for you. Will provide you with example later.

    String[] headlines = { "Aniden yerimden fırladım ve üzerine atladım. Ayağım takıldı ve düşmemle birlikte kafamı yere çarptım.", };
    
    PFont f; // Global font variable 
    float x; // horizontal location of headline 
    int index = 0;
    
    void setup() { 
    size(800,450); 
    f = createFont("calibri",16,true);
    // Initialize headline offscreen to the right 
    x = width; 
    }
    
    void draw() { 
    background(245); 
    fill(0);
    
        // Display headline at x location 
    textFont(f,16);
        textAlign(LEFT);
     text(headlines[index],x,180);
    
        // Decrement x 
    x = x - 1;
    
    // If x is less than the negative width, 
    // then it is off the screen 
    float w = textWidth(headlines[index]); 
    if (x < -w) { 
    x = width; index = (index + 1) % headlines.length; 
      }
    }
    
  • edited April 2016 Answer ✓

    Basically try removing x = x - 1; and adding this at the end:

    void mouseWheel(MouseEvent event) {
      x = event.getCount(); // or x+=event.getCount(); 
    }
    
  • Thank you so much Ater. It made my sliding text control with mouse wheel. By the way, do you know how can i make actions when i sliding the text. Forexample a reader is scrolling the story text with mouse, then in a specific word in story text, something will occur. The word will be scaling up, or fade out, or geting screen dark. I will appreciate if you help me. I can pay for it too. This is my school project.

Sign In or Register to comment.