Jump to content

Marquee / Moving text?


Tails

Recommended Posts

Hello,

bJ0U6Og.gif

Does anyone here have some experience with moving text, in particular like in the image above?

I have some issues with this. First let me tell you what I did to achieve the above.

To create this effect, I'm using string.sub() along with some other code to put the first letter behind the last and a timer to keep doing it.

There's just one issue, though. It's all very choppy and I need something much smoother.

So, I was wondering if anyone here knows a way to achieve that, preferably with dxDrawText. I've been thinking about ways but I just can't come up with anything good.

One way I thought of was to change the position of the text until it gets to a certain point then delete it and create a new one (or put it back) at the starting point.

But then what about what's between the end and the beginning? It could potentially work but it shouldn't go all the way across the screen and disappear into nothingness, it needs to scroll in this certain area only. If only there was a way to hide/cover a part of the text.

If you have any ideas, please share them with me. Anything would be helpful.

Tails

Edited by Guest
Link to comment

I don't know. That whole function just don't seem to work for me. All I get is big black square on my screen, I don't see how that's going to be useful. Unless I'm doing something wrong?

Based on the example from the wiki (I really have no idea what I'm doing here):

addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        drawArea = dxCreateRenderTarget(800,700)     
    end 
) 
  
addEventHandler( "onClientRender", root, 
    function() 
        if drawArea then 
            dxSetRenderTarget( drawArea ) 
            dxDrawText("This is the title of the song", 415, 790, 871, 837, tocolor(235, 133, 23, 255), 1.50, "pricedown", "left", "top", true, false, false, false, false) 
            dxSetRenderTarget() 
            dxDrawImage( 415, 790, 871, 837, drawArea ) -- ? 
        end 
    end 
) 

Link to comment

First of all, to change it from being a black square, into a transparent-background square, add true as the 3rd parameter on dxCreateRenderTarget (line 3)

Secondly, on line 11, you should change the positions of the text, since your render target is 800x700, and your text starts on Y 790, it is 90 pixels below the cut-off point. It should start at (0,0) and end at (800,700) to fill up the whole render target material, which will later be drawn in the correct position.

Link to comment

You can imagine a render target as a "new screen", When you do this:

drawArea = dxCreateRenderTarget(800,700) 

You are creating a "new screen" with 800px as width and 700 as height, As you may know, When you draw elements outside the player's resolution ( < -0 or > your width ) the "dx" will cut and won't render completely (the parts outside the resolution will not be visible), This will occur in render targets also:

text = "Sample Text"; 
render = dxCreateRenderTarget ( 200, 50, true ); 
x = 200 + 5; 
  
addEventHandler ( "onClientRender", root, 
    function ( ) 
        local minWidth = ( -dxGetTextWidth ( text, 1, "pricedown" ) - 5 ); 
        x = ( x == minWidth ) and ( 200 + 5 ) or ( x - 0.5 ); 
         
        dxSetRenderTarget ( render, true ); 
            dxDrawRectangle ( 0, 0, 200, 50, 0xAA000000 ); 
            dxDrawText ( text, x, 0, 200, 50, 0xFFFFFFFF, 1, "pricedown", "left", "center" ); 
        dxSetRenderTarget (); 
         
        dxDrawImage ( 200, 200, 200, 50, render ) 
    end 
) 

As you can see it's pretty simple, we have to use dxSetRenderTarget to tell MTA that we wish to render the text under the render target and not in the "normal screen", After going back to the "render-on-the-normal screen" mode (using dxSetRenderTarget without parameters) we have to draw the render target itself (using dxDrawImage) .

The other things in the script are just maths to move the text (i don't think that i need to explain it btw).

I hope that you have understood, Apologizes for my English, Also i have not tested the code (but it seems to work).

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...