Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: Can I get some help.  (Read 2010 times)

0 Members and 1 Guest are viewing this topic.
Can I get some help.
« on: July 21, 2014, 05:25:30 am »
  • *
  • Reputation: +12/-2
  • Offline Offline
  • Gender: Male
  • Posts: 4836
Maybe it's the stress, but my heart drawing code isn't working 100%. 

Code: [Select]
var i, ii;var fraction;var modValue;
fraction = global.life div 4;
modValue = global.life mod 4;
draw_set_font(font0);
for (i = 0; i < global.hearts ; i += 1)
{
    draw_text(view_xview+32,view_yview,global.life);
    draw_text(view_xview+32,view_yview+16,global.life mod 4)
   
    if (i <= 9)
        draw_sprite(sprHeart,0,x+92+(6*(i+1)),y+2);
    if (i > 9)
        draw_sprite(sprHeart,0,x+92+(6*(i-9)),y+9);
}

for (ii = 0; ii < fraction ; ii += 1)
{
    if (ii <= 9)
        draw_sprite(sprHeart,4,x+92+(6*(ii+1)),y+2);
    if (ii > 9)
        draw_sprite(sprHeart,4,x+92+(6*(ii-9)),y+9);
}

if (round(global.life / 4) <= 10) //(fraction <= 10)
    if (modValue > 0)
        draw_sprite(sprHeart,modValue,x+92+(6*fraction),y+2);
    else
        draw_sprite(sprHeart,4,x+92+(6*fraction),y+2);
else
    if (modValue > 0)
        draw_sprite(sprHeart,modValue,x+92+(6*fraction),y+9);

The code has been changed a few times but yields the same results.  The last heart before life is 0 is getting drawn in the wrong place as is the current heart if you are about to increase to the next heart.

Unable to post screenshots at this moment.

Been screwing with this for an hour now.  Maybe someone who hasn't stared at it can see the problem.


I will also add that sprite fonts aren't working for me.  I am quite sure I have them set up correctly, but all I am getting drawn is a black block the size of the sprite instead of the proper image.
« Last Edit: July 21, 2014, 06:31:22 am by Theforeshadower »
Logged
  • Super Fan Gamers!
Re: Can I get some help.
« Reply #1 on: July 21, 2014, 06:42:55 am »
  • Minalien
  • *
  • Reputation: +10/-1
  • Offline Offline
  • Gender: Female
  • Posts: 2119
Definitely need a screenshot to see exactly what's happening, and a mockup of what it should look like.

Some things:

1) Why on earth are you using two separate index variables? 'i' is never used after the first loop, so just re-use it.

2) Looking over your first loop - I'll start by pointing out that I'm assuming you are intending to have 10 hearts per row: rather than doing i-9 (which puts index 10 in the same place as index 1), do i - 10.

3) I'm assuming your second loop (fraction) is supposed to only draw the fractional heart? In which case, you're just drawing the fractional hearts over your full hearts (assuming that's what the first part is).

4) If you're nesting code branches (your if/else statements), use brackets. Yes, your indentation makes it easy for those of us reading it to understand what each one is supposed to tie to, but it can be somewhat ambiguous for compilers and doesn't give people unfamiliar with the GML compiler an easy way of telling if it's affecting your code.

Overall, I recommend you scrap the code, and take some time to work out the logic on paper. Figure out exactly what it is you want to do, and then execute. Again, this may be the effect of making a multitude of changes trying to get it to work, but this looks disorganized to me. And take the time to get some screenshots, because your description of your problem is clear as mud.
Logged
Quote
There's such a double standard about religion in the modern world. Catholics can gather, wear white robes, and say "In nomine Patris, et Filii, et Spiritus Sancti" and be considered normal.

But if my friends and I gather, wear black robes, and say  "Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn", we're considered cultists.
  • Development Blog
Re: Can I get some help.
« Reply #2 on: July 21, 2014, 07:03:21 am »
  • *
  • Reputation: +12/-2
  • Offline Offline
  • Gender: Male
  • Posts: 4836
1. I do it for myself.  Just helps me with readability.

2.  I did the i-10 to start.  It wasn't achieving what it was supposed to.

3.  Fraction is the amount of full hearts drawn UPTO the current heart.  So, fraction will always be 1 less than the current heart or equal to the current heart if the health is divisible perfectly by 4.  I shoulda renamed it to divValue.  Never got around to it.

4.  I never use brackets for single line if/else statements.  Seem very readable to me.  First time, I heard of a problem about doing so.  I been reading code done mostly in Java or C# done like that for years.  To each his own.

