Tween Help

I am new to Codea and Lua but thanks to some great tutorials by @Ignatz I am well on my way to creating a Tower Defense game.

Where I am running into problems is using the Tween function and maybe I am just using it wrong. What I am trying to do is tween a sprite from the tower to the enemy but the sprite just sits over the tower. If I try to tween a sprite in a separate project it works just fine. Am I trying to do something that the original function was not intended to be used for?

I attached a YouTube video so you can see what I am creating I have the tween disabled in this video.

We’re going to need to see at least the tween code to try and see the problem

This is the code from the tower class which handles the shooting.

-- Draws Defense Tower and Calculates Shots --

Tower = class()

function Tower:init(x, y)
    -- you can accept and set parameters here
    self.x = x                          -- Tower X location
    self.y = y                          -- Tower Y location
    self.shot = false                   -- Whether tower Shot
    self.shottimer = math.random(1,5)   -- Set time delay on Tower Shot

function Tower:Shoot(locx, locy, Radius, EnemyHit)
       if locx > self.x - Radius and locx < self.x + Radius and locy > self.y - Radius and locy < self.y + Radius and -- Test Enemy in Range
           ElapsedTime >= self.shottimer and EnemyHit.Health > 0 then -- Test Shot Timer and Enemy Health
             self.origin = {x = self.x, y = self.y} -- Tower Location
    = {x = locx, y = locy} -- Enemy location
             -- Tween.Path bullet test did not work
             -- tween.path(4, self.origin, {self.origin,})
             -- sprite("Space Art:Green Bullet", self.origin.x, self.origin.y, 10, 10)
             -- Tower Laser
             stroke(234, 25, 53, 255)
             line(self.origin.x, self.origin.y,,
             self.shottimer = self.shottimer + math.random(1,5) -- Delay before next shot
             EnemyHit.Health = EnemyHit.Health - 20 -- Add damage to Enemy

function Tower:draw()
    -- Codea does not automatically call this method
    sprite("Small World:Watch Tower", self.x, self.y, 50, 50) -- Current tower Sprite
    -- Extra Towers
    -- sprite("Small World:Church", 19 * 50 - 13, 35, 50, 50)
    -- sprite("Small World:Fountain", 18 * 50 - 13, 35, 50, 50)
    -- sprite("Small World:Observatory", 17 * 50 - 13, 35, 50, 50)

function Tower:touched(touch)
    -- Codea does not automatically call this method
    return false

I have expanded on this class but this was the last time I tried to get Tween to work.

@romspy Are you trying to do something like this. Tap the screen to start the tween.

function setup()

function draw()
    background(40, 40, 50)
    sprite("Space Art:Red Ship",100,300)
    sprite("Small World:Tower",300,700)
    if obj~=nil then
        sprite("Space Art:Green Explosion",obj.x,obj.y)

function touched(t)
    if t.state==BEGAN and obj==nil then
        tween(1,obj,{x=100,y=300},tween.easing.linear,function() obj=nil end)       

Try something like this: tween(4, self, { x = locx, y = locy }). You are misusing tween.path from what I read.

@dave1707 yes that is what I want without the need to tap first.

@JakAttak That would just move the tower not a “new” bullet object between the two but I think I see what you mean about using it wrong.

Thanks for the help!

@romspy I just had it in the touched function to be able to control when it started. If that’s what you can use, then you’ll have to put the code where you need it since I didn’t see your code when I did this.

@romspy, sorry about that I hadn’t read very closely obviously

@romspy After watching your video, you should look into rotating the ships so they point in the direction they’re moving.

@dave1707 That’s one of the many changes I still have to do. I would put the game at around 60% done.