Tails Posted December 21, 2015 Share Posted December 21, 2015 (edited) Hello, 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 December 21, 2015 by Guest Link to comment
</Mr.Tn6eL> Posted December 21, 2015 Share Posted December 21, 2015 dxCreateRenderTarget Link to comment
Tails Posted December 21, 2015 Author Share Posted December 21, 2015 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
Addlibs Posted December 21, 2015 Share Posted December 21, 2015 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
Tails Posted December 22, 2015 Author Share Posted December 22, 2015 But how do I match the render target to the dxDrawText position and size? Because the text by it self is already in the correct position. I just randomly typed in that 800,700 for the target creation to see what I'm doing. Link to comment
Tails Posted December 22, 2015 Author Share Posted December 22, 2015 How do you project the text onto the target? Is there anyway to make the target visible? Or is the image going to be the target? I don't get it at all. Link to comment
t3wz Posted December 22, 2015 Share Posted December 22, 2015 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
Tails Posted December 23, 2015 Author Share Posted December 23, 2015 Thank you t3wz. I will study it and come back here if I have more questions. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now