【发布时间】:2015-05-01 22:45:37
【问题描述】:
我不确定这是否是迄今为止最好的方法,但这是我想出的。我试图生成三个单词,每个单词都有自己的名字,这样它们就可以有一个单独的触摸事件。一个是正确的答案,另外两个是错误的,并且会发出相应的声音。 无论如何,我现在的挑战是试图将这三个单词均匀地分开,因为它们只是堆叠在一起。每个单词图像的大小相同(150x75)。如何让它们彼此均匀分开?
local content = require "content"
--chooses a random number according to the maximum number available in the table
local rnd = math.random
local maxSightwords = 3
print (rnd)
local wordIndex = rnd(1, #content)
print (wordIndex)
--on tap of a star the name of the star prints
local function wordTap (event)
print(event.target.name)
end
local function makeaWord()
--chooses a random word from the content table
local wordIndex = rnd(1, #content)
print (wordIndex)
local word = (content[wordIndex].word)
--uses the word index variable to get a random word image
local sightword = display.newImage("images/words/"..word..".png")
sightword.x = display.contentWidth/2
sightword.y = display.contentHeight/2
--sets the words name as the name of the word
sightword.name = word
sightword:addEventListener ("tap", wordTap)
print (wordIndex)
end
for v = 1, maxSightwords do
makeaWord (v)
end
makeaWord()
这是我尝试过的:
local content = require "content"
--chooses a random number according to the maximum number available in the table
local rnd = math.random
local maxSightwords = 3
local gap = 10 -- gap between words
local _w = display.contentWidth
local _h = display.contentHeight
local playOrder
local wordIndex = rnd(1, #content)
--on tap of a star the name of the star prints
local function wordTap (event)
print(event.target.name)
end
local function makeaWord(v)
--chooses a random word from the content table
local wordIndex = rnd(1, #content)
print (wordIndex)
local word = (content[wordIndex].word)
--uses the word index variable to get a random word image
local sightword = display.newImageRect("images/words/"..word..".png", 150, 75)
sightword.x = (_w/2-(sightword.contentWidth+gap))+((sightword.contentWidth+gap)*v)
sightword.y = display.contentHeight/2
--sets the words name as the name of the word
sightword.name = word
sightword:addEventListener ("tap", wordTap)
print (wordIndex)
end
for v = 1, maxSightwords do
makeaWord (v)
end
makeaWord()
单词接近我需要的位置,但我仍然收到错误,并且我还得到了右上角的第四个单词。
【问题讨论】:
标签: coronasdk