I decided to to try to make a homing projectile project, and have the character move around with WASD. But my visualParam for key does not run:
require "ssk2.loadSSK" \_G.ssk.init({enableAutoListeners = true}) local physics = require "physics" physics.start() local isWPressed = false local isAPressed = false local isSPressed = false local isDPressed = false function onKeyEvent( self, event ) local vx, vy = self:getLinearVelocity() if event.keyName == "a" then if event.phase == "down" then --transition.to(self, {time = 3000, x = self.x - (display.actualContentWidth / 2)}) isAPressed = true self:setLinearVelocity(-300, vy) elseif event.phase == "up" then --transition.cancel() isAPressed = false if isDPressed == true then self:setLinearVelocity(300, vy) else self:setLinearVelocity(0, vy) end end end if event.keyName == "d" then if event.phase == "down" then --transition.to(self, {time = 3000, x = self.x - (display.actualContentWidth / 2)}) isDPressed = true self:setLinearVelocity(300, vy) elseif event.phase == "up" then --transition.cancel() isDPressed = false if isAPressed == true then self:setLinearVelocity(-300, vy) else self:setLinearVelocity(0, vy) end end end if event.keyName == "w" then if event.phase == "down" then --transition.to(self, {time = 3000, x = self.x - (display.actualContentWidth / 2)}) isWPressed = true self:setLinearVelocity(vx, -300) elseif event.phase == "up" then --transition.cancel() isWPressed = false if isSPressed == true then self:setLinearVelocity(vx, 300) else self:setLinearVelocity(vx, 0) end end end if event.keyName == "s" then if event.phase == "down" then --transition.to(self, {time = 3000, x = self.x - (display.actualContentWidth / 2)}) isSPressed = true self:setLinearVelocity(vx, 300) elseif event.phase == "up" then --transition.cancel() isSPressed = false if isWPressed == true then self:setLinearVelocity(vx, -300) else self:setLinearVelocity(vx, 0) end end end end local target = ssk.display.newRect(nil, centerX, centerY, {key = onKeyEvent}, {gravityScale = 0})
What am I missing?
I placed print statements to check if the function was being called, but nothing was printed.