Hey guys,
I’m just working on an project, where I want that one object, wich for I’ve created an own class and a draw function ,should appear on that spot you tap on.
I’ve heard something of table.insert but dont know how this actually works, so it would be very nice, if somebody can send me an example please.
Thank you very much
Here’s a short example that creates a new object when you touch the screen:
--# Main
-- Create Objects
function setup()
objects = {} -- creates a table for objects
end
function draw()
background(40, 40, 50)
for i, o in pairs(objects) do
o:draw() -- loop through your objects table and draw
end
end
function touched(touch)
if touch.state == BEGAN then
table.insert(objects,Object(touch.x,touch.y))
-- add a new object where you touch and put it in your object table
end
end
--# Object
Object = class()
function Object:init(x,y)
self.x = x
self.y = y
end
function Object:draw()
stroke(255, 255, 255, 255)
strokeWidth(5)
fill(29, 114, 133, 255)
ellipse(self.x,self.y,50)
end
Thank you very much thats very nice