I already know exactly what I want to do: 

draw all the empty hearts first(as in the total hearts say, 12)
then draw full hearts upto the current heart
finally, draw the final heart which could be quarter, half, three quarters, or full


That simple.
« Last Edit: July 21, 2014, 07:08:31 am by Theforeshadower »
Logged
  • Super Fan Gamers!
Re: Can I get some help.
« Reply #3 on: July 21, 2014, 07:21:20 am »
  • Minalien
  • *
  • Reputation: +10/-1
  • Offline Offline
  • Gender: Female
  • Posts: 2119
2.  I did the i-10 to start.  It wasn't achieving what it was supposed to.

You still haven't specified clearly what it's supposed to do or what it is doing instead, except with very vague descriptions. In any case, I spotted my error regarding this part, because I hadn't noticed your i + 1.

3.  Fraction is the amount of full hearts drawn UPTO the current heart.  So, fraction will always be 1 less than the current heart or equal to the current heart if the health is divisible perfectly by 4.  I shoulda renamed it to divValue.  Never got around to it.

divValue is just as meaningless as "fraction." You really need to develop better variable naming practices.

Quote
draw all the empty hearts first(as in the total hearts say, 12)
then draw full hearts upto the current heart
finally, draw the final heart which could be quarter, half, three quarters, or full

This is why you need to provide screenshots and an explanation of what you're trying to do the first time. In any case, you still haven't clearly defined your problem, so I'm still shooting at an invisible target with trying to find possible errors in your code.
Logged
Quote
There's such a double standard about religion in the modern world. Catholics can gather, wear white robes, and say "In nomine Patris, et Filii, et Spiritus Sancti" and be considered normal.

But if my friends and I gather, wear black robes, and say  "Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn", we're considered cultists.
  • Development Blog
Re: Can I get some help.
« Reply #4 on: July 25, 2014, 03:02:53 am »
  • *
  • Reputation: +12/-2
  • Offline Offline
  • Gender: Male
  • Posts: 4836
Stupid naming conventions aside, the code was almost functioning as intended.  I was just trying to code at a bad time.

The code is near identical, however, you can see the changes near the bottom.
I commented out the lines that are going to be removed.  The 6*fraction has been changed.  Fraction now gets added by 1.  The hearts/life displayed on the HUD now function as I intended.  I will test some more to make sure it can't be broken, but it seems to be working.

Code: [Select]
var i, ii;var fraction;var modValue;
fraction = global.life div 4;
modValue = global.life mod 4;
draw_set_font(font0);
for (i = 0; i < global.hearts ; i += 1)
{
    draw_text(view_xview+32,view_yview,global.life);
    draw_text(view_xview+32,view_yview+16,global.life mod 4)
   
    if (i <= 9)
        draw_sprite(sprHeart,0,x+92+(6*(i+1)),y+2);
    if (i > 9)
        draw_sprite(sprHeart,0,x+92+(6*(i-9)),y+9);
}

for (ii = 0; ii < fraction ; ii += 1)
{
    if (ii <= 9)
        draw_sprite(sprHeart,4,x+92+(6*(ii+1)),y+2);
    if (ii > 9)
        draw_sprite(sprHeart,4,x+92+(6*(ii-9)),y+9);
}

if (round(global.life / 4) <= 10) //(fraction <= 10)
    if (modValue > 0)
        draw_sprite(sprHeart,modValue,x+92+(6*(fraction+1)),y+2);
    //else
        //draw_sprite(sprHeart,4,x+92+(6*fraction),y+2);
else
    if (modValue > 0)
        draw_sprite(sprHeart,modValue,x+92+(6*(fraction+1)),y+9);
    //else
        //draw_sprite(sprHeart,4,x+92+(6*fraction),y+9);


I plan on cleaning up some things you mentioned such as better variables names and adding comments as well.  The reason,I guess, as to why it seems like a weird way of handling the heart system is that I chose to base the hearts on whole numbers instead of decimals.  Even in LTTP, you can be hit without taken visible damage to your hearts when you have the Red Tunic.  The later Zelda games changed this by having quarters of the heart displayed.

I decided it was easier to make the life system run as 4 life to each heart.  I could have been done with decimals such as .25 .5 .75 then 1 for a full heart.  I chose to use whole numbers so that I can directly draw the image_index based on mod value if there is one.

Anyway, I probably make no sense.  It is what it is.  Even though I didn't start over, I did take a step back to re-evaluate based on your suggestions.  Thank you.
Logged
  • Super Fan Gamers!
Re: Can I get some help.
« Reply #5 on: July 27, 2014, 04:53:26 am »
  • ...---^^^---...
  • *
  • Reputation: +6/-0
  • Offline Offline
  • Gender: Male
  • Posts: 601
Alternatively...  and mostly because I feel like giving this a whack, you could do all of this in a single loop without drawing multiple layers (meaning the background and the heart on top).  I am going to use the variables Health_X, and Health_Y to represent the position on the screen of the whole health bar.  I am also assuming a heart sprite called "sprHeart" is a sprite containing 5 images (0-Empty Black Heart, 4-Full Red Heart)

Code: [Select]
//Variables set in the create event
Health_X =  ??        //Enter the x position of health bar here
Health_Y =  ??        //Enter y position here
X_Grid = 6            //How many pixels over the next heart will be drawn
Y_Grid = 6            //How many pixels down the second row of hearts will be drawn
Max_Health = 80       //This would be assuming the player has two rows of 10 hearts with a quarter heart system  Every time the player gets a container heart this would be updated to reflect his current maximum.

//Draw event
Code: [Select]

//Initialize relavent variables
var i, Full_Hearts, Total_Hearts, Fraction;

//Determine which image to draw for the last heart containing health
Full_Hearts = floor(global.life/4);      //Stores the current number of full hearts
Fraction = global.life mod 4;            //Stores the fractional quantity of the last heart (0-3)
Total_Hearts = Max_Health/4              //Stores the total number of hearts the player currently has available

//Draw the players health bar
for (i=0 ; i<Total_Hearts ; i += 1)
{
     //Determine the location to draw the heart
     if i < 9     //Draw first row of hearts
     {
          if i < Full_Hearts     //Draw full hearts
          {
               draw_sprite(sprHeart,4,view_xview[0]+Health_X+i*X_Grid,view_yview[0]+Health_Y);
          }
          else
          {
               if i == Full_Hearts     //Draw fractional heart
               {
                    draw_sprite(sprHeart,Fraction,view_xview[0]+Health_X+i*X_Grid,view_yview[0]+Health_Y);
               }
               else     //draw empty hearts
               {
                    draw_sprite(sprHeart,0,view_xview[0]+Health_X+i*X_Grid,view_yview[0]+Health_Y);
               }
          }
     }
     else     //Draw second row of hearts
     {
          if i < Full_Hearts     //Draw full hearts
          {
               draw_sprite(sprHeart,4,view_xview[0]+Health_X+(i-10)*X_Grid,view_yview[0]+Health_Y+Y_Grid);
          }
          else
          {
               if i == Full_Hearts     //Draw fractional heart
               {
                    draw_sprite(sprHeart,Fraction,view_xview[0]+Health_X+(i-10)*X_Grid,view_yview[0]+Health_Y+Y_Grid);
               }
               else     //draw empty hearts
               {
                    draw_sprite(sprHeart,0,view_xview[0]+Health_X+(i-10)*X_Grid,view_yview[0]+Health_Y+Y_Grid);
               }
          }
     }
}



I guess I can't say for sure, but I think this would be more efficient, but it looks bigger because of all the comments and white space.  This is untested code, but it should work...  If you wanted it to be even more efficient you could update "Full_Hearts", "Fraction", and "Total_Hearts" outside of the draw event (could be updated every time the player is hit for example).
« Last Edit: July 27, 2014, 05:22:35 am by Aero88 »
Logged
Re: Can I get some help.
« Reply #6 on: July 27, 2014, 09:43:00 am »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
Alternatively...  and mostly because I feel like giving this a whack, you could do all of this in a single loop without drawing multiple layers (meaning the background and the heart on top).  I am going to use the variables Health_X, and Health_Y to represent the position on the screen of the whole health bar.  I am also assuming a heart sprite called "sprHeart" is a sprite containing 5 images (0-Empty Black Heart, 4-Full Red Heart)

Code: [Select]
//Variables set in the create event
Health_X =  ??        //Enter the x position of health bar here
Health_Y =  ??        //Enter y position here
X_Grid = 6            //How many pixels over the next heart will be drawn
Y_Grid = 6            //How many pixels down the second row of hearts will be drawn
Max_Health = 80       //This would be assuming the player has two rows of 10 hearts with a quarter heart system  Every time the player gets a container heart this would be updated to reflect his current maximum.

//Draw event
Code: [Select]

//Initialize relavent variables
var i, Full_Hearts, Total_Hearts, Fraction;

//Determine which image to draw for the last heart containing health
Full_Hearts = floor(global.life/4);      //Stores the current number of full hearts
Fraction = global.life mod 4;            //Stores the fractional quantity of the last heart (0-3)
Total_Hearts = Max_Health/4              //Stores the total number of hearts the player currently has available

//Draw the players health bar
for (i=0 ; i<Total_Hearts ; i += 1)
{
     //Determine the location to draw the heart
     if i < 9     //Draw first row of hearts
     {
          if i < Full_Hearts     //Draw full hearts
          {
               draw_sprite(sprHeart,4,view_xview[0]+Health_X+i*X_Grid,view_yview[0]+Health_Y);
          }
          else
          {
               if i == Full_Hearts     //Draw fractional heart
               {
                    draw_sprite(sprHeart,Fraction,view_xview[0]+Health_X+i*X_Grid,view_yview[0]+Health_Y);
               }
               else     //draw empty hearts
               {
                    draw_sprite(sprHeart,0,view_xview[0]+Health_X+i*X_Grid,view_yview[0]+Health_Y);
               }
          }
     }
     else     //Draw second row of hearts
     {
          if i < Full_Hearts     //Draw full hearts
          {
               draw_sprite(sprHeart,4,view_xview[0]+Health_X+(i-10)*X_Grid,view_yview[0]+Health_Y+Y_Grid);
          }
          else
          {
               if i == Full_Hearts     //Draw fractional heart
               {
                    draw_sprite(sprHeart,Fraction,view_xview[0]+Health_X+(i-10)*X_Grid,view_yview[0]+Health_Y+Y_Grid);
               }
               else     //draw empty hearts
               {
                    draw_sprite(sprHeart,0,view_xview[0]+Health_X+(i-10)*X_Grid,view_yview[0]+Health_Y+Y_Grid);
               }
          }
     }
}



I guess I can't say for sure, but I think this would be more efficient, but it looks bigger because of all the comments and white space.  This is untested code, but it should work...  If you wanted it to be even more efficient you could update "Full_Hearts", "Fraction", and "Total_Hearts" outside of the draw event (could be updated every time the player is hit for example).

I don't even know GML, so this probably won't work, but that redundent code bugged me;

Code: [Select]
//Initialize relavent variables
var i, Total_Hearts;

//Determine which image to draw for the last heart containing health
Total_Hearts = Max_Health/4              //Stores the total number of hearts the player currently has available

//Draw the players health bar
for (i=0 ; i<Total_Hearts ; i += 1)
{
var row = i / 10
var column = i mod 10
var fractions = min(4, max(0, global.life - (i * 4)))

draw_sprite(sprHeart,fractions,view_xview[0]+Health_X+(column*X_Grid),view_yview[0]+Health_Y+(row*Y_Grid));
}
Logged
Re: Can I get some help.
« Reply #7 on: July 27, 2014, 12:46:02 pm »
  • ...---^^^---...
  • *
  • Reputation: +6/-0
  • Offline Offline
  • Gender: Male
  • Posts: 601
Where your code is running calculations to determine row, column, and fraction inside of the loop I am not entirely sure that it is faster in the end than using a few if checks.  Even though my code has redundant code, it being an if/else means only 1 of the halves is ever checked in one run of the loop.  Yours does look cleaner, and at first glance it seems it would work in gml.  From what I understand the mod operator is a slow one to calculate though, so running it 20 times per draw event I think would be slower in the end.  I could be wrong though.
« Last Edit: July 27, 2014, 12:55:15 pm by Aero88 »
Logged
Re: Can I get some help.
« Reply #8 on: July 27, 2014, 01:34:30 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
Where your code is running calculations to determine row, column, and fraction inside of the loop I am not entirely sure that it is faster in the end than using a few if checks.  Even though my code has redundant code, it being an if/else means only 1 of the halves is ever checked in one run of the loop.  Yours does look cleaner, and at first glance it seems it would work in gml.  From what I understand the mod operator is a slow one to calculate though, so running it 20 times per draw event I think would be slower in the end.  I could be wrong though.
Optimization is entirely redundant in that code, I only wrote that because its far more maintainable and less bloated to do it that way. Personal preference.

However if you want to talk optimization;

Branching is typically one of the most expensive operations you an execute on a CPU, they incur pipeline stalls and introduce branch-delay-slots. If you are ever trying to optimize code, the first thing you will want to do is remove redundant if statements. Modulus in practice on integral values shouldn't be particularly slow (its typically the same cost as a DIV instruction, plus a MOV (so worst case; 40 cycles?)).

