Visualizzazione dei risultati da 1 a 9 su 9
  1. #1

    [AS3] - News Ticker a scorrimento orizzontale - [POCO FLUIDO ??]

    Sto realizzando un News Ticker a scorrimento orizzontale il problema è che il movimento del testo è poco fluido, il testo si muove a scatti e non so come risolvere...
    il filmato e di 1280 px X 91 px a 25 fps (le dimensioni e il frame rate sono obbligatorie) e credo che incidano negativamente sulla fluidità ma pur troppo sono queste.

    il file XML
    Codice PHP:
    <?xml version="1.0" encoding="UTF-8"?>
    <news>

    <title>09:35 Afghanistan</title>
    <description>Attacco simultaneo a Nimroz: 7 esplosioni, morti</description>

    <title>09:29 Grecia</title>
    <description>Merkel difende aiuti: ne va del futuro dell'Europa</description>

    <title>07:43 Gb</title>
    <description>Elezioni, Blair critica Liberal-Democratici</description>

    <title>07:33 Grecia</title>
    <description>Ancora proteste, oggi secondo giorno sciopero generale</description>

    <title>06:54 Usa</title>
    <description>Record mondiale per quadro Picasso,venduto a 82 milioni euro</description>

    <title>04:57 Attentatore New York</title>
    <description>Addestrato in terra al Qaida, ho agito solo</description>
        
    </news>
    AS3
    Codice PHP:
    //-------------------------------------------------------------------------
    // XML
    //-------------------------------------------------------------------------
    var xmlLoader:URLLoader = new URLLoader();
    var 
    xmlRequest:URLRequest = new URLRequest("news/news.xml");

    xmlLoader.addEventListener(Event.COMPLETELoad_XML);
    xmlLoader.load(xmlRequest);

    var 
    news_title:Array = new Array();
    var 
    news_description:Array = new Array();
    var 
    text_to_scroll "";
    var 
    i:int;
    /*
    var title_tag_op:String = "<font color='#66CC00'>";
    var title_tag_cl:String = "</font>";
    */
    function Load_XML(e:Event) {
        var 
    xml:XML = new XML(e.target.data);
    // ..
        
    for each (var item_1:String in (xml.title.*) ) {
            
    news_title.push(item_1);
        }
    // ..
        
    for each (var item_2:String in (xml.description.*) ) {
            
    news_description.push(item_2);
        }
    // ..
        
    for (0<= (news_title.length-1); i++) { 
            
    text_to_scroll += "[b]" news_title[i] + "[/b]" " " news_description[i] + " ";
        }
    // ..
        
    load_news();
    // ..
    }

    function 
    load_news():void{
        
        
    //SCROLLING SPEED
        
    var scrolling_speed:int 4;
        
        
    //establish the field
        
    var my_text:TextField = new TextField();
        
        
    //add the field to stage
        
    addChild(my_text);
        
        
    //set the text
        
    my_text.htmlText text_to_scroll;
        
        
    //set the x coord off right side of stage
        
    my_text.stage.stageWidth;
        
        
    //set y coord in middle of stage (about)
        //my_text.y = (stage.stageHeight/2)-(my_text.height/2);
        
    my_text.16;
        
        
    //not selectable
        
    my_text.selectable false;
        
        
    //no border
        
    my_text.border false;
        
        
    //field scales with more text    
        
    my_text.autoSize TextFieldAutoSize.LEFT;
        
        
    //set a format
        
    var my_text_format:TextFormat = new TextFormat();
        
        
    my_text_format.font "Arial";    

        
    my_text_format.color 0xFFFFFF;

        
    my_text_format.size 40;
        
        
    //apply formatting
        
    my_text.setTextFormat(my_text_format);
        
        
    //add the listener to scroll    
        
    my_text.addEventListener(Event.ENTER_FRAME,move_text);
        
        
    //scroll function
        
    function move_text(myevent:Event):void {
            
    my_text.x-=scrolling_speed;
            if(
    my_text.x<(0-my_text.width)){
                
    my_text.x=stage.stageWidth;
            }
        }

    cichity74

  2. #2
    Utente di HTML.it L'avatar di and80
    Registrato dal
    Mar 2003
    Messaggi
    15,182
    Io lo vedo piuttosto fluido impostando un framerate a 30fps e mettendo un velocità di scroll di 2 o 3

  3. #3
    Originariamente inviato da and80
    Io lo vedo piuttosto fluido impostando un framerate a 30fps e mettendo un velocità di scroll di 2 o 3
    Nel mio caso sono obbligato a lavorare a 25fps
    e comunque anche portato a 60fps e speed a 2, pur essendo molto più
    fluido si vede lo scatto che fa su ogni ciclo di enterframe
    è possibile migliorare il movimento in qualche modo?

    cichity74

  4. #4
    Utente di HTML.it L'avatar di and80
    Registrato dal
    Mar 2003
    Messaggi
    15,182
    Sì ho capito, parli di quello scattino che fa ogni tanto, non vorrei sconfortarti ma mi pare che sia un problema derivante dallo scorrimento del testo che stressa il player e la cpu in maniera più accentuata rispetto al movimento di una bitmap.
    La soluzione più vicina sarebbe quella di usare una bitmap che appunto sostituisca il campo di testo e far muovere quella.
    In pratica la crei dopo che hai predisposto il testo, non agganci allo stage il campo di testo, ma solo la bitmap e muovi quella.

    Per creare una bitmap dal campo di testo devi creare prima una bitmapdata da usare per disegnare il campo di testo sotto forma di immagine e poi attaccarla ad un nuovo oggetto bitmap.

    Genericamente avresti un codice del genere:

    Codice PHP:
    var bd:BitmapData = new BitmapData(my_text.widthmy_text.heighttrue0x00808080);
    var 
    bp:Bitmap = new Bitmap(bd);
    addChild(bp); 
    E passare tutto il controllo dell'enterFrame al nuovo oggetto bitmap creato muovendo quest'ultimo.

  5. #5
    Hai perfettamente centrato il problema...
    stavo tentando di applicare il tuo suggerimento al mio script ma non riesco neanche a visualizzarla
    la bitmap "figuriamoci a muoverla"...

    Codice PHP:
    load_news();

    function 
    load_news():void{
        
        var 
    text_to_scroll "Pippo Pippo... in BitMap!";
        
        
    //SCROLLING SPEED
        
    var scrolling_speed:int 4;
        
        
    //establish the field
        
    var my_text:TextField = new TextField();
        
        
    //add the field to stage
        
    addChild(my_text);
        
        
    //set the text
        
    my_text.htmlText text_to_scroll;
        
        
    //set the x coord off right side of stage
        
    my_text.stage.stageWidth;
        
        
    //set y coord in middle of stage (about)
        //my_text.y = (stage.stageHeight/2)-(my_text.height/2);
        
    my_text.16;
        
        
    //not selectable
        
    my_text.selectable false;
        
        
    //no border
        
    my_text.border false;
        
        
    //field scales with more text    
        
    my_text.autoSize TextFieldAutoSize.LEFT;
        
        
    //set a format
        
    var my_text_format:TextFormat = new TextFormat();
        
        
    my_text_format.font "Arial";    
        
        
    //(stage bianco, text nero)
        
    my_text_format.color 0x000000;

        
    my_text_format.size 40;
        
        
    //apply formatting
        
    my_text.setTextFormat(my_text_format);
        
        
    /**/
        // creo bmp
        
    var bd:BitmapData = new BitmapData(my_text.widthmy_text.heighttrue0x00808080);
        var 
    bp:Bitmap = new Bitmap(bd);
        
        
    //bp.x = my_text.x;
        
    bp.= (stage.stageWidth/2);
        
    bp.my_text.y;
        
        
    addChild(bp);
        
        
    trace ("bitmap_x = " bp." | bitmap_y = " bp.y);    
        
        
        
    //add the listener to scroll    
        
    my_text.addEventListener(Event.ENTER_FRAME,move_text);
        
        
    //scroll bitmap function
        /**/
        
    function move_text(myevent:Event):void {
            
    bp.x-=scrolling_speed;
            if(
    bp.x<(0-bp.width)){
                
    bp.x=stage.stageWidth;
            }
        }
        
    //scroll text function
        /*
        function move_text(myevent:Event):void {
            my_text.x-=scrolling_speed;
            if(my_text.x<(0-my_text.width)){
                my_text.x=stage.stageWidth;
            }
        }
        */

    cichity74

  6. #6
    Utente di HTML.it L'avatar di and80
    Registrato dal
    Mar 2003
    Messaggi
    15,182
    Ho mancato nel codice il draw del campo di testo

    dopo aver creato la bitmapdata bisogna aggiungere la riga

    bd.draw(my_text);

    sennò non disegna proprio un bel niente

  7. #7
    Ho seguito le tue indicazioni crea e muove la BitMap....
    Ma è il movimento è ancora più blocchettoso di prima
    (1280 x 91 sfondo bianco a 25 Fps)
    Codice PHP:
    load_news();

    function 
    load_news():void{
        
        var 
    text_to_scroll "Pippo Pippo... in BitMap!";
        
        
    //SCROLLING SPEED
        
    var scrolling_speed:int 3;
        
        
    //establish the field
        
    var my_text:TextField = new TextField();
        
        
    //add the field to stage
        
    addChild(my_text);
        
        
    //set the text
        
    my_text.htmlText text_to_scroll;
        
        
    //set the x coord off right side of stage
        
    my_text.stage.stageWidth;
        
        
    //set y coord
        
    my_text.16;
        
        
    //not selectable
        
    my_text.selectable false;
        
        
    //no border
        
    my_text.border false;
        
        
    //field scales with more text    
        
    my_text.autoSize TextFieldAutoSize.LEFT;
        
        
    //set a format
        
    var my_text_format:TextFormat = new TextFormat();
        
        
    my_text_format.font "Arial";    
        
        
    //(stage bianco, text nero)
        
    my_text_format.color 0x000000;

        
    my_text_format.size 40;
        
        
    //apply formatting
        
    my_text.setTextFormat(my_text_format);
        
        
    /**/
        // creo bmp
        
    var bd:BitmapData = new BitmapData(my_text.widthmy_text.heighttrue0x00808080);
        var 
    bp:Bitmap = new Bitmap(bd);
        
    bd.draw(my_text);
        
    //bp.x = my_text.x;
        
    bp.= (stage.stageWidth/2);
        
    bp.my_text.y;
        
        
    addChild(bp);
                
        
    //add the listener to scroll    
        
    my_text.addEventListener(Event.ENTER_FRAME,move_text);
        
        
    //scroll bitmap function
        
    function move_text(myevent:Event):void {
            
    bp.x-=scrolling_speed;
            if(
    bp.x<(0-bp.width)){
                
    bp.x=stage.stageWidth;
            }
        }

    Come posso creare una scritta con movimento fluido ???
    il problema persiste

  8. #8
    up...

  9. #9
    Utente di HTML.it L'avatar di and80
    Registrato dal
    Mar 2003
    Messaggi
    15,182
    Nel codice vedo che continui ad attaccare "my_text" e non ce n'è bisogno, in più sfrutti l'enterFrame del campo di testo, lascia perdere e usa quello della bitmap.
    Non posso testare il tuo lavoro in questo momento, quindi non riesco a capire cosa non vada.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.