Jump to content

Scrolling Help - Maths


.:HyPeX:.

Recommended Posts

Well i'm not sure how is this happening, but i have the following:

A Render target with my maplist.

The BG (Wich allows 8 maps to fit) is drawn inside the render target the quantity of maps divided by 8 (Becouse it allows 8 maps each image)

I stop the BG short away from the "visible point" (As only a part of the render is drawn) to improve performance.

This works.

However, i tried to implement this on my dxDrawText for the map names, and it certainly failed, but in a weird way, and i cant understand why.

The text stops drawing correctly at 0.043 of progress (Number provided to check the code for my flaw..)

This is my code:

  
local mapslist = upanel.tab.mapstore.mapslist or {} 
local large = math.ceil(#mapslist / 8 )+50 
local progress = upanel.tab.mapstore.progress or 0 
dxSetRenderTarget(maplist) 
outputConsole(progress) 
for i=1, large do 
if i >= (progress * large) - 2 and i <= (progress*large) + 2 then 
dxDrawImage(0,0+mapY*(i-1), mapX, mapY,"img/mapshop/MapListBG.png") 
end 
end 
  
for i=1, #mapslist+(50*8) do 
if i >= (progress*(#mapslist+(50*8))) - (2*8) and i <= (progress*(#mapslist+(50*8 ))) + (2*8 )  then 
dxDrawText("[DM] Your Mum is so big that it cant fit in here",5,0 + (mapY/8 )  * (i-1),mapX - 30, (mapY/8 ) * (i-1) + (mapY / 8 ),tocolor(255,255,255,255),1,upanel.default[10],"left","center",true) 
dxDrawImage(mapX - 23,(mapY/8 ) * (i-1) + ((mapY/8)/2  - 18/2),18,18,"img/mapshop/FavN.png") 
end 
end 
  
dxSetRenderTarget(panel) 
  
dxDrawImage(-sx+300+localtab*bx+mapX+1,65,13,mapY,"img/mapshop/BarBG.png") 
local possible = mapY - 166 
dxDrawImage(-sx+300+localtab*bx+mapX+1.5+1,65 + possible * progress,11,166,"img/mapshop/bar.png") 
dxDrawImageSection(-sx+300+localtab*bx,65,mapX,mapY,0,0+mapY*large*progress,mapX,mapY,maplist) 
  

Explanation:

The "50" Extra are for testing purposes (As right now the #mapslist is returning always 0, so i assume the maplist is 50*8 maps long.)

Note: The "Extra white" line is the bottom of the BG image.

Visual:

Thanks in advance

HyPeX

Link to comment
  • MTA Team

I am a bit tired, but you may try to use that code:

local mapCount = #mapslist --[[debug:]] + 50 
local beginIndex = math.max(0, (progress * mapCount) - 8) 
local endIndex = (beginIndex + 8) 
  
for i = beginIndex, endIndex do 
    -- draw 
end 

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...