GML will incur far higher costs being an interpreted language, but the principle of branching being one of the more expensive operations will probably still hold true.

Again, I was going for simpler code, not optimized :). Premature optimization is the bane of all evil in programming, its definitely not something you should consider in code like this unless you know its causing a problem.

« Last Edit: July 27, 2014, 01:36:20 pm by Infinitus »
Logged
Re: Can I get some help.
« Reply #9 on: July 27, 2014, 02:52:24 pm »
  • ...---^^^---...
  • *
  • Reputation: +6/-0
  • Offline Offline
  • Gender: Male
  • Posts: 601
I haven't taken any courses or really dug into the inner workings of how much each operation costs, and it sounds like you know what you are talking about so you are probably right.  I had heard that in GML at least the modulus operator is quite taxing though so my answer is based on that assumption.  It is quite likely that in the case of this code the difference in efficiency is quite negligible anyway, but it is interesting to conjecture.   :)

In either case both of these solutions are faster than looping twice to draw the background images and then the hearts.
« Last Edit: July 27, 2014, 02:54:35 pm by Aero88 »
Logged
Re: Can I get some help.
« Reply #10 on: July 27, 2014, 06:19:50 pm »
  • *
  • Reputation: +12/-2
  • Offline Offline
  • Gender: Male
  • Posts: 4836
As far as the slowness of Mod in GML, my game currently maintains an average of over 2k fps according to the console.  Seeing as the game runs at 160 x 144 to maintain Gameboy like presentation, the game never seems to slow.

Then again, I am coding on a second gen i7 quad with a 560 gtx m  gpu.  I do have much older hardware to test with ranging from Tseries C2duo, dual core  AMD Phenom II with Ati 4200 apu, and one of those old netbooks with an Atom and 950gma.

Optimization is on my back burner for when the game nears completion.  I already had a swell time rewriting all the audio code to remove the legacy sound as it causes glitches with mp3.

My issue with using a sprite font hasnt been fixed.  It always shows a black 8x8 square instead of the correct image for a letter/number.   I worked around it for now by having the string converted letter by letter to a value which ends up being the ccorrect iamge_index.

Should have something uploaded one of these days.
Logged
  • Super Fan Gamers!
Re: Can I get some help.
« Reply #11 on: July 27, 2014, 08:37:58 pm »
  • Minalien
  • *
  • Reputation: +10/-1
  • Offline Offline
  • Gender: Female
  • Posts: 2119
Let's assume for a second that for some reason the Mod operator is more expensive in GML.

It's not going to impact the game. Certainly not this one, and still not 99% of games ever created in Game Maker - by the time you've got a computer that this would have a negative impact on, said users aren't likely to run the game at all for entirely different reasons.
Logged
Quote
There's such a double standard about religion in the modern world. Catholics can gather, wear white robes, and say "In nomine Patris, et Filii, et Spiritus Sancti" and be considered normal.

But if my friends and I gather, wear black robes, and say  "Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn", we're considered cultists.
  • Development Blog

Diminish

4Sword
Re: Can I get some help.
« Reply #12 on: August 07, 2014, 06:28:53 am »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6582
I have no idea the full-scope of what a lot of you said, but in terms of inefficiency - using a for-loop to redraw the HUD every step can be implementationally wasteful and the use of targeted if-conditionals can allow you to make secondary logical assumptions which involve less calculation (as long as the code is commented properly, maintenance should not be too bad). I hope that does not sound argumentative.

The first point I am making is something I haven't taken advantage of until recently, but basically your health and rupees are not always constantly changing (for the most part the player avoids getting damage and is not swimming in boatloads of continuous rupees). Thus, in having a for-loop redraw everything when mostly nothing changes, means that for every step the HUD has to go through the calculations and conditionals to draw the stuff unnecessarily.

Solution: Use Surfaces. While in Game Maker 8, this was a paid feature, in Game Maker Studio Standard Edition, the surface functions are free to use. If your hearts/rupees don't change, you can just redraw the surface. When drawing sprites to the surface, always remember to clear out the surface if you are going to rebuild everything on it, and also to disable interpolation in the Game Options so that the sprites drawn to the surface aren't distorted.

Here is some sample code:
Code: [Select]
//build_hudSurface();
   
var i, j, k;

surface_set_target(hudSurface);

//clears/reinitializes the surface
draw_clear_alpha(c_white, 0);
   
