![]() NOTE: You may want to set your Current Health attribute to something other than zero in When Created to test your bar drawing. Just like we did before, we will use the actual health bar part to cover up the top left of the black rectangle that we don’t want to see. If you draw it as is, that black rectangle may look a little weird sitting inside of the white rectangle, but do not fear. So we have our basic outline of the health bar. In the example, I added 1 (our stroke thickness) to both the Bar X and Bar Y to move it over slightly, and then adjusted its width and height to 1 less than Bar Width and Bar Height to keep it inside of what we want our boundaries to be yet at the same time cover up the bottom right corner of our white rectangle. We will draw it similar to our white rectangle then, but move it over slightly as to NOT cover up the top left of the white rectangle. Again, set your stroke color! Now this one is a bit different we want it to cover up the bottom-right corner of our white rectangle. Draw the black rectangle which will make up the darker bottom-right corner, giving that soft shading effect we want. ![]() Don’t forget to set stroke color! This one is simple: use Bar X and Bar Y for the position and Bar Width and Bar Height for the dimensions. Draw the white rectangle for the top-left corner.Set the stroke thickness (here I have set it to 1)! Otherwise, the “draw rect” events will not show anything, because stroke thickness is at 0 by default. Also, I put a picture near the bottom that shows the progression of our drawn health bar as we add each rect, so as you add code you can see if it looks similar. Since its a lot of repetition (select color, draw/fill rect, select color, draw/fill rect, etc.), I decided to just put the picture of the final drawing code near the bottom of the code instead of using multiple pictures. Ultimately, it may be more preference than for efficiency’s sake, but I like doing it this way. ![]() What if you represent each health bar as its own actor? It’s possible: what if you want your character to be able to get more bars to their health? But as your max health climbs, so does your actor count on screen. That scenario, though, I don’t think is nearly as painful as the next one I will mentions. Your actor’s sprite sheet can quickly grow to a pretty big size if you are doing this all through a single actor. Now maybe you’re thinking “Why not use an actor/set of actors to represent health?” Personally, I think this is slightly inefficient at times. So for now we only have two number attributes:ĭraw events may sound a little complicated and scary… kind of like lists, but just like lists, they just involve knowing a few pointers to get you through it. Once we start adding the bells and whistles like drawing a health bar is when we will add some more. No need to make it any more complicated than it need be. Guess what? That’s about all we need in terms of attributes for a bare bones health behavior. In this tutorial, I will call it Current Health. This will be the attribute that will increase or decrease based on damage or recovery. Second, we will want a hidden attribute that keeps track of where our character’s health is at in-game. In this tutorial, my attribute will be named Max Health. First, we will want an attribute to indicate the maximum amount of health our character can have. ![]() We may want to attach this to other actors later for instance, maybe our future sledge hammer bearing mech could benefit from using this behavior as well. Make an actor behavior to host your health logic. In this tutorial, we’ll learn some basic set-up and how you can draw a health bar to the screen using Stencyl’s draw events. Maybe amusing at first, but not really that entertaining in the long run. After all, an invincible character is a little unfair. A wild sledge hammer bearing mech approaches your quest pal and BAM! Oh no… time to start the level over again.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |