Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

ScrollView w/ Tables - Object Position Not Changing
Started by binky Jan 20 2019 08:09 PM

1 reply to this topic
scrollview tables object

Best Answer binky , 20 January 2019 - 08:12 PM

Solved. I added a rect and set its height to the object height.
local my_rect = display.newRect( center_x, center_y, width, group.height )
my_rect:setFillColor( 1, 1, 1 )
scroll_view:insert( my_rect )

[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

binky

[GLOBAL: userInfoPane.html]
binky
  • Observer

  • 9 posts
  • Corona SDK

Hello everyone, I am having an issue with scrollview. Here is an example of my problem.

 

The table used if anyone wants it:

utils.settings =
{--id, name, value, cost, + table num, image, obj x offset, obj y offset
	{  1, "balance"      , 0,  0 , 0,       "", },
	{  2, "gamercoin"    , 0,  0 , 0,       "", },
	{  3, "clickervalue" , 1,  0 , 0,       "", },
	{  4, "autoclicker"  , 1,  0 , 0,       "", },
	{  5, "monitor_level", 4,  0 , 0,       "", },
	{  6, "buymouse"     , 0, -20, 1, "mouse1", 100, 75 }, --make sure the value increases by three each time :)
  {  7, "buycpu"       , 0, -20, 4,       "", },
  {  8, "buygpu"       , 0, -20, 7,       "", },
  {  9, "buyram"       , 0, -20, 10,      "", },
	{ 10, "buybuilding"  , 0, -20, 13,      "", },
}

Code:

  local objects = {}

  local function scroll_listener( event )

      local phase = event.phase

      if ( event.limitReached ) then
          if ( event.direction == "up" ) then print( "Reached bottom limit" )
          elseif ( event.direction == "down" ) then print( "Reached top limit" )
          end
      end

      return true
  end

  local scroll_view = widget.newScrollView(
      {
          top = 60,
          left = 0,
          width = width,
          height = height * 2,
          horizontalScrollDisabled = true,
          verticalScrollDisabled = false,
          listener = scroll_listener
      }
  )

  local function increase_upgrades( event )
    for i = 1, #utils.settings do
      if ( event.target.string == utils.settings[i][2] ) then
        if ( utils.settings[1][3] + utils.settings[i][4] >= 0 ) then --if the users balance + objects cost >= 0 then
          if ( objects[utils.settings[i][5]].alpha == 1 ) then --if the object has a alpha value of 1 then

            if ( event.phase == "began" ) then
              objects[utils.settings[i][5]].y = objects[utils.settings[i][5]].y + 1.5
            end

            if ( event.phase == "ended" ) then
              utils.update_balance( utils.settings[i][4] ) --update the balance by deducting the cost of the object

              if ( utils.settings[i][6] ~= "" and utils.settings[i][3] < 1 ) then --if the object can draw an image then
                utils.settings[i][3] = 1 --these objects only get brought once
                objects[utils.settings[i][5]].alpha = 0.5 --set alpha to 0.5
                objects[utils.settings[i][5] + 1].alpha = 0.5 --set alpha to 0.5 (they now cannot be brought again)
                objects[utils.settings[i][5] + 2].alpha = 0.5 --set alpha to 0.5 (they now cannot be brought again)
              elseif ( utils.settings[i][6] == "" ) then --if the object cannot draw an image then
                utils.settings[i][3] = utils.settings[i][3] + 1 --increase the value of the object by 1
                utils.settings[i][4] = utils.settings[i][4] * 2 --doubling the cost of the object
                utils.settings[3][3] = utils.settings[3][3] + 1 --increasing the clickervalue by 1
                utils.update_database( utils.settings[3][1], utils.settings[3][2], utils.settings[3][3], utils.settings[3][4] ) --updating the clickervalue to the database
              end

              objects[utils.settings[i][5] + 1].text = utils.settings[i][2] .. ": " .. ( -1 * utils.settings[i][4] ) --updating the text associated with the brought object
              objects[utils.settings[i][5] + 2].text = "amount: " .. ( utils.settings[i][3] )
              utils.update_database( utils.settings[i][1], utils.settings[i][2], utils.settings[i][3], utils.settings[i][4] ) --updating the objects value in the database
              objects[utils.settings[i][5]].y = objects[utils.settings[i][5]].y - 1.5

            end

            return true

          end
        end
      end
    end
  end

  for i = 1, #utils.settings do
    if ( utils.settings[i][4] ~= 0 ) then

      objects[utils.settings[i][5]] = display.newImage( utils.settings[i][2] .. ".png", center_x - 60, ( i - 5 ) * ( height / 4.5 ) - 35 )
      sceneGroup:insert( objects[utils.settings[i][5]] )
      objects[utils.settings[i][5]]:scale( 0.4, 0.4 )

      objects[utils.settings[i][5] + 1] = display.newText( utils.settings[i][2] .. ": " .. ( -1 * utils.settings[i][4] ), center_x - 10, ( i - 5 ) * ( height / 4.5 ) - 35, font, 24 )
      sceneGroup:insert( objects[utils.settings[i][5] + 1] )
      objects[utils.settings[i][5] + 1].anchorX = 0

      objects[utils.settings[i][5] + 2] = display.newText( "amount: " .. ( utils.settings[i][3] ), objects[utils.settings[i][5] + 1].x, objects[utils.settings[i][5] + 1].y + 17, font, 16 )
      sceneGroup:insert( objects[utils.settings[i][5] + 2] )
      objects[utils.settings[i][5] + 2].anchorX = 0

      if ( utils.settings[i][3] == 1 and utils.settings[i][6] ~= "" ) then --when switching to "upgrades.lua" draw the image & text to .alpha(0.5) if only able to be brought once
        objects[utils.settings[i][5]].alpha = 0.5
        objects[utils.settings[i][5] + 1].alpha = 0.5
        objects[utils.settings[i][5] + 2].alpha = 0.5
      end

      objects[utils.settings[i][5]].string = utils.settings[i][2]
      scroll_view:insert( objects[utils.settings[i][5]] )
      scroll_view:insert( objects[utils.settings[i][5] + 1] )
      scroll_view:insert( objects[utils.settings[i][5] + 2] )
      objects[utils.settings[i][5]]:addEventListener( "touch", increase_upgrades )

    end
  end

  sceneGroup:insert( scroll_view )

Any help would be greatly appreciated!



[TOPIC: post.html]
#2

binky

[GLOBAL: userInfoPane.html]
binky
  • Observer

  • 9 posts
  • Corona SDK

  Best Answer

Solved. I added a rect and set its height to the object height.
local my_rect = display.newRect( center_x, center_y, width, group.height )
my_rect:setFillColor( 1, 1, 1 )
scroll_view:insert( my_rect )



[topic_controls]
[/topic_controls]