if (heartsFull > 10) {
    if (heartsDraw > 10) {
 
        //draw 1st line of full hearts
        draw_sprite(sprHearts, 4,  0,  0);
        draw_sprite(sprHearts, 4,  8,  0);
        draw_sprite(sprHearts, 4, 16,  0);
        draw_sprite(sprHearts, 4, 24,  0);
        draw_sprite(sprHearts, 4, 32,  0);
        draw_sprite(sprHearts, 4, 40,  0);
        draw_sprite(sprHearts, 4, 48,  0);
        draw_sprite(sprHearts, 4, 56,  0);
        draw_sprite(sprHearts, 4, 64,  0);
        draw_sprite(sprHearts, 4, 72,  0);
   
        //draw 2nd line of empty hearts
        i = (heartsFull - 10) << 3;
        for (j = 0; j < i; j += 8)
            draw_sprite(sprHearts, 5, j, 8);
     
        //draw 2nd line of inactive full hearts
        k = ceil(heartsDraw);
        i = ((k - 10) << 3);
        for (j = 0; j < i; j += 8)
            draw_sprite(sprHearts, 4, j, 8);
     
        //draw 2nd line's active enlarged heart
        k = (k - heartsDraw) * 4;
        draw_sprite(sprHearts, k, j - 8, 8);
    }
    else {
         
        //draw 1st line of empty hearts
        draw_sprite(sprHearts, 5,  0,  0);
        draw_sprite(sprHearts, 5,  8,  0);
        draw_sprite(sprHearts, 5, 16,  0);
        draw_sprite(sprHearts, 5, 24,  0);
        draw_sprite(sprHearts, 5, 32,  0);
        draw_sprite(sprHearts, 5, 40,  0);
        draw_sprite(sprHearts, 5, 48,  0);
        draw_sprite(sprHearts, 5, 56,  0);
        draw_sprite(sprHearts, 5, 64,  0);
        draw_sprite(sprHearts, 5, 72,  0);
   
        //draw 2nd line of empty hearts
        i = (heartsFull - 10) << 3;
        for (j = 0; j < i; j += 8)
            draw_sprite(sprHearts, 5, j, 8);
 
        //draw 1st line of inactive full hearts
        k = ceil(heartsDraw);
        i = (k << 3);
        for (j = 0; j < i; j += 8)
            draw_sprite(sprHearts, 4, j, 0);
     
        //draw 1st line's active enlarged heart
        if (heartsDraw > 0) {
            k = (k - heartsDraw) * 4;
            draw_sprite(sprHearts, k, j - 8, 0);
        }
    }
}
else {

    //draw 1st line of empty hearts
    i = heartsFull << 3;
    for (j = 0; j < i; j += 8)
        draw_sprite(sprHearts, 5, j, 0);
   
    //draw 1st line of inactive full hearts
    k = ceil(heartsDraw);
    i = (k << 3);
    for (j = 0; j < i; j += 8)
        draw_sprite(sprHearts, 4, j, 0);
     
    //draw 1st line's active enlarged heart
    if (heartsDraw > 0) {
        k = (k - heartsDraw) * 4;
        draw_sprite(sprHearts, k, j - 8, 0);
    }
}

draw_sprite(sprRButton, 0, 198, 2);
draw_sprite(sprABButton, 0, 197, 15);
draw_sprite(sprABButton, 1, 173, 15);

surface_reset_target();

Disclaimer 1: The way I coded the demo takes advantage of a lot of "optimizations", but it is by no means completely optimized. It might be possible, for example, to rework the variable for-loops so that they both don't start from the beginning. The fixed drawn positions to the surface and starting for-loop values could be altered so that the draw_surface function used later would require no additional offset calculation.

Disclaimer 2: If I were to change around some of the code, I could have used the surfaces better. In my example demo, any time your hearts change it will rebuild the hearts entirely. Hypothetically, if I were to draw the active heart as a sprite and not a surface - to where I only was drawing empty and inactive full hearts to the surface, I could reduce the amount of surface operations. If, for  example, I added a heart, I could just draw it over the empty heart and if I took away a heart, I could just redraw an empty heart over an inactive full heart. This would make it to where the majority of heart HUD building is just the manipulation of changing one heart instead of rebuilding everything on the surface. Huzzah!

Anyway, I attached .gmx demo which is in the .rar file attached to the post.
« Last Edit: August 07, 2014, 06:33:14 pm by 4Sword »
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.077 seconds with 41 queries.