Using Change Image behaviour frequently

CapCap Member Posts: 225
edited November -1 in Working with GS (Mac)
Hi,

at the moment I'm frequently changing the image from an enemy actor every few seconds. The points for destroying this enemy actor depends on the image that is set. This seems to work.

So when the enemy gets hit I use;
if self.image contains "image1"
game.points = game.points +100
if self.image contains "image2"
game.points = game.points +200
etc

Any doubts or suggestions?
Thanks.

Comments

  • IgnisIgnis Member Posts: 72
    Instead, could you just create a custom actor attribute (integer) for these enemies called "points_on_hit" (or similar) and then change that value each time you change the image? Upon hit/kill, that number would be added to game.points. I think that would spare the potentially memory-taxing routine of if>then, if>then, if>then, etc.

    Maybe this isn't what you had in mind, but that's my suggestion. I suppose it wouldn't work if you're randomly changing the image in a repeating timer; in that case the game wouldn't know which image was associated with which point value, and you'd have to rely on the if>then series to determine that "small=100", "medium=200", "large=500", or whatever you're doing.

    Best of luck,
    Brent
  • CapCap Member Posts: 225
    Hi,

    thanks for your answer!

    It's like that: at the moment I have four different enemies with four different point values. But instead of creating four different actors, I created just one and put this one actor eight or ten times in my scene (as often as I need it). The image of this enemy actor is chosen randomly, and until now if I hit an enemy I just check what image this enemy actor has to get the appropriate point value. I thought that would be more efficient than creating different actors.
    As long as we can't use arrays, we have to be inventive. :-)

    What do you think of that? I'll check if I can use your suggestion, thanks a lot.
  • BarkBarkCoBarkBarkCo Member Posts: 1,400
    depending on how you are randomly assigning the image, you probably already have some type of ID value that you are adding a random value to prior to picking your image...am I close?

    if I'm wrong, it probably would be hard to add an integer attribute and change it to the number associated with the image selected. then you can use that integer as a multiplier for your scoring system:

    `
    Rule: When enemy gets hit: (no checking for image type here!)
    -- change game.points to game.points+(self.enemyID*100)
    `
    this saves you at least one rule/condition for every possible enemy type...
  • CapCap Member Posts: 225
    Hi,

    well, that was a neat idea!

    It's like you said, I randomly add an integer value to change the image:

    self.type = random(1,4)
    if self.type = 1
    change image
    change size
    if self.type = 2
    etc...

    Now when I check for collision, I don't check the image type anymore, but use your rule

    Rule: When enemy gets hit:
    -- change game.points to game.points+(self.type*100)

    That works great, but I don't really have the power to set the exact point value anymore, as type will always be between 1 and 4. It probably would be better if I could do something like that when I chose the enemy type:

    instead of...
    self.type = random(1,4)

    I could do something like...

    self.type = random(enemy1points,enemy2points,enemy3points,enemy4points)

    This way I would have control over the exact point value. Hope you understand what I mean. ;-)

    But your suggestion at least helped me to throw out some conditions, thanks a lot! :-)
  • BarkBarkCoBarkBarkCo Member Posts: 1,400
    if you're already setting the image and size once your random value is determined, why not add an attribute for the value when destroyed and set that at the same time?

    `
    self.type = random(1,4)
    if self.type = 1
    change image
    change size
    change score value
    if self.type = 2
    etc...
    `
    when the enemy gets hit you could just do the following:

    `change game.points to game.points+(self.value)`
  • CapCap Member Posts: 225
    Hm. Okay, then I have to add some change attributes for the score. That's probably more efficient then the if...then rules I had before for checking the score by parsing the images.

    By the way: thanks for all the answers I get here. That's really important if you're new to GS. :-)
Sign In or Register to comment.