Ich erstelle ein Platformer-ähnliches Spiel wie Mario Brothers und bin auf ein großes Problem gestoßen. Mein Problem ist, dass, wenn ich auf den Richtungstasten klicke und den Mauszeiger ziehe, der Charakter sich bewegt, obwohl ich den Klick losgelassen habe. Ich habe diese Frage bereits im Corona-Forum gepostet und konnte nicht zu einer Lösung kommen.Der Charakter bewegt sich weiter, nachdem er einen Richtungsschlüssel weggeschoben hat.
Hier ist mein Code:
local function makeControls(event)
if anim.isJumping == false then
if event.phase == "began" then
if event.target.isPressed == false then
if event.target.id == "left" then
walk(-1)
elseif event.target.id == "right" then
walk(1)
end
end
event.target.isPressed = true
elseif (event.phase == "moved" and event.target.isPressed == true) then
if (
event.x > event.target.contentBounds.xMin+4 and
event.x < event.target.contentBounds.xMax-4 and
event.y > event.target.contentBounds.yMin+4 and
event.y < event.target.contentBounds.yMax-4
) then
event.target:dispatchEvent({ name="touch", phase="began", target=event.target })
else
event.target:dispatchEvent({name = "touch", phase = "ended", target = event.target })
end
elseif event.phase == "ended" then
anim:setLinearVelocity(0,0)
event.target.isPressed = false
end
end
return true
end
local function createArrowKey(group, x, y, rotation, name)
local newButtonBoundary = display.newRoundedRect(group, x, y, 75, 75, 12)
newButtonBoundary.strokeWidth = 6
newButtonBoundary:setStrokeColor(1, 1, 1, 0.5)
newButtonBoundary:setFillColor(1, 1, 1, 0.2)
newButtonBoundary.id = name
newButtonBoundary:addEventListener("touch", makeControls)
newButtonBoundary.isPressed = false
local newArrow = display.newPolygon(group, x, y, { 0, -24, 24, 24, -24, 24 })
newArrow.rotation = rotation
newArrow.strokeWidth = 3
end
createArrowKey(parent2, left + fullw/3, bottom - fullh/5.5, 90, "right")
createArrowKey(parent2, left + fullw/5.5, bottom - fullh/5.5, 270, "left")
createArrowKey(parent2, left + fullw/3.88, bottom - fullh/8.5, 180, "down")
createArrowKey(parent2, left + fullw/3.88, bottom - fullh/3.9, 0, "up")
createButton(parent2, left + fullw - 150, bottom - fullh/5.5, "Shoot", "shoot")
createButton(parent2, left + fullw - 250, bottom - fullh/5.5, "Throw", "throw")
createButton(parent2, left + fullw - 350, bottom - fullh/5.5, "Melee", "melee")
Vielleicht [JoyKey und vjoy von Ponywolf] versuchen (https://github.com/ponywolf/joykey). – ldurniat
Ich habe versucht, aber ich konnte nie die linke und rechte Bewegung zur Arbeit bekommen. – alexjr
Warum funktioniert die linke und die rechte Bewegung nicht? – ldurniat