スプライトシートを使用して、クリックしたときにキャラクターの画像を変更しようとしていますが、タッチを使用すると機能が複数回実行されます。これはばかげた質問かもしれませんが、私は昨日始めたので...これがコードです、ありがとう! :)
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)'