Ich mache ein Spiel mit Corona SDK, das die Physik-Engine nutzt und einen ziemlich nervigen Fehler erlebt: Jedes Mal, wenn ich einen Asteroiden treffe und die Zurück-Taste drücke, wird der Playback erneut gedrückt Sprungwert.Corona Gravity Glitch
Ich würde jede und alle Hilfe schätzen !!
Hier ist mein Code:
Hauptdatei:
local Physics = require("physics")
Physics.start()
centerX = display.contentCenterX
centerY = display.contentCenterY
myScene = require("scene")
myHero = require("hero")
myGoomba = require("badguy")
myButtons = require("buttons")
myMenu = require("mainmenu")
myMenu.drawMainMenu()
playButton:addEventListener("tap", myMenu.play)
MainMenu:
local mainmenu = {}
local Physics = require("physics")
Physics.start()
function mainmenu.drawMainMenu()
menuTheme = audio.loadStream("Music/menuTheme.ogg")
menuThemeChannel = audio.play(menuTheme, { channel=1, loops=-1, fadein=3000 })
background = display.newImage("menuBackground.png")
background.x = display.contentCenterX
background.y = display.contentCenterY
background:scale(1.2, 1.2)
playButton = display.newImage("playButton.png")
playButton.x = display.contentCenterX
playButton.y = display.contentCenterY - 75
playButton:scale(.3, .3)
end
function mainmenu.play()
print("mainmenu - tap registered, preparing to load game..")
audio.stop(1)
myScene.sayHello()
myScene.drawScene()
myHero.sayHello()
myHero.drawHero()
myGoomba.hello()
myGoomba.drawBadGuy()
myButtons.sayHello()
myButtons.drawButtons()
myGoomba.move()
gameTheme = audio.loadStream("Music/playTheme.ogg")
gameThemeChannel = audio.play(gameTheme, { channel=2, loops=-1, fadein=0 })
jumpButton:addEventListener("tap", myButtons.jump)
backButton:addEventListener("tap", myButtons.goBack)
end
function mainmenu.sayHello()
print("mainmenu - Hello....")
end
return mailmen
Buttons:
local buttons = {}
local Physics = require("physics")
Physics.start()
function buttons.drawButtons()
jumpButton = display.newImage("button.png")
jumpButton.x = 473
jumpButton.y = 305
jumpButton:scale(.2, .7)
slideButton = display.newImage("button.png")
slideButton.x = 5
slideButton.y = 305
slideButton:scale(.2, .7)
backButton = display.newImage("backButton.png")
backButton.x = display.contentCenterX - 245
backButton.y = display.contentCenterY - 100
backButton:scale(.11, .11)
end
function buttons.jump()
--work on decreasing air time by increasing gravity...
instance2:applyLinearImpulse(0, -0.12, instance2.x, instance2.y)
--Applying 0 force in the X direction and -0.12 in the Y direction. Y is negative because
--down is considered positive by the physics engine.
--Apply force to the center of the green guy, hence instance.x & instance.y
end
function buttons.goBack()
print("buttons - loading main menu...")
audio.stop(2)
myMenu.drawMainMenu()
--reset gravity and jump-impulse values here
end
function buttons.sayHello()
print("buttons - Hello....")
end
return buttons
Hero:
local hero = {}
local Physics = require("physics")
Physics.start()
function hero.drawHero()
print("hero - loading hero...")
greenGuysheet = graphics.newImageSheet("greenman.png", { width=128, height=128, numFrames=15 })
-- play 15 frames every 500 ms
instance2 = display.newSprite(greenGuysheet, {start=1, count=15, time=500 })
instance2.name = "greenGuy"
Physics.addBody(instance2, "dynamic", {radius = 20, bounce = 0})
instance2.x =100
instance2.y = 260
instance2.gravityScale = 2.5
instance2:play()
end
function hero.sayHello()
print("hero - Hello....")
end
return hero
Also die Tatsache, dass ich Event Listener nicht entfernt, wenn die "Zurück" Taste gedrückt wurde, verursachte den Sprung Glitch? –
Meiner Meinung nach gibt es zwei Lösungen für Ihr Problem. Alles erwähnt in meiner Antwort oben. – ldurniat
Antwort für Ihre letzte Frage ist ja. – ldurniat