Does Corona/Lua have an equivalent to this or self?
For example I want to make an object that moves itself. I created a function to create these objects.
Here’s what I have:
function Bug()
local b = display.newCircle(0, 0, 15)
b.direction = math.random(math.pi\*2)
b.deviation = math.random()
b.speed = math.random(1, 3)
b:setFillColor(255, 60, 0)
return b
end
Here’s where I’d like to go:
function Bug()
local b = display.newCircle(0, 0, 15)
b.direction = math.random(math.pi\*2)
b.deviation = math.random()
b.speed = math.random(1, 3)
b.move = function()
this.x = this.x + this.speed
this.y = this.y + this.speed
end
b:setFillColor(255, 60, 0)
return b
end
[import]uid: 98652 topic_id: 19075 reply_id: 319075[/import]