Insert a timer into a display.newRect Object

Good day,

I was wondering if it is possible to insert a timer on my Rectangle Object?

my objective is achieve the same function and behavior like this one, but only using a timer:

local function muRuntime(event) print("RUNTIME FUNCTION") end local a = display.newRect(\_W/2,\_H/2,100,100) a.enterFrame = muRuntime Runtime:addEventListener("enterFrame",a)

Yes, you can put a listener for just about anything on any object:

local rect = display.newRect( 200, 200, 100, 100 ) function rect:timer() print( "Just some string." ) end timer.performWithDelay( 1000, rect, 0 )

This should call the timer() function on the rect object once every second.

oh okay thank you :slight_smile:

Really helped! :slight_smile:

Yes, you can put a listener for just about anything on any object:

local rect = display.newRect( 200, 200, 100, 100 ) function rect:timer() print( "Just some string." ) end timer.performWithDelay( 1000, rect, 0 )

This should call the timer() function on the rect object once every second.

oh okay thank you :slight_smile:

Really helped! :slight_smile: