Start offset for go.animate()

Hi!

When you trigger a particle effect there’s a handy start offset option.

Has anyone ever done the same thing with go.animate()? It’s extra hard in my case because I am using ping-pong-loop.

What are you animating? A script property or something else?

Hi!

I’m animating position.y of around 60 GOs in order to create a wave effect.

I’ve coded this now and it’s working fine:

function init(self)
	self.count = {}
	self.speed = 0.02
	self.ydistance = 50
	self.spritewidth = 11
	self.numberofparents = 60
	self.offset = 5
	for i = 1,self.numberofparents do
		self.count[i] = (self.speed + (i/self.offset))
		go.set("left"..i,"position.x", self.spritewidth*-(i-1))
		go.set("right"..i,"position.x", self.spritewidth*(i-1))
	end
end

function update(self, dt)
	for i = 1,self.numberofparents do
		self.count[i] = self.count[i]+self.speed
		go.set("parent"..i, "position.y", (math.sin(self.count[i])*self.ydistance))
	end
end

Is that a reasonable fix? Can’t tell if my laptop is getting hot or it’s my imagination.

Setting the position of 60 game objects each frame is no big deal.

Now that I think of it couldn’t you do go.animate with a varying delay across the 60 segments?

The delay could be calculated as:

local delay = math.abs(math.sin(math.rad(i*20)))

20 is the frequency, higher = more waves along the X axis.

Not sure, I would need to try it to know if it works as I’m thinking it should.

This sounds like it would also be a neat effect. But actually, delay can be regular (delay = i/10 for example) as long as you use sine easing.

In any case, my idea here was to have absolutely 0 delay- the collection loads, and it’s already a sea of waves (it’s for the AV project). And it works using the code as described!

It’s actually a challenge I’ve had many times on this project, because a lot of it is based on animations looped using playback_loop_pingpong, but i need everything to already be in motion as soon as I press the button. In this case it was not too hard to find a workaround.

Ah, yeah, you may be right! As you say, you got it working and performance wise your solution is not a problem.

I have managed to take this technique to the next level and I am now setting the position of 1,152 GOs each frame:

function update(self, dt)
	for i = 1,24 do
		self.pcount[i]= self.pcount[i]+ self.xspeed
		go.set("parent"..i, "position.x", self.pstartpos[i] + math.sin(self.pcount[i])*self.xspread)
		for n = 1,48 do
			local number = (i-1)*self.children+n
			self.ccount[n] = self.ccount[n]+ self.yspeed
			go.set("child"..number, "position.y", math.sin(self.ccount[n])*self.xspread)
		end
	end
end
1 Like