Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

SSK2: index of a loop
Started by premierghost May 14 2019 09:36 PM

1 reply to this topic

Best Answer nick_sherman , 14 May 2019 - 09:47 PM

image[i].index = i, then event.target.index in listener.

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

premierghost

[GLOBAL: userInfoPane.html]
premierghost
  • Observer

  • 17 posts
  • Corona SDK

Hi, I made a loop to place 17 images in a scrollview which I will use to play an audio. Im using ssk2 scroller and a faketap function to avoid the images to be touched when scrolling. The code below works fine, but I dont know how to capture the index of the loop in order to play the audio doing something like this "assets/FF/"..i..".mp3". I was only able to capture table: 12948F78 using event.target but i only can use that to edit properties on the image like the alpha. Sorry for bad english, hope you can help me. Thanks in advance :D

local scroller = ssk.vScroller.new( nil, centerX, centerY+myRectangle.height,
                                            { w = display.contentWidth, h = display.actualContentHeight,
                                              backFill = hexcolor("#FFFFFF") } )  

local function fakeTap( self, event )
    -- Only do work in "ended" phase
    local phase = event.phase
    if( event.phase == "ended" ) then
        -- Assign taps if not set yet
        self.taps = self.taps or 1

        -- Detect 'dragged' and show it
        if( event.dragged ) then 
            self.taps = 0
            return false 
        end
    end
    return false
    end


image = {}

    for i=1, 17 do


        image[i] = display.newImageRect( "assets/FF/"..i..".png",wVar, hVar )
        image[i].anchorY=0
        image[i].anchorX=0

        if i % 2 == 0 then

        cte0=cte0+1
        cte1=cte1+5

        image[i].x= image[i-1].x+image[i-1].width+5

            if i==2 then
            image[i].y=5
            else
            image[i].y= hVar*cte0 + (cte1)
            end

        else


        image[i].x=5
            
            cte2=cte2+1
            cte3=cte3+5

            if i==1 then
            image[i].y=5
            else
            image[i].y= hVar*cte2 + (cte3)
            end
        end


        scroller:insert(image[i])
        scroller:addTouch( image[i], fakeTap )
    end
    


[TOPIC: post.html]
#2

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,811 posts
  • Corona SDK

  Best Answer

image[i].index = i, then event.target.index in listener.
  • roaminggamer likes this


[topic_controls]
[/topic_controls]