ianmere
YaBB Newbies
Offline
Posts: 7
Smooth text scrolling????
Apr 7th , 2008, 2:42pm
Hi I've been making up a ticker which scrolls news headlines across the screen. The problem I'm having is getting the text to move across smoothly but also not using too much cpu, goal is under 10%. Has anyone looked into this?? Or have any ideas? I'm guessing that its something to do with the perfect, frame rate, pixel movement, screen hertz. I just cant get it right! Heres the code: import proxml.*; XMLInOut xmlIO; PImage orange = null; PImage black = null; String tickerMessage = ""; float txtlenth = 0; float xpos = screen.width; float xposb = (screen.width + txtlenth); void setup() { size(screen.width, 100); noStroke(); frameRate(60); smooth(); PFont font = loadFont("AkzidenzGrotConBQ-Medium-70.vlw"); textFont(font, 70); orange = loadImage("ORGE_logo with transparancyV2 copy.png"); black = loadImage("Black_logo with transparancyv3.png"); xmlIO = new XMLInOut( this ); xmlIO.loadElement("http://tvnz.co.nz/content/news_index_top_stories_group/rss_20_skin.xml"); } void xmlEvent(XMLElement element){ StringBuilder sb = new StringBuilder(); Vector elements = element.getSpecificElements("channel"); XMLElement channelElement = (XMLElement) elements.get(0); Vector items = channelElement.getSpecificElements("item"); for (int i = 0; i < items.size(); i++) { sb.append(((XMLElement) items.get(i)).firstChild().firstChild() .getText()); sb.append(" - "); } setTickerMessage( sb.toString() ); } public synchronized void setTickerMessage( String message ){ tickerMessage = message; txtlenth = textWidth( message ); xposb = txtlenth + screen.width; xpos = screen.width; } public synchronized String getTickerMessage(){ return tickerMessage; } void draw() { String message = getTickerMessage(); if( message != null ){ xpos = xpos - 2; xposb = xposb - 2; if(second() <= 30) { //what colour the background is depending on the time background(255, 127, 0); } else { background(0); } text(message, xpos, 75); text(message, xposb, 75); if (xpos < (-txtlenth)){ xpos = txtlenth; } if (xposb < (-txtlenth)){ xposb = txtlenth; } if(second() <= 30) { image(orange, 0, 0); //which image loads depending on the time } else { image(black, 0, 0); } } }