Determining whether a sprite is in the display list

Is there a convenient way to determine whether a sprite is in the display list (that is, add() has been called, and remove() hasn't been subsequently called) short of looping through the list of all sprites in attempt to find it?


The SDK provides a way to do this here.

Edit: I forgot to add that this returns an array. You could copy the list and then iterate through it to see if any of its values match something you want to find.

Sorry, I might not have been clear. I'm aware of how to do this by looping through the list returned by that function. I'm asking if that's the only way to do it, or if there's something more convenient, along the lines of mySprite.added or mySprite:isDisplayed(), etc. ?

Invisible sprites still remain in the display list, so that doesn’t provide the info I’m looking for.

Looks like we don't currently have a function that can tell you that; I've filed a feature request, will be easy to add. In the mean time you could override the current add/remove functions to add that (:firecracker: untested code follows):

local spritelookup = {}
local _spriteadd =
local _spriteremove = = function(s)
  spritelookup[s] = true
end = function(s)
  spritelookup[s] = nil
end = function(s)
  return spritelookup[s] ~= nil