I am a bit confused with the lastTime variable. I tried looking at this article:
https://coronalabs.com/blog/2013/06/18/guest-tutorial-delta-time-in-corona/
But I don’t think that is correct, or I just did not do it right. When I run this, the bullet does not move, and there are no error messages, just the target in the middle. This is the code:
require "ssk2.loadSSK" \_G.ssk.init() local function enterFrame(self) local vec = ssk.math2d.diff( self.tx, self.ty, self.x, self.y, true ) local len = ssk.math2d.length(vec) if( len \<= 0.05 ) then ignore("enterFrame", self) display.remove(self) return end vec = ssk.math2d.normalize(vec) local lastTime = 0 local curTime = system.getTimer() local dt = curTime - lastTime self.lastTime = curTime local dr = self.rotRate \* dt / 1000 local dm = self.moveRate \* dt / 1000 if( dm \> 0.05 ) then ignore("enterFrame", self) display.remove(self) return end vec = ssk.math2d.scale( vec, dm ) self.x = vec.x self.y = vec.y end local target = display.newCircle(centerX, centerY, 15) target:setFillColor(0.39, 0.16, 0.74) local bullet = ssk.display.newImageRect( target.group, 800, 800, "arrow.png", { size = 25, rotation = angle, myType = "bullet", fill = \_R\_ }) bullet.tx = target.x bullet.ty = target.y bullet.rotRate = 90 -- rotate about target at 90-degrees per second bullet.moveRate = 200 -- move at 200 pixels per second bullet.enterFrame = enterFrame bullet:addEventListener("enterFrame", bullet)
Also, what is .tx and .ty? Is it supposed to represent a certain value? Or is it supposed to be left alone?