Animated 2D Sprites

Hi @juglarx again!

it seems i found the problem. This is bacause of casiting to int/float. I suppose you have ATI card.
http://hub.jmonkeyengine.org/forum/topic/strange-glsl-trouble/ - see second post of @llama .

I need to fix these lines in the vertex shader i guess:
[java]
texCoordAni.x = -(1.0 - ((texCoordAni.x + mod((selectedTile), (iNumTilesU))) / iNumTilesU)); ///selectedTile;
texCoordAni.y = ((-texCoordAni.y - (selectedTile / iNumTilesU)) / iNumTilesV); ///selectedTile;
[/java]

@juglarx I trying to fix your issue. Can you test it on your machine?

Just change lines 38,39 in the vertex shader:
[java]
texCoordAni.x = -(1.0 - ((texCoordAni.x + mod(float(selectedTile), float(iNumTilesU))) / float(iNumTilesU))); ///selectedTile;
texCoordAni.y = ((-texCoordAni.y - (float(selectedTile) / float(iNumTilesU))) / float(iNumTilesV)); ///selectedTile;
[/java]

Possibly, it will solve the issue.

Thanks.

Hi! @mifth awesome ! it was very helpful. it seem it have the same error on the line 36 i change to

selectedTile += int(g_Time) * int(m_Speed);

but i have a wire effect in the sprite related to the round int, i will try to fix and i back to you :slight_smile: if you have any clue just write me :slight_smile: my videocard it’s an old geforce 9400m executing opengl 2.1 on mac os x 10.6.6

regards!!!

@juglarx sorry, I misunderstood you. Can you explain what a “wire effect” you have? Can you paste video or screenshot?

you should see this: http://www.youtube.com/watch?v=7XFxbt-dw3I

[video]http://www.youtube.com/watch?v=7XFxbt-dw3I[/video]

@juglarx it seems i fixed it. Can you test my code on your machine?
Don’t forget to make “clean and build” before running the test.

[java]
selectedTile += int(g_Time*m_Speed);

// the "1 - " bit is because otherwise it goes from right to left
texCoordAni.x = -(1.0 - float((texCoordAni.x + mod(float(selectedTile),  float(iNumTilesU))) / float(iNumTilesU))); ///selectedTile;
    texCoordAni.y = (-texCoordAni.y - float(selectedTile / iNumTilesU)) / float(iNumTilesV); ///selectedTile;[/java]

hi ! thanks again @mifth, in order to compile i need to change
This line
selectedTile += int(g_Time*m_Speed);
for this one
selectedTile += (int(g_Time) * int(m_Speed));

but now it seem skip same frame in the animation any clue on that? i think is for the int round… but i can’t figure out how to solve it…

AAAhhhh!!! @juglarx you need to do like this!
[java]selectedTile += int(g_Time*float(m_Speed));[/java]

Entire change will be:
[java]
selectedTile += int(g_Time*float(m_Speed));

// the "1 - " bit is because otherwise it goes from right to left
texCoordAni.x = -(1.0 - float((texCoordAni.x + mod(float(selectedTile),  float(iNumTilesU))) / float(iNumTilesU))); ///selectedTile;
    texCoordAni.y = (-texCoordAni.y - float(selectedTile / iNumTilesU)) / float(iNumTilesV); ///selectedTile;

[/java]

TEST IT AGAIN!

1 Like

awesomeeee !!! it is works fine!!!

1 Like

Thank you man for testing!