Topic: 2.5D side scrooling lanscape ain't running smooth.. Pages that link to <a href="https://ozoneasylum.com/backlink?for=31166" title="Pages that link to Topic: 2.5D side scrooling lanscape ain&amp;#039;t running smooth.." rel="nofollow" >Topic: 2.5D side scrooling lanscape ain&#039;t running smooth..\

 
Author Thread
der redsplat
Nervous Wreck (II) Inmate

From:
Insane since: Jun 2009

IP logged posted posted 07-27-2009 19:59 Edit Quote

I've made this little thingy in JavaScript that I'm going to use in a game. But it's running pretty laggy N' slow..

Is there someone out there who knows how to make the perfomance of this better?

http://redsplat.org/LOL/

der redsplat
Nervous Wreck (II) Inmate

From:
Insane since: Jun 2009

IP logged posted posted 07-27-2009 21:37 Edit Quote

By changing:

code:
var bgpos1=0;
var bgpos2=0;
var bgpos3=0;
document.onload
function background() {
document.getElementById('background1').style.backgroundPosition=bgpos1+"px 0px";
document.getElementById('background2').style.backgroundPosition=bgpos2+"px 0px";
document.getElementById('background3').style.backgroundPosition=bgpos3+"px 0px";
bgpos1-=0.7;
if (bgpos1<=0) { bgpos1=1000 }
bgpos2-=0.4;
if (bgpos2<=0) { bgpos2=850 }
bgpos3-=0.1;
if (bgpos3<=0) { bgpos3=700 }
}


to:

code:
var bgpos1=1000/0.7;
var bgpos2=850/0.4;
var bgpos3=700/0.2;
document.onload
function background() {
document.getElementById('background1').style.backgroundPosition=bgpos1*0.7+"px 0px";
document.getElementById('background2').style.backgroundPosition=bgpos2*0.4+"px 0px";
document.getElementById('background3').style.backgroundPosition=bgpos3*0.2+"px 0px";
bgpos1--;
if (bgpos1<=0) { bgpos1=1000/0.7; }
bgpos2--;
if (bgpos2<=0) { bgpos2=850/0.4; }
bgpos3--;
if (bgpos3<=0) { bgpos3=700/0.2; }
}


I have got a little bit better perfomance altough I still think it can be better..

White Hawk
Maniac (V) Inmate

From: zero divided.
Insane since: May 2004

IP logged posted posted 07-27-2009 21:45 Edit Quote

Ooh! Retro parallax scrolling! That brings back good gaming memories.

der redsplat
Nervous Wreck (II) Inmate

From:
Insane since: Jun 2009

IP logged posted posted 07-27-2009 22:48 Edit Quote

I'm glad you think so cuzz I'm accutually trying to get a retro feel

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

IP logged posted posted 07-27-2009 22:58 Edit Quote

White Hawk: Like November 20lines Javascript Contest - Arcade Scrollers - Comments ?

der redsplat: setInterval( foo, 10 ) ain't a great idea.. You'd better use a recurring setTimeout with a ~16ms delay, and depending on your game and the range of target devices you might want to make the animation depend on the current timestamp instead of an arbitrary tick count.



(Edited by poi on 07-27-2009 22:58)

der redsplat
Nervous Wreck (II) Inmate

From:
Insane since: Jun 2009

IP logged posted posted 07-27-2009 23:59 Edit Quote

Thanks poi.

Why is setTimeout better than setInterval? Later on I am going to add a timestamp so the game doesn't run slower on slower machines.

Anyway tommorow I will check out the source of your game Shadow of the Beast. It looks very cool

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

IP logged posted posted 07-28-2009 00:11 Edit Quote
quote:
Why is setTimeout better than setInterval?

Read the second result of the search query I gave above

cindy
Neurotic (0) Inmate
Newly admitted

From:
Insane since: Jul 2009

IP logged posted posted 07-28-2009 14:09 Edit Quote

we are providing [Edit TP: Spam url removed. Thank your for spaming.] information to interested hookah smokers to experience the true pleasures.

(Edited by Tyberius Prime on 07-28-2009 14:38)

WebShaman
Lunatic (VI) Mad Scientist

From: The Happy Hunting Grounds...
Insane since: Mar 2001

IP logged posted posted 07-28-2009 16:54 Edit Quote
quote:

cindy said:

we are providing [Edit TP: Spam url removed. Thank your for spaming.] information to interested hookah smokers to experience the true pleasures.(Edited by Tyberius Prime on 07-28-2009 14:38)



Wow.

Hallucinary spam!

Me loves side scrollers!

WebShaman | The keenest sorrow (and greatest truth) is to recognize ourselves as the sole cause of all our adversities.
- Sophocles


(Edited by WebShaman on 07-28-2009 16:56)

der redsplat
Nervous Wreck (II) Inmate

From:
Insane since: Jun 2009

IP logged posted posted 07-29-2009 21:49 Edit Quote

Thanks poi! I didn't saw the link. I'm going to check out the source for Shadow of the Beast it looks pretty cool

revjx2
Obsessive-Compulsive (I) Inmate

From:
Insane since: Aug 2009

IP logged posted posted 08-07-2009 15:30 Edit Quote

Ahh, so simple but looks excellent. I love parallax style stuff.

coach
Nervous Wreck (II) Inmate

From:
Insane since: May 2011

IP logged posted posted 05-31-2011 11:07 Edit Quote
Edit TP: spam removed


Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu