Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
How to do movieClips with a for loop — Gideros Forum

How to do movieClips with a for loop

Tom2012Tom2012 Guru
edited December 2013 in General questions
Hello everyone,

An obvious question but how do you cut back on the mass of code generated by movieClip animations?

I'm trying to figure out how to do it in a for loop. Has anyone tried this yet?

Thanks



... example:
	-- Create splat animation
 
	local frame1 = Bitmap.new(self.scene.atlas[5]:getTextureRegion("bullet splat 0001.png"))
	frame1:setAnchorPoint(.5,.5)
 
	local frame2 = Bitmap.new(self.scene.atlas[5]:getTextureRegion("bullet splat 0002.png"))
	frame2:setAnchorPoint(.5,.5)
 
	local frame3 = Bitmap.new(self.scene.atlas[5]:getTextureRegion("bullet splat 0003.png"))
	frame3:setAnchorPoint(.5,.5)
 
	local frame4 = Bitmap.new(self.scene.atlas[5]:getTextureRegion("bullet splat 0004.png"))
	frame4:setAnchorPoint(.5,.5)
 
	local frame5 = Bitmap.new(self.scene.atlas[5]:getTextureRegion("bullet splat 0005.png"))
	frame5:setAnchorPoint(.5,.5)
 
	local frame6 = Bitmap.new(self.scene.atlas[5]:getTextureRegion("bullet splat 0006.png"))
	frame6:setAnchorPoint(.5,.5)
 
	local frame7 = Bitmap.new(self.scene.atlas[5]:getTextureRegion("bullet splat 0007.png"))
	frame7:setAnchorPoint(.5,.5)
 
	local mc = MovieClip.new{
		{1, 3, frame1},
		{3, 6, frame2},
		{6, 9, frame3},
		{9, 12, frame4},
		{12, 15, frame5},
		{15, 100, frame7},
	}

Comments

  • ar2rsawseenar2rsawseen Maintainer
    edited December 2013
    something like this could work:
    local t = {}
    local bmp
    for i = 1, 7 do
        bmp = Bitmap.new(self.scene.atlas[5]:getTextureRegion("bullet splat 000"..i..".png"))
        bmp:setAnchorPoint(.5,.5)
        t[#t+1] = {(i-1)*3, i*3, bmp}
    end
    local mc = MovieClip.new(t)
    ;)

    Likes: chipster123

    +1 -1 (+1 / -0 )Share on Facebook
  • As always, THANK YOU! :D
  • NinjadoodleNinjadoodle Member
    edited October 2015
    Hi guys

    I've been looking for a way to cut down my movie clip code (just like in this post), but no matter what I try, I can't get this working.

    I have 14 images, and I set up an mc going from 1 - 14 then back to 1.

    this is the long code ...
    local frames = {}
     
    	frames[1] = Bitmap.new(pack1:getTextureRegion("lightbulbAnim0001.png", true))
    	frames[2] = Bitmap.new(pack1:getTextureRegion("lightbulbAnim0002.png", true))
    	frames[3] = Bitmap.new(pack1:getTextureRegion("lightbulbAnim0003.png", true))
    	frames[4] = Bitmap.new(pack1:getTextureRegion("lightbulbAnim0004.png", true))
    	frames[5] = Bitmap.new(pack1:getTextureRegion("lightbulbAnim0005.png", true))
    	frames[6] = Bitmap.new(pack1:getTextureRegion("lightbulbAnim0006.png", true))
    	frames[7] = Bitmap.new(pack1:getTextureRegion("lightbulbAnim0007.png", true))
    	frames[8] = Bitmap.new(pack1:getTextureRegion("lightbulbAnim0008.png", true))	
    	frames[9] = Bitmap.new(pack2:getTextureRegion("lightbulbAnim0009.png", true))
    	frames[10] = Bitmap.new(pack2:getTextureRegion("lightbulbAnim0010.png", true))
    	frames[11] = Bitmap.new(pack2:getTextureRegion("lightbulbAnim0011.png", true))
    	frames[12] = Bitmap.new(pack2:getTextureRegion("lightbulbAnim0012.png", true))
    	frames[13] = Bitmap.new(pack2:getTextureRegion("lightbulbAnim0013.png", true))
    	frames[14] = Bitmap.new(pack2:getTextureRegion("lightbulbAnim0014.png", true))
     
    	for key,value in pairs(frames) do
    		frames[key]:setAnchorPoint(0.5, 0)
    	end
     
    	self.lightbulbAnim = MovieClip.new{
    		{1, 1, frames[1]}, 
    		{2, 2, frames[2]},
    		{3, 3, frames[3]},
    		{4, 4, frames[4]},
    		{5, 5, frames[5]},
    		{6, 6, frames[6]},
    		{7, 7, frames[7]},
    		{8, 8, frames[8]},
    		{9, 9, frames[9]},
    		{10, 10, frames[10]},
    		{11, 11, frames[11]},
    		{12, 12, frames[12]},
    		{13, 13, frames[13]},
    		{14, 14, frames[14]},
    		{15, 15, frames[13]},
    		{16, 16, frames[12]},
    		{17, 17, frames[11]},
    		{18, 18, frames[10]},
    		{19, 19, frames[9]},
    		{20, 20, frames[8]},
    		{21, 21, frames[7]},
    		{22, 22, frames[6]},
    		{23, 23, frames[5]},
    		{24, 24, frames[4]},
    		{25, 25, frames[3]},
    		{26, 26, frames[2]},
    		{27, 27, frames[1]},
    	}
    and this is the new code I have, struggling with the part where I add the frames / make a movie clip.
    local frames = {}
    	local bmp
    	for i = 1, 14 do
    		if (i<10) then
    			bmp = Bitmap.new(pack1:getTextureRegion("lightbulbAnim000"..i..".png"))
    		else 
    			bmp = Bitmap.new(pack1:getTextureRegion("lightbulbAnim00"..i..".png"))
    		end
     
    		bmp:setAnchorPoint(.5, 0)
    		frames[i] = bmp
    	end
    Any help would be absolutely awesome!

    Thank you in advance!
  • piepie Member
    @Ninjadoodle if your long code works, I'd say that the problem could be here:
    frames[8] = Bitmap.new(pack1:getTextureRegion("lightbulbAnim0008.png", true))	
    	frames[9] = Bitmap.new(pack2:getTextureRegion("lightbulbAnim0009.png", true))
    	frames[10] = Bitmap.new(pack2:getTextureRegion("lightbulbAnim0010.png", true))
    number 9 is in pack2 but in your short code falls in i<10 so it is taken from pack1, while the other option of your short code still use pack1 as texture pack instead of pack2
  • NinjadoodleNinjadoodle Member
    edited October 2015
    Hi @pie

    Thank you for pointing that out!!

    I made some errors in the code and I think I got it working now :)
Sign In or Register to comment.