Relative touch

Thanks Dave, although even my capabilities could merge those!

The starfield code really helps though, thank you.

I still want to display the static image below all this though and whilst this line does it correctly, I don’t get why the image also replaces the ship sprite…

sprite(imageBackground, WIDTH/2, HEIGHT/2, WIDTH, HEIGHT)

@RaggedTooth I’m not sure why you’re having trouble with the imageBackground line. Since I don’t have whatever you imageBackground is, I replaced it with the Cargo Bot image for this example. The ship moves and the background doesn’t.

displayMode(FULLSCREEN)

function setup()
    ship = Ship(vec2(WIDTH/2,HEIGHT/2), "Tyrian Remastered:Evil Orb")
end

function draw()
    background(40,40,50)
    sprite(asset.builtin.Cargo_Bot.Startup_Screen,WIDTH/2,HEIGHT/2,WIDTH,HEIGHT)
    ship:draw()
end

function touched(t)
    if ship:touched(t) then
        return
    end
end

Ship = class()

function Ship:init(p,s)
    self.position = p
    self.sprite = s
end

function Ship:draw()
    sprite(self.sprite, self.position.x,self.position.y)
end

function Ship:touched(t)
    if not self.inTouch then
        self.offset = self.position - vec2(t.x,t.y)
        self.inTouch = true
        self.touchid = t.id
        return true
    end
    if not self.touchid == t.id then
        return false
    end
    self.position = vec2(t.x,t.y) + self.offset
    if t.state == ENDED then
        self.inTouch = false
    end
    return true
end

It appears I’m not now. Just tried putting it back in and with the starfield code there it works.

Hmm.

Thank you.