Game Development Community

Bug 1.1: Camera shake doesn't effect tilemaps

by Tom Spilman · in Torque Game Builder · 07/27/2006 (12:35 am) · 8 replies

I don't have a fix for this one yet... but i'm tired... it would be great if someone got to it before me. ;)

Anyway. If you do some camera shake in a scene with some tilemap layers and some sprites you'll notice the sprites shake, but the tilelayer doesn't move at all.

Looking at the t2dTileLayer::RenderObject() call it for some reason completely recalculates all the camera settings... including shake. So it seems like it is doing it incorrectly.

About the author

Tom is a programmer and co-owner of Sickhead Games, LLC.


#1
07/27/2006 (12:52 am)
It was an easy fix. Change the following code in t2dTileLayer::renderZeroAngleObject()...

// Get Camera Shake.
   const t2dVector& cameraShake = pSceneWindow->getCameraShake();
   // Calculate Window Shake Scale.
   Point2F shakeScale( cameraShake.mX * (objectClip.len_x() / F32(windowRectClip.len_x())), cameraShake.mY * (objectClip.len_y() / F32(windowRectClip.len_y())) );

   // Setup new Clipping Projection (including camera shake).
   glMatrixMode(GL_PROJECTION);
   glPushMatrix();
   glLoadIdentity();
   glOrtho( objectClip.point.x + shakeScale.x, objectClip.point.x + objectClip.len_x() + shakeScale.x, objectClip.point.y + objectClip.len_y() + shakeScale.y, objectClip.point.y + shakeScale.y, 0.0f, t2dSceneGraph::maxLayersSupported );

... to this....

// Get Camera Shake offset.
   const t2dVector& cameraShake = pSceneWindow->getCameraShake();

   // Setup new Clipping Projection (including camera shake).
   glMatrixMode(GL_PROJECTION);
   glPushMatrix();
   glLoadIdentity();
   glOrtho( objectClip.point.x + cameraShake.mX, objectClip.point.x + objectClip.len_x() + cameraShake.mX, objectClip.point.y + objectClip.len_y() + cameraShake.mY, objectClip.point.y + cameraShake.mY, 0.0f, t2dSceneGraph::maxLayersSupported );

Tada... working camera shake for tile layers!
#2
07/27/2006 (9:05 am)
Your amazing Tom!

Which file is t2dTileLayer::renderZeroAngleObject() in?
#3
07/27/2006 (9:10 am)
It's in the t2dTileMap file. I just fixed it just now and it works great. Thanks again Tom!
#4
07/27/2006 (11:26 am)
Tom,

This has been fixed in the 1.1.1 release, thanks for the find and fix!

Cheers,
-Justin
#5
07/28/2006 (5:19 pm)
Please humor me. . .I have made the changes in the file and saved it. I know I must compile the file, but I get an error whenever I try. Obviously I'm doing something wrong. I'm using Dev C++, so how can I go about compiling this file or doing whatever I need to do to make the changes effect the actual game?
#6
07/28/2006 (5:50 pm)
From what I heard, Dev-C++ won't be able to compile it since the source is too big. However, you could (like me) use Visual C++ 2005 express edition, which is free from microsoft's website. Then follow this tutorial on how to set VC++ up. If you can't be bothered, and the problem isn't too big, I guess you could wait for the fix to come out. But, this is a one time only thing, so in future you could update everything yourself if you have the code.
#7
07/28/2006 (6:01 pm)
Yeah, I have Microsoft Visual C++ ver.SOMETHING.ANOTHERTHING. . .but I thought that Dev C++ was more widely used. . .lol. Kudos Apurva. (Kudos???. . .I'm getting tired)

G'night!
#8
07/29/2006 (3:29 pm)
Wow, that is really long. . .my problem is minor, so I'll wait before I sink a day into setting VC++ up. If I ever have nothing Torqish to do though. . .