General discussion about LÖVE, Lua, game development, puns, and unicorns.
dizzykiwi3
Citizen
Posts: 58 Joined: Tue Jan 14, 2014 2:03 am
Post
by dizzykiwi3 » Fri Feb 06, 2015 5:38 pm
This probably has a simple solution but I'm a bit unfamiliar with Lua
How would I go about overriding the setPitch function so that I can have it link to a speed value so that it ramps down during slow-motion moments
The way I'm currently trying to do it is
Code: Select all
rampspeed = .1
origsetPitch = Source:setPitch
function Source:setPitch(pitch)
origsetPitch(pitch * rampspeed)
end
but that isn't working.
slime
Solid Snayke
Posts: 3172 Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:
Post
by slime » Fri Feb 06, 2015 5:48 pm
You could make a completely new function which does what you want, and change your game's code to call the new function instead of Source:setPitch directly. It would also have the added benefit of letting you use Source:setPitch directly in specific cases if you want.
Like this:
Code: Select all
rampspeed = 0.1
function SetRampingPitch(source, pitch)
source:setPitch(pitch * rampspeed)
end
dizzykiwi3
Citizen
Posts: 58 Joined: Tue Jan 14, 2014 2:03 am
Post
by dizzykiwi3 » Fri Feb 06, 2015 6:47 pm
I was thinking about doing that, it'd just save me some time if I could override it.
I'm also a bit unfamiliar with using the color and self parameters in lua functions so I wanted to try it out
is this syntax close to correct? It isn't working but I think it's close?
Code: Select all
origsetPitch = setPitch
function Source:setPitch(pitch)
self:origsetPitch(pitch * .1)
end
BruceTheGoose
Citizen
Posts: 76 Joined: Sat Sep 20, 2014 2:54 pm
Post
by BruceTheGoose » Tue Feb 10, 2015 4:27 pm
The self variable refers to the table used to call the method.
Code: Select all
Player = {}
Player.x = 0
function Player:move(x,dt)
self.x = self.x + x * dt
end
function Player:update(dt)
self:move(5,dt)
end
"I don't know."
Users browsing this forum: Bing [Bot] , Google [Bot] and 6 guests