• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
anupgupta

image Stretching

7 posts in this topic

Hello

 

I am facing a peculiar issue in my game, i am currently making a game which is an endless car driving game using cocos2dx and box2d for iOS platform.

 

[attachment=21145:IMG_0176.PNG]    [attachment=21146:IMG_0179.PNG]

 

As you can see the ground below, initially when i start the ground image is fine, but as i progress through the game driving continuously, the ground image starts stretching. 

 

I am also attaching the reference code of the ground(terrain.zip), so that i can get some inputs as to where the problem could be.

 

Any Suggestions

0

Share this post


Link to post
Share on other sites
void CTerrainLayer::generateTerrainTexture()
{
    //terrain top texture                                                                                              
    ccTexParams txpTop = {GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT};
    gameplaySceneRef->gameImages[IMG_GAME_TERRAINTOP]->getTexture()->setTexParameters(&txpTop);
    terrainTopTexId = gameplaySceneRef->gameImages[IMG_GAME_TERRAINTOP]->getTexture()->getName();
    terrainTopTexSize = gameplaySceneRef->gameImages[IMG_GAME_TERRAINTOP]->getContentSize().height/CC_CONTENT_SCALE_FACTOR()/2;

    //terrain bottom texture                                                                                           
    ccTexParams txpBottom = {GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT};
    gameplaySceneRef->gameImages[IMG_GAME_TERRAINBOTTOM]->getTexture()->setTexParameters(&txpBottom);
    terrainBottomTexId = gameplaySceneRef->gameImages[IMG_GAME_TERRAINBOTTOM]->getTexture()->getName();
    terrainBottomTexSize = gameplaySceneRef->gameImages[IMG_GAME_TERRAINBOTTOM]->getContentSize().height*CC_CONTENT_SCALE_FACTOR()/2;

    //CCLog("texSize:%f %f", terrainTopTexSize, terrainBottomTexSize);                                                 
}
Hmmm... I don't really understand your code but, why would you divide by CC_CONTENT_SCALE_FACTOR for the top texture and multiply by it instead for the bottom texture?
0

Share this post


Link to post
Share on other sites


… but as i progress through the game driving continuously, the ground image starts stretching.

If the effect actually starts after already driving for a while, the problem may be due to an accumulation. Actually, there is a location in getTerrainNextPoint which is IMO problematic: Therein you continuously add 200 onto a float variable (namely the x co-ordinate of the terrain control points). I have no clue with which rate this is done, but if it happens often enough the float variable's precision will suffer. Could you check for the current value of that variable when the effect starts to be noticeable?

 

BTW: I would expect the problem to have an effect on the top terrain texture, too, but the hills visible in the two screen shots seem to be scaled well. However, that may be due to a difference in the values of terrainBottomTexSize and terrainTopTexSize.

0

Share this post


Link to post
Share on other sites

 

 

..why would you divide by CC_CONTENT_SCALE_FACTOR for the top texture and multiply by it instead for the bottom texture?

 

my bottom texture image size was 512x512 and top texture size was 32x32 .. that i did to scale down the textures to make it look appropriate on the screen. 

 

 

 

 

Actually, there is a location in getTerrainNextPoint which is IMO problematic: Therein you continuously add 200 onto a float variable (namely the x co-ordinate of the terrain control points). I have no clue with which rate this is done

 

just roughly what i am doing is i have calculated 10 points(MAX_HILL_POINTS) which are 200 pixels apart of each other and then divided the whole 10 points into 100 segments (MAX_SEGMENTS)..and then in the update i keep checking if the points go outside screen then delete the point from the left and then add one point to the right and recalculate the terrain and thus this gives me endless terrain. the new point which is added is also 200 pixels apart in x and random in y in a given range. and the cardinal spline algorithm gives me a smooth curve across points(100 segments). i guess the issue could be in the generatecoordinates() function..but am not sure and need help to understand it.

 

the 200 is added only when one point is deleted and when the next is added..thus every point added is 200 pixel apart in X direction and random in Y direction between a set range.

 

checking of all the 10 points is done every frame if any of the point is gone outside screen, and if it goes outside the screen then delete the point and add a new point as the next point (getTerrainNextPoint) to the hill points array and then recalculate the whole terrain again and map the texture on it. thus with only 10 points divided into 100 segments i get a constantly generated terrain which is endless.

 

 

?generally, though i have now tried to follow a tutorial for texture mapping on the terrain and i revised my code..here is the link : http://www.codeproject.com/Articles/727918/d-Textures-in-cocos-d-x-V

 

but the problem remains as it is..the terrain bottom texture still gets stretched even after implementing this tutorial.

Attaching the revised code ([attachment=21149:terrain.zip]) for your reference and to get some inputs for this query.

 

Please suggest something or if you have a better way of doing it do let me know. rolleyes.gif  .. the problem i am facing is in texture mapping. i guess

 

[attachment=21147:IMG_0181.png]    [attachment=21148:IMG_0186.png]

Edited by anupgupta
0

Share this post


Link to post
Share on other sites

You should learn how to debug your code. There are many things you can do to gain an understanding of what your code is doing. For instance, you could run the program in a debugger, get to the point where the textures look wrong and then execute the code step by step, checking intermediate values to see what variables have unexpected values. Or you write out a piece of text to a file every frame, with the texture coordinates you are using, to see where they go wrong.

 

Debugging is not particularly fun, but it's an important skill.

0

Share this post


Link to post
Share on other sites

 

 

Debugging is not particularly fun, but it's an important skill.

 

smile.png  .. yes..i did try to debug it and gather much of the data i could with respect to the vertices and texture co-ordinates which are being generated, and trying to make some meaning out of the data.

though i think the code area:

//get the hill texcoordinates
for(short i = 0; i < MAX_SEGMENTS; ++i)
{
   //calculating texture co-ordinates
   CCPoint pt = hillBottomVertices[i];
   hillBottomTexCoords[i] = pt * (1.0f / terrainBottomTexSize);
   hillBottomTexCoords[i].y = 1.0f - hillBottomTexCoords[i].y;

   CCLOG("point: %f %f", hillBottomTexCoords[i].x, hillBottomTexCoords[i].y);
}

the texture coordinates values are like 

point: 0.937500 0.594344

point: 0.937500 1.000000

point: 1.093750 0.565063

point: 1.093750 1.000000


point: 2.031250 0.347375

point: 2.031250 1.000000 ...so on

 

point: 166.875000 0.280531

point: 166.875000 1.000000 ... till

 

point: 260.937500 0.308594

point: 260.937500 1.000000  .. until the X co-ordinates goes beyond 256 which is also the size of the texture(size = 256) ..that the stretch starts to appear.

As i move ahead the x co-ordinates keeps on increasing and the texture goes on stretching more.

Edited by anupgupta
0

Share this post


Link to post
Share on other sites

My guess is that is due to decreased precision of the part of the value to the right of the decimal point as your floating point numbers get larger.

 

A solution would be to "reset" all your texture coordinates once they get too large, so that everything is as close to 0 as possible.

0

Share this post


Link to post
Share on other sites

 

 

A solution would be to "reset" all your texture coordinates once they get too large, so that everything is as close to 0 as possible.

 

the texture co-ordinates in the x direction are being generated with respect to the terrain vertices (hillBottomVertices[i]) which are being created as the vehicle moves ahead in the x-direction

how do i make sure that the texture co-ordinates in the x direction are close to 0...or maybe reach 256 (texture size = 256) and then reset.

Edited by anupgupta
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0