Jump to content

Changin' Image on click.


Karuzo

Recommended Posts

Hi Community,

so i have a question about dx Images.

I have a few images in a folder, and i named them all like 1, 2, 3 ,4, etc...

My Question is : How can i show the 2nd picture after the first if i click on my button ?

i know i have to count it +1 but how ?

i hope you could help me.

regards,

KRZO.

Link to comment

You can do something like this:

local images = { "images/1.png", "images/2.png", "images/3.png", "images/4.png" } 
  
local curIndex = 1 
  
addEventHandler( "onClientRender", root, 
function () 
    dxDrawImage(x, y, w, h, images[curIndex]) 
end ) 
  
addEventHandler( "onClientGUIClick", button, 
function () 
    curIndex = curIndex + 1 
end ) 

Link to comment

Thank you guys for you replies, DNL291, your's is working perfectly.

I tried to make a left button also so i can press the left button to get a picture before if im on the last picture.

but that doesn't really work

addEventHandler( "onClientGUIClick", linksbut, 
function () 
    if (curIndex == #images) then 
        return 
    end 
    curIndex = curIndex - 1 
end ) 

Link to comment
addEventHandler( "onClientGUIClick", guiRoot, 
function () 
    if (source == nextPicButton) then 
        if (curIndex == #images) then 
            return 
        end 
        curIndex = curIndex - 1 
    elseif (source == previousPicButton) then 
        if (curIndex == 1) then 
            return 
        end 
        curIndex = curIndex - 1 
    end 
end ) 

nextPicButton and previousPicButton must be defined.

Link to comment

Oh , didn't knew that, thx.

Well , it doesn't work either.

local images = { "images/photo/1.png", "images/photo/2.png", "images/photo/3.png"} 
  
local curIndex = 1  
  
addEventHandler( "onClientGUIClick", guiRoot, 
function () 
    if (source == rechtsbut) then 
        if (curIndex == #images) then 
            return 
        end 
        curIndex = curIndex - 1 
    elseif (source == linksbut) then 
        if (curIndex == 1) then 
            return 
        end 
        curIndex = curIndex - 1 
    end 
end ) 

After the first picture theres nothin.

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