Changing animation

Non-platform specific questions.

Changing animation

Postby jcflysrc » Thu May 12, 2011 4:26 am

I give up. I have tried to change my enemies animation to a death animation after he is killed. I can't figure it out. Any help here is appreciated. Idealy I would like for the actor to change animation, and then for the animation to disappear after a second or two. I am not a coder, so please give me specific directions if you can help me with this. Thanks.
jcflysrc
 
Posts: 49
Joined: Wed Apr 27, 2011 9:56 am
Score: 0 Give a positive score

Re: Changing animation

Postby skydereign » Thu May 12, 2011 4:59 am

This really doesn't have much to do with coding, just gE. I'm going to assume you already setup the hp variable, and have some code somewhere that looks something like this (usually a collision event).
Code: Select all
if(hp<=0)
{
    DestroyActor("Event Actor");
}


Assuming that is the case, then instead of DestroyActor, use this.
Code: Select all
if(hp<=0)
{
    ChangeAnimation("Event Actor", "death", NO_CHANGE);
}


When hp less than or equal to zero (player dies), it changes the animation to death, instead of destroying it. Now, if you want to destroy the actor when that animation finishes, then add an Animation Finish event for death that destroys the actor. Not quite sure what you mean by "disappear after a second or two", but I am assuming you have an animation so this should work.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Changing animation

Postby jcflysrc » Thu May 12, 2011 7:59 am

Like I said, I don't know much about coding. I assume hp is something to do with health? In your example I would have to have something set up to handle the health status of a player? Which I don't. I am totally new at this, and I know very little about how to achieve anything at all. So I suppose I will read further in this forum and try to figure it out. I must say, this forum is hard to find relevant info in. Most of the tutorials are basic at best, and unfinished in most cases. I assume there are a lot of "foreigners"(not to offend anyone), as reading the poor spellings of the english language is very difficult at best to decipher at times. Most of the post seem to assume that the reader knows a little about GE, and coding in general. I do not. But thanks for your help.

My solution was to create an actor for the death animation, not to be created at start. I then assigned a collision event to the actor I want to "disappear", and added a create actor event pointing to the death actor. I put the death actor on a path. I then assigned a Path Finish event to the death actor, with a Destroy Actor action, and got the result I was after.

I suppose figuring it out for myself is the best way, but I am sure there was a better way...a short cut if you will, for coding the same result in fewer steps. I will learn in time I suppose. Now I need to try and understand a few things related to adding lives to my player, and a game over scenario. Not to mention multiple levels, etc., etc.
jcflysrc
 
Posts: 49
Joined: Wed Apr 27, 2011 9:56 am
Score: 0 Give a positive score

Re: Changing animation

Postby skydereign » Thu May 12, 2011 8:23 am

Ok, so you don't have any life mechanism in your game. Your first post sounded like you did have an hp variable setup. As for the tutorials, a lot of them are messed up, and akr did release a version where we could create our own (but it hasn't worked for me yet). Just to note, even those fluent in English (as a first language) still don't necessarily have great spelling or grammar. Though it is true the gE community is very diverse.

For the most part, from what it sounds like you are doing, this should work. Add the death animation to the actor you want to disappear. On the collision event where you were putting the CreateActor code, put a ChangeAnimation call to set the death animation. Also call ChangePath there as well.
player -> Collision with Bullet (disabled) -> Script Editor
Code: Select all
ChangeAnimation("Event Actor", "death", FORWARD);
ChangePath("Event Actor", "deathPath", BOTH_AXIS);


player -> Path Finish (deathPath) -> Script Editor
Code: Select all
DestroyActor("Event Actor");



The most important thing to know is how to use variables. To put it in overly simple (but effective) terms, a variable is a number. In script you can access this number whenever you want. You can change it and use it for comparisons. So, in your case you want to have a lives variable. To gameEditor, the variable will always be there and you can use it to tell gE what to do. I think this link adequately describes how to make a variable. If not, do tell me and I'll fix it. http://game-editor.com/Creating_variables

When you have created the lives variable, you can set how many lives the player gets. I put the script in the view's create actor, so it happens each time you load the game.
view -> Create Actor -> Script Editor
Code: Select all
lives=3;


Now, if you want to make the player lose a life (for example hitting a projectile), just lower the variable by 1.
player -> Collision with Bullet (disabled) -> Script Editor
Code: Select all
lives=lives-1;


If you want to check if the player has no more lives, and if so end the game, add this code.
player -> Collision with Bullet (disabled) -> Script Editor
Code: Select all
lives--; // same as the lives=lives-1; code

if(lives<=0) // if lives is less than or equal to zero execute the code inside the {    }
{
    ExitGame(); // quits the game
}


So you know, the // comments the code, meaning gE will ignore any code after the //, so you can write notes to explain what you are doing. Anyway that is a quick description, I can pm you a more in depth version if you want. I'm working on improving the wiki, among other things, so I like getting as much input from new users about what needs to be improved as I can.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Changing animation

Postby jcflysrc » Thu May 12, 2011 5:39 pm

Now that was very helpful, and I thank you. I will indeed give this a try. This is very clear and concise info for a noob like me. I truly hope I didn't offend ANYONE with the comments from above, but it's hard to tell sometimes what is meant in some of the post I've read. Again thanks for the very clearly stated information. +1 to you.
jcflysrc
 
Posts: 49
Joined: Wed Apr 27, 2011 9:56 am
Score: 0 Give a positive score

Re: Changing animation

Postby jcflysrc » Fri May 20, 2011 8:46 am

So now I have question about a lives counter based on the above code. I am using this code and it works fine. My player dies after three contacts with the enemy, and the game ends, just perfect. How do I add a counter to the top of the page now and have it show the lives status? Thanks in advance, and I really appreciate all the help I get from you guys. Without it I wouldn't be as far along as I am.
jcflysrc
 
Posts: 49
Joined: Wed Apr 27, 2011 9:56 am
Score: 0 Give a positive score

Re: Changing animation

Postby skydereign » Fri May 20, 2011 8:58 am

To display the contents of a variable, you use text actors. To create a text actor, create a normal actor, click text, [New Font], then pick your font type, then font. Usually you will use a .ttf file. After selecting your font, make sure to add something in the large text box, for example
Code: Select all
Lives: 3


Now in the text actor's draw event, use this.
Code: Select all
sprintf(text, "Lives: %d", lives);


This sets the text of the actor equal to the string in the double quotes. It will replace %d with the number of lives you have. If you don't want to have it say Lives: you can take that part out, or use the following code.
Code: Select all
textNumber=lives;


With that code it will just show the number of lives.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Changing animation

Postby jcflysrc » Fri May 20, 2011 9:25 am

Thank you sir! I wil give that a try.
jcflysrc
 
Posts: 49
Joined: Wed Apr 27, 2011 9:56 am
Score: 0 Give a positive score

Re: Changing animation

Postby jcflysrc » Fri May 20, 2011 10:00 am

Dude you really have been good to me. Thanks. It worked like magic.
jcflysrc
 
Posts: 49
Joined: Wed Apr 27, 2011 9:56 am
Score: 0 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest