Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Super fast sprites — Gideros Forum

Super fast sprites

RamaBotRamaBot Member
edited July 2016 in General questions

I think that with a little work the particle system could be easily adapted to create a nice lean mean super fast sprite system.

I would think that a lean sprite system based on a single texture using texture regions would be faster than the one we have. ( Which is quite fast )

A bunch of sprites would be associated with a single mesh and texture. This would save on primitive draws and texture swapping.

Also moving speed and some sort of gravity settings, as well as acceleration into the system would take the load off lua.

Removing individual sprites from the view hierarchy would reduce processing time. We could have tons of sprites flying all over the place.

thoughts?






http://www.devwilliams.com - Check out our games, including Codewords Infinite and Super Teddy Bubble Pop made with Gideros

Comments

  • SinisterSoftSinisterSoft Maintainer
    Do you mean being able to specify the x,y,w,h of the individual particle texture within the main particle texture?
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • Yup. Setting the uv's of the quads.
    http://www.devwilliams.com - Check out our games, including Codewords Infinite and Super Teddy Bubble Pop made with Gideros
  • SinisterSoftSinisterSoft Maintainer
    Maybe @hgy29 could put the in, it's early days for the particle stuff. :)
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • antixantix Member
    edited July 2016
    You can create a pure lua particle system. If you use a pool of sprites and as you mentioned, texture region swapping from one large texture you can get some pretty good results. My latest particle system can have hundreds of particles whizzing about and very quickly.

    Sprite pooling and TextureRegion swapping are the key things that make them very fast.

    As a side note it would be good to see the MovieClip class get some attention. Check this example from my game..
      local frames = {
        Bitmap.new(pack:getTextureRegion("coin1.png")), -- 1 Coin
        Bitmap.new(pack:getTextureRegion("coin2.png")),
        Bitmap.new(pack:getTextureRegion("coin3.png")),
        Bitmap.new(pack:getTextureRegion("coin4.png")),
        Bitmap.new(pack:getTextureRegion("coin5.png")),
        Bitmap.new(pack:getTextureRegion("coin6.png")),
        Bitmap.new(pack:getTextureRegion("coin7.png")),
        Bitmap.new(pack:getTextureRegion("coin8.png")),
        Bitmap.new(pack:getTextureRegion("coin9.png")),
        Bitmap.new(pack:getTextureRegion("coin10.png")),
     
        Bitmap.new(pack:getTextureRegion("star1.png")), -- 11 Star
        Bitmap.new(pack:getTextureRegion("star2.png")),
        Bitmap.new(pack:getTextureRegion("star3.png")),
        Bitmap.new(pack:getTextureRegion("star4.png")),
        Bitmap.new(pack:getTextureRegion("star5.png")),
        Bitmap.new(pack:getTextureRegion("star6.png")),
        Bitmap.new(pack:getTextureRegion("star7.png")),
        Bitmap.new(pack:getTextureRegion("star8.png")),
        Bitmap.new(pack:getTextureRegion("star9.png")),
        Bitmap.new(pack:getTextureRegion("star10.png")),
     
        Bitmap.new(pack:getTextureRegion("heart1.png")), -- 21 Heart
        Bitmap.new(pack:getTextureRegion("heart2.png")),
        Bitmap.new(pack:getTextureRegion("heart3.png")),
        Bitmap.new(pack:getTextureRegion("heart4.png")),
        Bitmap.new(pack:getTextureRegion("heart5.png")),
        Bitmap.new(pack:getTextureRegion("heart6.png")),
        Bitmap.new(pack:getTextureRegion("heart7.png")),
        Bitmap.new(pack:getTextureRegion("heart8.png")),
        Bitmap.new(pack:getTextureRegion("heart9.png")),
        Bitmap.new(pack:getTextureRegion("heart10.png")),
     
        Bitmap.new(pack:getTextureRegion("shield1.png")), -- 31 shield
        Bitmap.new(pack:getTextureRegion("shield2.png")),
        Bitmap.new(pack:getTextureRegion("shield3.png")),
        Bitmap.new(pack:getTextureRegion("shield4.png")),
        Bitmap.new(pack:getTextureRegion("shield5.png")),
        Bitmap.new(pack:getTextureRegion("shield6.png")),
        Bitmap.new(pack:getTextureRegion("shield7.png")),
        Bitmap.new(pack:getTextureRegion("shield8.png")),
        Bitmap.new(pack:getTextureRegion("shield9.png")),
        Bitmap.new(pack:getTextureRegion("shield10.png")),
     
        Bitmap.new(pack:getTextureRegion("2x1.png")), -- 41 2x
        Bitmap.new(pack:getTextureRegion("2x2.png")),
        Bitmap.new(pack:getTextureRegion("2x3.png")),
        Bitmap.new(pack:getTextureRegion("2x4.png")),
        Bitmap.new(pack:getTextureRegion("2x5.png")),
        Bitmap.new(pack:getTextureRegion("2x6.png")),
        Bitmap.new(pack:getTextureRegion("2x7.png")),
        Bitmap.new(pack:getTextureRegion("2x8.png")),
        Bitmap.new(pack:getTextureRegion("2x9.png")),
        Bitmap.new(pack:getTextureRegion("2x10.png")),
     
        Bitmap.new(pack:getTextureRegion("3x1.png")), -- 51 3x
        Bitmap.new(pack:getTextureRegion("3x2.png")),
        Bitmap.new(pack:getTextureRegion("3x3.png")),
        Bitmap.new(pack:getTextureRegion("3x4.png")),
        Bitmap.new(pack:getTextureRegion("3x5.png")),
        Bitmap.new(pack:getTextureRegion("3x6.png")),
        Bitmap.new(pack:getTextureRegion("3x7.png")),
        Bitmap.new(pack:getTextureRegion("3x8.png")),
        Bitmap.new(pack:getTextureRegion("3x9.png")),
        Bitmap.new(pack:getTextureRegion("3x10.png")),
     
        Bitmap.new(pack:getTextureRegion("token1.png")), -- 61 token
        Bitmap.new(pack:getTextureRegion("token2.png")),
        Bitmap.new(pack:getTextureRegion("token3.png")),
        Bitmap.new(pack:getTextureRegion("token4.png")),
        Bitmap.new(pack:getTextureRegion("token5.png")),
        Bitmap.new(pack:getTextureRegion("token6.png")),
        Bitmap.new(pack:getTextureRegion("token7.png")),
        Bitmap.new(pack:getTextureRegion("token8.png")),
        Bitmap.new(pack:getTextureRegion("token9.png")),
        Bitmap.new(pack:getTextureRegion("token10.png")),
      }
    Creating so many bitmaps just to animate one sprite might work (and it does) but isn't it terribly inefficient? One bitmap and some TextureRegions could accomplish the same goal, whilst being more efficient and quicker.

    I haven't installed the latest version of Gideros yet but will have a look at the new particle feature soon :)
  • SinisterSoftSinisterSoft Maintainer
    Just curious, but why do you do it that way and not with a loop?
    local frames={}
    local files={"coin","star","heart","shield","2x","3x","token"}
    for loop=1,10 do
      frames[loop]={}
      for loop2=1,#files do
        frames[loop][loop2]=Bitmap.new(files[loop2]..loop..".png")
      end
    end

    Likes: antix, keszegh, talis

    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
    +1 -1 (+3 / -0 )Share on Facebook
  • antixantix Member
    Probably because I wasn't thinking very hard about it =))

    Thanks for improving it, I'll go and implement that this morning ;)

    Likes: SinisterSoft

    +1 -1 (+1 / -0 )Share on Facebook
  • totebototebo Member
    edited July 2016
    For fixed frame rate animations, I use this helper method to load bitmaps in a sequence:
    function MovieClip.newFromBitmapSequence( texturePack, base_filename, frame_duration, loop, reverse )
     
    	local texture
    	local i=1
    	local bitmaps = {}	
     
    	repeat
    		texture = texturePack:getTextureRegion(base_filename..i..".png")
    		if texture then
    			local bitmap = Bitmap.new(texture)
    			insert(bitmaps, bitmap)
    		end
    		i = i+1
    	until texture == nil	
     
    	local timeline = {}
    	local first_frame 
    	local last_frame 
    	local count
     
    	if reverse then
    		first_frame = #bitmaps
    		last_frame = 1
    		count = -1
    	else
    		first_frame = 1
    		last_frame = #bitmaps
    		count = 1
    	end
     
    	for i=first_frame, last_frame, count do
    		local start_frame = (i-1)*frame_duration+1
    		local end_frame = i*frame_duration
    		local frame = {start_frame, end_frame, bitmaps[i]}
    		insert(timeline, frame)
    	end
     
    	if #timeline == 0 then
    		print( "MovieClip.newFromBitmapSequence(): Error: Missing file: " .. base_filename )
    	end
     
    	local mc = MovieClip.new(timeline)
    	local total_frames = frame_duration*#bitmaps
     
    	if loop == true then
    		mc:setGotoAction(total_frames, 1)
    	end
     
    	mc.isLooping =
    		function()
    			return loop == true
    		end	
     
    	return mc
     
    end
    To load a one-shot animation with the filenames "explosion1.png", "explosion2.png", [ .. ], "explosion14.png" with each bitmap showing for 4 frames:
    local mc_explosion = MovieClip.newFromBitmapSequence( texturePack, "explosion", 4, false )
    My Gideros games: www.totebo.com
    +1 -1 (+2 / -0 )Share on Facebook
  • SinisterSoftSinisterSoft Maintainer
    That was just code I typed in the forum directly, not tested, it should work though. :)
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • SinisterSoftSinisterSoft Maintainer
    If you want it to be a single array rather than a double array you should put something like:
    [((loop-1)*10)+loop2]
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • antixantix Member
    Thanks for getting my brain chugging @SinisterSoft, it's been a cold frosty morning here :)

    I boiled it down a wee bit further too..
      local frames={}
      local files={"coin", "star","heart","shield","2x","3x","token"}
      for i = 1, #files do
        for j = 1, 10 do
          frames[#frames + 1] = Bitmap.new( pack:getTextureRegion(files[i]..j..".png")) 
        end
      end
    p.s, I must have forgotten to press "post message" this morning too LOL

    Likes: SinisterSoft

    +1 -1 (+1 / -0 )Share on Facebook
  • SinisterSoftSinisterSoft Maintainer
    yes, that is better. :)
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
Sign In or Register to comment.