[solved]Why are my sprites translating with each other?

I have two sprites, one is called “Ninja” and the other is called “Enemy1” and of course the main file. The ninja works fine and is coded to go towards my finger like this:

Ninja = class()

function Ninja:init(ninjaX,ninjaY,ninjaD,fdistance)
    self.x = ninjaX
    self.y = ninjaY
    self.r = ninjaD
    self.f = fdistance
end

function Ninja:draw()
    ninjaD = math.atan(CurrentTouch.y - ninjaY,CurrentTouch.x - ninjaX)
    fdistance = math.sqrt(((CurrentTouch.x - ninjaX)^2)+((CurrentTouch.y - ninjaY)^2))

    -- this tells ninja to move when your touching
    if CurrentTouch.state == BEGAN or MOVING then
        -- this tells ninja the ratio of movement in the x vs y dimensions
        speedX = math.cos(ninjaD) * GameSpeed * (fdistance/64)
        speedY = math.sin(ninjaD) * GameSpeed * (fdistance/64)
    end
    
    -- this tells ninja not to move when you aren't touching
    if CurrentTouch.state == ENDED then
        speedX = 0
        speedY = 0
        fdistance = 0
    end
    
    ninjaX = ninjaX + speedX
    ninjaY = ninjaY + speedY
   
    translate(ninjaX,ninjaY)
    rotate(math.deg(ninjaD))
    pushMatrix()
    sprite("Project:Ninja")
    popMatrix()
end

The “Enemy1” however, does not work. It is supposed to stand in the middle of the screen and look towards “ninja”. Though instead it translates with “ninja”. When you move “ninja” it "stands on top of “ninja”.
Here is the code for the enemy:

Enemy1 = class()

function Enemy1:init(E1X,E1Y,E1D)
    self.x = E1X
    self.y = E1Y
    self.d = E1D
end
function Enemy1:draw()
    E1D =math.atan(ninjaY-E1Y,ninjaX-E1X)
    
    rotate(math.deg(E1D))
    pushMatrix()
    sprite("Project:Enemy")
    popMatrix()
    print(E1D,E1X,E1Y)
end

And for if the problem is in the main file, here is the code for that:

function setup()
    ninjaD = 90
    ninjaX = WIDTH/2
    ninjaY = HEIGHT/2
    fdistance = 0
    speedX = 0
    speedY = 0
    E1X = WIDTH/2
    E1Y = HEIGHT/2
    E1D = 0
    
    parameter.number("GameSpeed",1,5)
end
function draw()
    background(65, 91, 99, 255)
    Ninja:draw()
    
    Enemy1:draw()
end

Can somebody tell me why “Enemy1” translates with “Ninja” ?
Thank you in advance.

@PlatinumFrog Try this. I changed the sprites to Codea characters because I don’t have access to yours. Compare my code to yours for the changes I made.

EDIT:Your translate statements were in the wrong place.


Ninja = class()

function Ninja:init(ninjaX,ninjaY,ninjaD,fdistance)
    self.x = ninjaX
    self.y = ninjaY
    self.r = ninjaD
    self.f = fdistance
end

function Ninja:draw()
    ninjaD = math.atan(CurrentTouch.y - ninjaY,CurrentTouch.x - ninjaX)
    fdistance = math.sqrt(((CurrentTouch.x - ninjaX)^2)+((CurrentTouch.y - ninjaY)^2))

    -- this tells ninja to move when your touching
    if CurrentTouch.state == BEGAN or MOVING then
        -- this tells ninja the ratio of movement in the x vs y dimensions
        speedX = math.cos(ninjaD) * GameSpeed * (fdistance/64)
        speedY = math.sin(ninjaD) * GameSpeed * (fdistance/64)
    end

    -- this tells ninja not to move when you aren't touching
    if CurrentTouch.state == ENDED then
        speedX = 0
        speedY = 0
        fdistance = 0
    end
    ninjaX = ninjaX + speedX
    ninjaY = ninjaY + speedY
    pushMatrix()
    translate(ninjaX,ninjaY)
    rotate(math.deg(ninjaD))
    sprite("Planet Cute:Character Pink Girl")
    popMatrix()
end


Enemy1 = class()

function Enemy1:init(E1X,E1Y,E1D)
    self.x = E1X
    self.y = E1Y
    self.d = E1D
end
function Enemy1:draw()
    E1D =math.atan(ninjaY-E1Y,ninjaX-E1X)
    pushMatrix()
    translate(WIDTH/2,HEIGHT/2)
    rotate(math.deg(E1D))
    sprite("Planet Cute:Character Boy")
    popMatrix()
    --print(E1D,E1X,E1Y)
end

function setup()
    ninjaD = 90
    ninjaX = WIDTH/2
    ninjaY = HEIGHT/2
    fdistance = 0
    speedX = 0
    speedY = 0
    E1X = WIDTH/2
    E1Y = HEIGHT/2
    E1D = 0
    parameter.number("GameSpeed",1,5)
end
function draw()
    background(65, 91, 99, 255)
    Ninja:draw()
    Enemy1:draw()
end

Thanks! I will try it out…

It worked, I will remember to have pushmatrix() at the top of my translation/rotation calls.