当我单击它时,我正在尝试使用 spritesheet 来更改角色的图像,但是使用触摸会不止一次地运行该功能。这可能是一个愚蠢的问题,但我昨天开始了......这是代码,谢谢!:)
local sprite = require "sprite"
local changed = 0
local baseballfield = display.newImageRect("baseballfield.png",display.contentWidth,display.contentHeight)
baseballfield.x = display.contentWidth/2
baseballfield.y = display.contentHeight/2
local spritesheet = sprite.newSpriteSheet("spritesheet.png",119,152)
local players = sprite.newSpriteSet(spritesheet, 1, 2)
local firstbase = sprite.newSprite(players)
function changeFrame(event)
if firstbase.currentFrame == 1 then
firstbase.currentFrame = 2
changed = 1
end
if firstbase.currentFrame == 2 and changed == 0 then
firstbase.currentFrame = 1
changed = 1
end
changed = 0
end
firstbase:addEventListener("touch", changeFrame)'