Scrolling Text using X and Y co-ord placement HELP!

Discussion in 'C' started by sg57, Jun 18, 2006.

  1. sg57

    sg57 New Member

    Joined:
    Mar 7, 2006
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    Well, im making a 'media player' typething, so the scrolling text in this case will be the title... Meaning its automatically assigned, so it neds to scroll on its own...

    Ok, i have enough room for 20 characters to fit until the title will need to scroll... Im having it delay 1/2 second which is used via:

    sceKernelDelayThread(250000*2);

    This isnt for windows, so thats my delay right there...

    Ok, so far ive been thinking how the :eek: im going to do this... so im just guessing here...

    (the string is just an example, its actually set to the name...)
    Code:
    char title[] = "abcdefghijklmnopqrstuvwxyz";
    int titleLength = strlen(title), overChars;
    int scrollDistance;
    int titleX = 50, titleY = 5;
    while (1) {
                  printTextScreen(titleX-scrollDistance, titleY, title, RGBA(255,255,255,100));
       if ( titleLength > 20 ) {
                       overChars = titleLength - 20;
                       scrollDistance = overChars * 7;
                       sceKernelDelayThread(250000*2);
    }
    }
    Well... i think this here will print out the title titleX - 42... but i want it to scroll character by character, meaning it will print itout -7, then -7 again, then -7 again, until it reaches 42...

    i know a for loop is necessary... could someone help me out on this?
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Why dont you pad the string with the blank characters before and after depening on the position where you want to display the title
    Code:
    printTextScreen("      Title to display     ");
    
    and change it with the spaces as the timer is triggered.
     
  3. sg57

    sg57 New Member

    Joined:
    Mar 7, 2006
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    itd be much easier if i could just mess with it via titleX variable... not to mention i want it to scroll 1 character by 1 character...


    cant someone make or somehow help me towards just using integers to subtract and mess with the titleX variable to allow it to scroll 1 character at a time, then once it reaches the end/the character before the \0 character is showed, tehn reset it...

    cant some math wizzs help me out here?
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Code:
    static int iStart = 0;
    static int iPad = 0;
    char title[] = "abcdefghijklmnopqrstuvwxyz";
    int titleLength = strlen(title), overChars;
    char titleToShow[20];
    
    if(titleLength > 20)
    {
    	for(int i=iStart;i<20+iStart;i++)
    		titleToShow[i] = title[i];
    	iStart++;
    	titleToShow[i] = '\0';
    
    }
    else
    {
    	// Before padding with spaces
    	for(int i=0;i<iPad;i++)
    		titleToShow[i] = ' ';
    	// Copying the characters
    	for(;i<titleLength;i++)
    		titleToShow[i] = title[i];
    	// After padding with spaces
    	for(;i<20;i++)
    		titleToShow[i] = ' ';
    }
    Just this is the handler to the timer where you pad based on the static variable.
     
  5. sg57

    sg57 New Member

    Joined:
    Mar 7, 2006
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    Ok, and this will basically return titleToShow, only printing out the first 20 letters...

    Ok, maybe i shouldve told you my displaying right now...

    I have a little title bar which can hold 14 characters befreoy ou cant see them anymore...

    I have it printing the title beneathe the backround, and that title bar is transparent, so it shows up... So i have the title printed, and if it goes underneathe the backround (the length of the title is larger then 14 characters) then i want it to scroll 1 character left, every 1/2 second using the 'sceKernelDelayThrerad(250000*2);' call i stated earlier...

    The X co-ordinate is titleX=50 in this case...The title will be: title="abcdefghijklmnopqrstuvwxyz" So isnt there a way to subtract 7 from titleX for every character over 14 in the 'title', then reset it back to titleX = 50 once its finished the second to last character (the \0 is pointless to scroll :P )?

    (WHOA... i just said what i want to do... im going to give it a try... but i doubt ill be able to do it, but i cant ry until some programming person better then me helkps me out here...)

    P.S. oh and shabbir, if your snippet works for the titleX subtraction (i used dev-c++ and it just printed out 20 chractes) then im sorry, i dont see it
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Give it a try.
    Can you explain what you meant by I dont see it.
     
  7. sg57

    sg57 New Member

    Joined:
    Mar 7, 2006
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    ok, here is my attempt that i think works, but i doubt it...
    Code:
    int TitleX = 9, titleLength = strlen(TITLE), w, overChars = titleLength-14; 
    while(1) {
         printTextScreen(TitleX,TitleY, Title, colorOFtitle);
         for(w=titleLength;w>overChars;w--) {
                                            TitleX--;
         }
    }
    
    Im just trying to subtract 7 from an integer, every 1/2 second... Thus making text scroll by 7 chars to the left every 1/2 second...
     
  8. FletcherFregoe

    FletcherFregoe New Member

    Joined:
    Mar 12, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0

    I have a little title bar which can hold 14 characters befreoy ou cant see them anymore...
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice