PDA

View Full Version : Side Scroller World scrolling



Zorrander
09-11-2013, 12:22 AM
Hello everyone,

I have a problem and would like some help. I am trying to scroll the game and am having difficulties since I am fairly new using clanlib. I fooled around with canvas.set_translate(), while setting the x coordinate to the player. The world did scroll so it worked but the sprites were jumpy, going back and forward. I am wanting to move the 'Camera' with the player so the world moves but the player is always center.

Is there another function that I am missing in clanlib that will do this? I was looking at pacman and it seemed to update every 'tile' based of the player.

I am using Clanlib 3.0 in VS 2012.

Any help would be appreciated, thank you.

rombust
09-11-2013, 07:08 AM
Using canvas.set_translate() and setting the x coordinate to the player at the same time, would make the sprites look jumpy (If I understand correctly)

Canvas translate, scale and rotate (known as the ModelView matrix) affects subsequent drawing of graphics to the canvas.

Although you can use it, I personally would avoid using it for positioning objects. It does have it's uses though. For example, to draw rotated text (remember to disable subpixel font rendering, if you do).
I also use it to scale the game screen to the display window size, so that if the user resizes the display window, the game screen viewable area stays the same (if that makes sense!)

Instead have an "int camera_position_x", that you subtract from object coordinates when you draw them.

This is my personal opinion, others may think differently :)

Zorrander
09-11-2013, 01:20 PM
Rombust,

Makes sense about Translate, scale, and rotate. And thanks for explaining a scenario as to when to use it. :)

So are you saying that have a displacement and draw every object in the game by said displacement? I thought about that but didn't know if there was the correct scrolling method in clanlib.

I'll give it a shot tonight and see if i get it work properly.

Thanks for your help. :)