• What is your GameDev Story?

Archived

This topic is now archived and is closed to further replies.

Frog Tounge....(A real stumper for you!)

This topic is 6773 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Ok, I have a sprite for a for a frog tounge, and I set the position of it so it appears to be coming out of the frog if the player presses the space bar. The problem is, the tongue won''t move with when the frog does, so it looks like the frog lost his tounge. I set the position of the frog like this: tounge.x = frog.x + 3; tounge.y = frog.y + 23; I also did this to make it move with the frog; if (frog.x++) tounge.x++; if (frog.x--) tounge.x--; if (frog.y++) tounge.y++; if (frog.y--) tounge.y--; Do you know the answer to this problem? Please help! Thanks! -Alex

Share on other sites
if you move the frog just do this again
tounge.x = frog.x + 3;
tounge.y = frog.y + 23;

Share on other sites
YOU ARE A GENIUS! I asked everybody in the chatroom and they couldn''t help! Thank you soooo much! I guess it really didn''t stump you afterall.

-Alex

Share on other sites
I may always be in the chat room but 90% of the time Im AFK coding and just read the logs later on

Share on other sites
So what the heck is a "tounge"?

Share on other sites
If your frog can turn around and face the other way you''ll need to modify the code, so that it either subtracts or adds depending on the direction of the frog.

Share on other sites
Comp, That''s exactly what we were trying to explain to you in the chat room.

Share on other sites
quote:
Original post by compfanatic

I also did this to make it move with the frog;

if (frog.x++)
tounge.x++;

if (frog.x--)
tounge.x--;

if (frog.y++)
tounge.y++;

if (frog.y--)
tounge.y--;

By the way, you can''t use checks like that in the way you think. What you''ve written above isn''t "Check if the frog moved,and if so, move the tongue too". It''s actually "Move the frog, if the new value isn''t 0, move the tongue too". But since the above code moves everything right 1 pixel, left 1 pixel, down one pixel then up one pixel, you''ll never see any effect. If you want to check if the frog moved, you''ll have to use some sort of variable to track this yourself.

Share on other sites
An even better piece of code wouldn''t update the tongue position every time the frog moved, but only when it needed to be drawn. For example, when the player hits the spacebar, do the following:

tongue.x = frog.x + 3;
tongue.y = frog.y + 23;

instead of doing it every frame, this will only update when it needs to.

Share on other sites
Ewww you have a frogs tounge in a bottle of Sprite? Im drinking Sprite right now and now i dont feel so good after reading that.

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 9
• 15
• 14
• Forum Statistics

• Total Topics
634071
• Total Posts
3015336
×