1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

Why doesn't my image_index work?

Discussion in 'Programming' started by no1youngin, Dec 3, 2019.

  1. no1youngin

    no1youngin Member

    Joined:
    Nov 28, 2019
    Posts:
    7
    trying to make my sprite turn white for a second once taking damage (by touching the bullet).
    the first image_index is the normal enemy, the second is the enemy colored in white. made this code in the step event of the enemy. Why doesn't this work?

    if place_meeting(x,y,obj_bullet)
    {
    image_index = 1;
    }

    if !place_meeting (x,y,obj_bullet)
    {
    image_index = 0;
    }
     
  2. Dr_Nomz

    Dr_Nomz Member

    Joined:
    Oct 31, 2016
    Posts:
    619
    Maybe it's happening too fast to see? I mean what you've got here is basically telling it to flash for 1 frame out of what, 30? More? It's gonna be hard to tell if anything happened at all with so few frames, I'd recommend 4 or 5 at least. As for the problem at hand, try slowing it down first and see if that helps. (I like to bind a key in my control object that slows it down on key press to like 5 steps per second, and upon releasing the same key it sets it back to normal room speed)
     
  3. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,121
    I see a couple issues. First a very minor one. There's no reason to have both if statements. You should only have one.

    Code:
    
    if place_meeting(x,y,obj_bullet)
    {
        image_index = 1;
    }
    else
    {
        image_index = 0;
    }
    
    
    Second, this code actually is good and would work, so something else must be causing the issue. There are two likely scenarios. The first is that you have other code somewhere else overwriting this. The second, is that you are destroying obj_bullet on contact. So as dr_Nomz pointed out, the image_index will only be 1 for at most one frame, and maybe not even that. For example, if the bullet is destroyed in its own collision or step event, it might be gone before this portion of the code runs later in the same step event.
     
  4. Erramir

    Erramir Member

    Joined:
    Dec 2, 2019
    Posts:
    9
    i am not a pro but:

    while we could find a solution to the code , you actually need a shader to make the character "twinkle"

    the code you are attempting to do is more for other stuff like changing a sprite index for when the characters is jumping , walking, running
     
  5. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,136
    On bullet collision set the enemy's alarm to 20 or something and set its its image_index to 1. In the alarm event, set image_index to 0.

    This is only really suitable for this particular style of hit notification/sprute handling.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice