I am fiddling around with the tutorial game (star explorer) and wanted to change the method of firing. Currently it uses the below method :
addEventListener("tap", fireLaser)
but I want to use the touch method so that I may tap and hold it. While holding I want it to continue to fire. I simply changed the above to:
ship:addEventListener( "touch", fireLaser )
I have 2 problems, and if they could be answered seperately to help me determine what is happening that would be great.
Problem 1. When using the touch method, it is firing extremely rapidly. I would love the ability to adjust the rate at which it fires while being held. Any ideas?
Problem 2. How do I get it to have the addEventListener to the ship and anything else on the screen (except future buttons). Meaning, how can I click and hold in the middle of the screen and it work instead of having to click specifically on the ship.
The above event listener is located in my scebe:Create right now according to the tutorial.
Below is the text that runs when it runs the function firelaser incase you need it.
local function fireLaser() -- Play fire sound! audio.play( fireSound ) local newLaser = display.newImageRect( mainGroup, objectSheet, 5, 14, 40 ) physics.addBody( newLaser, "dynamic", { isSensor=true } ) newLaser.isBullet = true newLaser.myName = "laser" newLaser.x = ship.x newLaser.y = ship.y newLaser:toBack() transition.to( newLaser, { y=-40, time=500, onComplete = function() display.remove( newLaser ) end } ) end