Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 564485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:46:18+00:00 2026-05-13T12:46:18+00:00

I have a question in game development. I am building a game for iPhone.

  • 0

I have a question in game development. I am building a game for iPhone. At the game play, there is a damage bar, that displays what the player has damage the enemies. The technique I use is using 2 pictures.
One is a damage bar which is fill with full damage, and one is jus a black bar but same size with the damage bar. It is like masking. I will scale the black bar shorter whenever it receives the value of the damage. But the problem here is the method i use to calculate the damage is different class from the method i use to draw the black bar. How do I draw it frequently everytime it gets a damage value? please help me , thank you so much.

-(void)damageTaken
{
    totalDamage = 0;
    for (uint i = 0 ; i< [bodyParts count]; i++) {
        RagdollBodypart *part = (RagdollBodypart *)[bodyParts objectAtIndex:i];
        totalDamage += part.damage;
    }
    [[NSNotificationCenter defaultCenter] postNotificationName:DAMAGE_TAKEN object:nil];
}

above is the method I used to calculate the damage. It will get called everytime the player hits something. It is created in a class called BodyDamage

This is the code i use to draw the mask for the damage bar. it just runs once, how can I run this with the number of time same as the damageTaken?

 float damage = [[GameController instance].engine.enemies totalDamage];
                        float scale = (float)(1400 -damage)/(float)1400;
                        [damageSprMask setScaleY:scale];
                        //[damageSprMask setPosition:ccp(20,150)];
                        [damageSprMask setPosition:ccp(20,150 +((1- damageSprMask.scaleY)*damageSpr.contentSize.height)/2)];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T12:46:18+00:00Added an answer on May 13, 2026 at 12:46 pm

    To cause a view to redraw itself you can use [view setNeedsDisplay] this will trigger the drawRect method for the view.

    So you can either call directly in damageTaken or in the method that listens for the notification you’re sending.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say we have a two players game, where one player always wins (there
I am fairly new to iPhone/ObjC programming, though I have several years of experience
I'm building a game which works as some type of a quiz. I ask
Edit: Just wanted to make the question I have more clear. I pretty much
i have a trivia game and i want to reward users for 2 events:
I am a new to developing for Android and have been reading up and
I'm coming from a background developing business applications so am used to MVC/n-Tier development.
I have the following tables for a competition: User: Id Name Email EntryId Entry:
This is the only official documentation available for the Halo: Reach stats API. If
I'm trying to get to grips with how Lua works, and how it can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.