Game Development Community

Tested And Working - Shake camera effect

by Andrea Farid Marsili · in iTorque 2D · 05/07/2011 (1:23 pm) · 6 replies

Really really simple script but maybe someone will find this useful.


function ActorName::onMouseDown(%this, %modifier, %worldPosition, %clicks){
//this is an example, this function have the only purpose to run multipleShake()
	$shake = true;
	
	echo($shake);
	
	multipleShake();
}

function singleShake(){
	if($shake){
		ScheduleShake(10, -10, 0);
    	ScheduleShake(8, -8, 100);
    	ScheduleShake(6, -6, 200);
    	ScheduleShake(4, -4, 300);
    	ScheduleShake(2, -2, 400);
    	ScheduleShake(0, 0, 500);
    	
    	sceneWindow2D.schedule(600, $shake = false);
    	echo($shake);
	}
}

function multipleShake(){
	if($shake){
		ScheduleShake(10, -10, 0);
    	ScheduleShake(8, -8, 100);
    	ScheduleShake(6, -6, 200);
    	ScheduleShake(4, -4, 300);
    	ScheduleShake(2, -2, 400);
    	
    	ScheduleShake(10, -10, 500);
    	ScheduleShake(8, -8, 600);
    	ScheduleShake(6, -6, 700);
    	ScheduleShake(4, -4, 800);
    	ScheduleShake(2, -2, 900);
    	ScheduleShake(0, 0, 1000);
    	
    	ScheduleShake(10, -10, 1100);
    	ScheduleShake(8, -8, 1200);
    	ScheduleShake(6, -6, 1300);
    	ScheduleShake(4, -4, 1400);
    	ScheduleShake(2, -2, 1500);
    	ScheduleShake(0, 0, 6000);
    	
    	sceneWindow2D.schedule(6010, $shake = false);
    	echo($shake);
	}
}

function ScheduleShake(%maxRnd, %minRnd, %time){
    %rnd1 = getRandom(%minRnd, %maxRnd);
    %rnd2 = getRandom(%minRnd, %maxRnd);
    sceneWindow2D.schedule(%time, "setCurrentCameraPosition", %rnd1, %rnd2);
}

#1
05/07/2011 (3:34 pm)
Andrea, is this different to the built in camera shake?

e.g. we use ...

sceneWindow2D.startCameraShake(30, 3);
#2
05/07/2011 (4:53 pm)
what is the purpose of the shake? this is suggesting the user is physically shaking his device?
#3
05/08/2011 (1:42 am)
@Scott: Yes is a bit different because you can control time between the various shake, you can get a far smooth effect.

@Rennie: This is a "earthquake" camera effect. I'm also working on a DetectShake script and I'll post it when it will be ready.
#4
05/09/2011 (11:23 am)
Oh. What is the purpose of the DetectShake script?
#5
05/09/2011 (11:59 am)
The DetectShake script detect if the device (not the camera) has been shaken.

Here my topic about detect shake script
#6
05/09/2011 (12:46 pm)
Oh nice. Thanks.