SamNainocard
Member
|
Screen shaking?
I wanted to make a screen shaking when hit or other explosion effect, but is there a built-in screen shaking? or how do I make it?
Thank you in advanced.
(This post was last modified: 01-07-2016 07:28 AM by SamNainocard.)
|
|
01-07-2016 07:28 AM |
|
Esenthel
Administrator
|
RE: Screen shaking?
Hi,
I use this class in my Dungeon Hero game:
Code:
/******************************************************************************/
class QuakeClass
{
C Vec& operator()() {return offset;}
flt intensity=0, step=0;
Vec offset=0, cur=0, next=0;
void add(flt intensity)
{
MAX(T.intensity, intensity);
}
void add(flt intensity, flt distance)
{
if(distance>1)intensity/=Sqr(distance);
add(intensity);
}
void update()
{
MAX(intensity-=Time.d()*2.0, 0);
step +=Time.d()*20;
if( step>=1)
{
step=Frac(step);
cur =next;
next=Random(Ball(1));
}
offset=Lerp(cur, next, step)*intensity;
}
}
QuakeClass Quake;
/******************************************************************************/
void AddQuake(C Vec2 &pos)
{
Quake.add(1, Dist(pos, Player.posf));
}
/******************************************************************************/
call Quake.update once per frame, Quake.add to add a shake.
and offset camera position each frame by Quake()*scale
Cam.pos=cam_pos+Quake()*0.1;
Hope this helps
|
|
01-07-2016 02:24 PM |
|