How to implement “circular side-scrolling” in my game?

怎甘沉沦 提交于 2019-12-10 16:49:16

问题


I'm developing a game, a big part of this game, is about scrolling a "circular" background ( the right end of the Background Image can connect with the left start of the Background image ).

Should be something like this: ( Entity moving and arrow to show where the background should start to repeat )

alt text http://img89.imageshack.us/img89/9308/circular.jpg

This happens in order to allow to have an Entity walking, and the background repeating itself over and over again.

I'm not working with tile-maps, the background is a simple Texture (400x300 px).

Could anyone point me to a link , or tell me the best way I could accomplish this ?

Thanks a lot.


回答1:


Alternatively you can translate the texture using an appropriate texture matrix. This saves you from having to recalculate/upload your UV coordinates each frame.




回答2:


I don't know how different it is on the iPhone (OpenGL ES, I believe?), but in normal OpenGL, you'd set the texture tiling to repeat and then simply change the UV coordinates by the distance that the player moved. The texture tiling is set using:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);


来源:https://stackoverflow.com/questions/2661220/how-to-implement-circular-side-scrolling-in-my-game

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!