4 Replies Latest reply on Dec 11, 2006 6:27 AM by duckets

    Question for the Experts!

    cratica Level 1
      Well I've spent 3 or 4 days trying to get this to work and am partially successful, but am very unhappy with how messy it is.

      What I'm trying to do.

      I have lyrics from a song that is loaded into a list from a text file. This text file could be from various songs. Along with the words are the time in milliseconds of when they should appear and then scroll across the screen. So, we have two pieces of data, word and time. When it's time for a new word to be displayed, it shows up offscreen, then moves across the screen from right to left in a predetermined scroll rate (that part of the code is working good). Depending on the length of the song, this cycle can happen up to several hundred times with perhaps up to 20 words onscreen at the same time at any given moment.

      How it works now... (not happy with)

      The sloppy way I have done this is to create a bunch of text members and placed them in seperate sprites. I then assign each word read from the list to a seperate member/sprite. Then I manually move each one across the screen. Very, very clumsy and messy.

      QUESTION...

      How do I do this more dynamically where it's cleaner on the screen, more efficient for the cpu and a LOT less code?? Text
        • 1. Re: Question for the Experts!
          duckets
          A couple of methods spring to mind:
          ---------------------------------------------
          Method 1:

          Use the lingo 'image' command to create an image object which is as wide as the visible scrolling area, plus an extra distance which is at least as wide as the longest word.

          Position the image on stage, flush with the left edge of the stage, extending off the right hand side.

          Create some code to 'scroll' whatever is in the image a certain number of pixels to the left each frame, using copypixels.

          Each time a word is due to appear, put the word on its own into a text field, then grab the .image property of that text field and copy it to the 'offscreen' part of your wide image - which should then scroll onto the screen because of the scrolling code I mentioned earlier.
          ---------------------------------------------
          Method 2:

          Put the first N words (say, 10) into a text field. The text field sprite should be flush with the left edge of the stage, and extend a certain distance beyond the right hand edge of the stage. Each time a new word is due to appear, append it to the end of the text in the text field, while at the same time sliding the text sprite to the left until it reaches a position where the first char of the second word is at the left edge of the stage (using charPosToLoc). Then delete the first word (& space) from the text field, and replace the text sprite position back flush with the edge of the stage. If this is done right, there should be no visible jerk at this point, and you should be ready to scroll and add the next word!

          I think the 2nd method is probably better since the first method would leave variable gaps between the words.

          hope this helps!


          - Ben


          • 2. Re: Question for the Experts!
            cratica Level 1
            Thanks Ben for that...

            Unfortunately, each word has to be a seperate item since each word also will have a different vertical position and not one that a simple line space would do.

            There will actually be a lot of gaps between some of the words since they are positioned by miliseconds (from cue points in a song wav file).

            Hmmm, might have to just stick with the ugly way of doing it! :)
            • 3. Question for the Experts!
              cratica Level 1
              duplicate

              • 4. Re: Question for the Experts!
                duckets Level 1
                You might also consider using a 'pool' of 10 or so text cast members (and therefore 10 sprites), and re-using them in turn, by replacing their position back off the right hand edge of the stage, and changing the word they display. Use a counter variable to determine which is the next sprite to use.

                - Ben