How do I subtract a portion of width from a tiled object!?

0 favourites
From the Asset Store
Piano tiles
$9.99 USD
Template for a piano tiles game, fully documented in comments and video
  • Hello all, I'm having a problem with my game, the lives left system won't work properly. The game will properly add width to the tiled background (which is a heart, representing the characters lives left) when you beat a level, but for some reason it will not subtract any width from it at all (it just seems to ignore the highlighted code below which tells it to subtract 24 pixels from the tiled object/hearts). Can somebody help me to figure out why this is happening? Any help at all would be greatly appreciated.

    Thanks,

    guannstar

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hey, I forgot to say that I also tried to simply subtract 1 (instead of trying to subtract by setting a width) from the tile object/heart's instance variable... needless to say, that didn't work either. I really need some help with this problem. I've been stuck on this for like a week now:(

  • Bump.

  • So many events that coulde be replaced by:

    LifeHeartTiled set width to: varlifeHearts*24

    I guess all enemyhealth global variables are the health for enemies on the layout.

    wouldn't it be easier to make that an instance variable and add 1 to varlifehealths on enemy destroyed?

  • "So many events that coulde be replaced by: LifeHeartTiled set width to: varlifeHearts*24"

    What do you mean by that? Could you explain further? Doesn't that mean it will just set the width to 24 pixels no matter what?

    Also, are you saying to turn all my enemyhealth global variables into instance variables? Or are you saying that when I destroy a level's enemies, just add 1 to varlifehealths's instance variables instead of setting variables to the next specific number?

  • All your events are being checked all the time.

    what you should do is something like this:

    Give the enemy an instance variable Health

    enemy : variable Health =< 0

    • enemy destroy

    On enemy destroyed

    • system subtract 1 from varlifehearts
    • LifeheartTiled set width : varlifehearts*24

    Are all your enemies different sprites or are they the same enemy cloned?

    For if they are cloned, I would recommend using copies rather than clones so they all respond to the same actions. (I'm assuming you don't have a paid version, for if so you could use families for that)

  • I do have a paid version, and I am using families. But, I don't want to subtract 1 from varlifeHearts on enemy destroyed, I want to subtract 1 from varlifeHearts when my character dies (the tiled hearts represent the character's lives left, not the enemy's).

  • [quote:1iglhjj6]I do have a paid version, and I am using families. But, I don't want to subtract 1 from varlifeHearts on enemy destroyed, I want to subtract 1 from varlifeHearts when my character dies (the tiled hearts represent the character's lives left, not the enemy's).

    Then you just need to do a slight adjustment to LittleStain's example:

    enemy : variable Health =< 0

    • enemy destroy

    On enemy destroyed

    • system add 1 to varlifehearts (since the events you posted seem to be increasing lives when enemies are destroyed)
    • LifeheartTiled set width : varlifehearts*24

    character : variable Health =< 0

    • system subtract 1 from varlifehearts
    • LifeheartTiled set width : varlifehearts*24
  • OK thanks guys, I'll try it and see if it works out.

  • I haven't read the whole post, but someone asked for a similiar (if not identical) thing a few days ago.

    Check if that helps.

  • Hey OddConfection, I tried what you said, but it's still not working for some crazy reason:( What did I do it wrong?

  • Bump.

  • Delete what is red and add the green bits..

    [attachment=0:rlvqjjaj][/attachment:rlvqjjaj]

  • Hey LittleStain, I'll add the "trigger once while true" conditions, but I don't get why I have to delete everything involving all other enemies and levels, and just leave the code involving the the first enemy and level one? Why would I do that (I don't get it)? Could you please explain what you mean?

  • Can somebody please show me a little tutorial/capx which shows exactly how to do this (I'm seriously going crazy over here trying to figure this thing out lol)? It seems like this problem should be soo easy to fix, I don't get it.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)