Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Is auto cull happens when sprite is out of view? — Gideros Forum

Is auto cull happens when sprite is out of view?

NascodeNascode Guru
edited August 2012 in General questions
Hello,

I am testing the performance of Gideros on term of displaying many sprites. Looks like there are no culling (getting rid of uneeded render) happens even when sprites are out of view. Should we do cull by ourself by using setVisible or removeChild?

Sample codes:
local texture = Texture.new('coin.png')
for i = 1,2000 do
	local coin = Bitmap.new(texture)
	coin:setPosition(-10000,-10000) -- try to get it out of viewable area, uneeded render
	stage:addChild(coin)
end
have fun with our games~
http://www.nightspade.com
Tagged:

Comments

  • atilimatilim Maintainer
    Accepted Answer
    exactly as you've said. culling is only implemented for tile maps.
  • NascodeNascode Guru
    edited August 2012
    @atilim would be lovely if we could set auto-cull of a sprite parent, which affecting every children of those sprite :)
    have fun with our games~
    http://www.nightspade.com
  • I understand "culling" to mean removing the sprite from the display list which would in turn mean that the sprite wouldn't then be drawn if it was moved BACK into view.

    What you need is an efficient manner of clipping sprites that are completely off screen (I suspect this is already implemented).

    @Atilim - is it more efficient to call :setVisible(false) when you know a sprite is offscreen or doesn't it make any difference?
    WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
    #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
  • @techdojo yes, efficient manner of clipping sprites off screen, in which this is currently not in Gideros yet according to @atilim , maybe culling is not correct word? Only tilemap got this support for now

    have fun with our games~
    http://www.nightspade.com
    +1 -1 (+2 / -0 )Share on Facebook
  • atilimatilim Maintainer
    I think culling (or more specifically view frustum culling) is the correct keyword here. We all mean "automatically (and efficiently) not drawing the sprites that are completely outside of the screen".

    @Atilim - is it more efficient to call :setVisible(false) when you know a sprite is offscreen or doesn't it make any difference?
    Yes it's more efficient. For example this code works faster:
    local texture = Texture.new('coin.png')
    for i = 1,2000 do
    	local coin = Bitmap.new(texture)
    	coin:setPosition(-10000,-10000) -- try to get it out of viewable area, uneeded render
    	coint:setVisible(false)
    	stage:addChild(coin)
    end
    Let me add this as a feature request.
  • That's good to know, thanks.
    WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
    #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
  • @atilim thank you for adding this as a feature request :)
    have fun with our games~
    http://www.nightspade.com
  • hnimhnim Member
    edited August 2012
    @atilim can you add new function that we can ignore sprite update (draw itself and its child) in code, ex: Sprite:setIgnoreUpdate(true/false) ?
    Thanks
  • @hnim - can you explain your request a bit further? what would be the use case for that?

    If you want to ignore the sprite update, then dont update it, if you don't want it to be drawn then use Sprite:setVisible(false)
    WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
    #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
  • hnimhnim Member
    oh, sorry. a bit confuse when i make my object pool. thanks techdojo :)
  • Sorry to bring back an old thread but I did some testing today on my game and using setVisible on any off-screen sprites has DRASTICALLY improved the performance of my game. As in I can't get it under 60fps on device testing.

    I made a class like this:
    SpritesOffScreen = Core.class(Sprite)
     
    function SpritesOffScreen:init(scene)
     
    	self.scene = scene
    	self:addEventListener(Event.ENTER_FRAME, self.cullOffScreenSprites, self)
     
    end
     
     
     
     
     
    function SpritesOffScreen:cullOffScreenSprites()
     
    	for i,v in pairs(self.scene.sprites) do
     
    		if(self.scene.playerMovement.heroX) then
     
    			local spriteX, spriteY = v:getPosition()
     
    			--print(self.scene.playerMovement.heroX)
     
    			local xDist = math.abs(self.scene.playerMovement.heroX - spriteX)
    			local yDist = math.abs(self.scene.playerMovement.heroY - spriteY)
     
    			if(xDist > 500 or yDist > 400) then
    				v:setVisible(false)
    			else
    				v:setVisible(true)
    			end
    		end
     
     
    	end
     
    end
    Basically just loop though every sprite and, if it's not on screen, use setVisible to turn it off. If you've got any game where you can use this, do! It saves LOADS of CPU!




    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • ar2rsawseenar2rsawseen Maintainer
    Wow @Tom2012
    nice to see you back in the game :)
    Better do something like that internally, and look also not for specific sprites, but the whole sprite trees to disable.
    But on the other hand, if it is not needed then looping from sprites will only take resources, and probably with LuaJIT it won't matter much if it is done natively or not :)

    Thanks for sharing ;)
Sign In or Register to comment.