使用Corona SDK难以在不同屏幕上创建对象

时间:2018-07-11 12:39:23

标签: lua corona

难以在不同屏幕上创建对象

你好,我正在创建一个应用,当在某张纸牌上播放时,它被选中,并创建了一个按钮,当按下该卡时将其发送到卡座,我在以下方面遇到了一些困难:

1-遵循8像素的比例和间距,使卡片填充任何设备的总宽度。

2-玩纸牌时,按钮没有出现在纸牌中间

3-只需触摸一下按钮,我便希望该卡过渡到屏幕顶部的绿色卡座,而其他卡则填补为卡座选择的卡所留下的空白。

我正在Windows 7上使用Corona 2018.3326,正在iOS上创建主要的基本应用程序,首先在iPhone 4S模拟器上进行测试

local composer = require( "composer" )
local widget = require("widget")

local scene = composer.newScene()

local mFloor = math.floor   
local myCardsRef, cards = {}, {}
local lastTappedCard
local navBar 
local scrollView
local deck
local sizeDeck = (display.contentHeight * 45 / 100) - 64
local title
local cardDeck1
local cardDeck2
local cardDeck3
local cardDeck4
local cardDeck5
local cardDeck6
local cardDeck7
local cardDeck8
local button

function scene:create( event )

    local sceneGroup = self.view

    navBar = display.newRect(sceneGroup,0, 0,display.contentWidth, 64)
    navBar.anchorX = 0
    navBar.anchorY = 0
    navBar:setFillColor(1,0,0)

    deck = display.newRect(sceneGroup,0, navBar.y + navBar.height,display.contentWidth, sizeDeck)
    deck.anchorX = 0
    deck.anchorY = 0
    deck:setFillColor(1,1,0)

    title = display.newText(sceneGroup,"Home",display.contentCenterX, navBar.y + navBar.height - 20,nil, 17)
    title:setFillColor(1,1,1)

    cardDeck1 = display.newRect(sceneGroup, 45,deck.y + 8,50,65)
    cardDeck1.anchorX = 0
    cardDeck1.anchorY = 0
    cardDeck1:setFillColor(0,1,0)

    cardDeck2 = display.newRect(sceneGroup, cardDeck1.x + cardDeck1.width + 8,deck.y + 8,50,65)
    cardDeck2.anchorX = 0
    cardDeck2.anchorY = 0
    cardDeck2:setFillColor(0,1,0)

    cardDeck3 = display.newRect(sceneGroup, cardDeck2.x + cardDeck2.width + 8,deck.y + 8,50,65)
    cardDeck3.anchorX = 0
    cardDeck3.anchorY = 0
    cardDeck3:setFillColor(0,1,0)

    cardDeck4 = display.newRect(sceneGroup, cardDeck3.x + cardDeck3.width + 8,deck.y + 8,50,65)
    cardDeck4.anchorX = 0
    cardDeck4.anchorY = 0
    cardDeck4:setFillColor(0,1,0)

    cardDeck5 = display.newRect(sceneGroup, 45,cardDeck1.y + cardDeck1.height + 8,50,65)
    cardDeck5.anchorX = 0
    cardDeck5.anchorY = 0
    cardDeck5:setFillColor(0,1,0)

    cardDeck6 = display.newRect(sceneGroup, cardDeck5.x + cardDeck5.width + 8,cardDeck1.y + cardDeck1.height + 8,50,65)
    cardDeck6.anchorX = 0
    cardDeck6.anchorY = 0
    cardDeck6:setFillColor(0,1,0)

    cardDeck7 = display.newRect(sceneGroup, cardDeck6.x + cardDeck6.width + 8,cardDeck1.y + cardDeck1.height + 8,50,65)
    cardDeck7.anchorX = 0
    cardDeck7.anchorY = 0
    cardDeck7:setFillColor(0,1,0)

    cardDeck8 = display.newRect(sceneGroup, cardDeck7.x + cardDeck7.width + 8,cardDeck1.y + cardDeck1.height + 8,50,65)
    cardDeck8.anchorX = 0
    cardDeck8.anchorY = 0
    cardDeck8:setFillColor(0,1,0)

scrollView = widget.newScrollView(
    {
      top = display.contentHeight - display.contentHeight * 55 / 100,
      left = 0,
      width = display.contentWidth,
      height = display.contentHeight * 55 / 100,
      scrollWidth = 600,
      horizontalScrollDisabled = true,
      scrollHeight = 1300,
      listener = scrollListener
    }
  ) 

  sceneGroup:insert(scrollView)

for i=1, 86 do

    cards[#cards + 1] = { 
        name = 'card'..i..'.png', 
        x    = 8 + ( i - 1 ) % 4 * 76,
        y    = 8 + ( mFloor( ( i - 0.5 ) / 4 ) * 98 ),
        w    = (display.contentWidth - 40) / 4,
        h    = 90
    }  
end 

print((scrollView.width - 40) / 4)

local function tap( self, event )

    if lastTappedCard then

        myCardsRef[lastTappedCard].alpha = 1
        button:removeSelf()
        button = nil

    end 

    myCardsRef[self].alpha = 0.5
    button = display.newRect(event.x,event.y, 50, 30)
    button:setFillColor(0,0,0)
    lastTappedCard = self

end

for index = 1, #cards do

  local card = display.newRect(cards[index].x,cards[index].y,cards[index].w,cards[index].h)
  card.anchorX = 0
  card.anchorY = 0
  card:setFillColor( 1, 0, 0 )
  card.tap = tap
  card:addEventListener( "tap" )
  scrollView:insert( card )

  myCardsRef[card] = card

end

end 

0 个答案:

没有答案