How do I send sprites as a parameter for functions ?

  • I need to use the same function with a sprite object in it to loop and work on any sprite that is send to it.

    As an example,

    When layout is loaded, Function : Call "GenerateEnemy" ("RedEnemySprite", 100, 12)

    Function : On "GenerateEnemy",

    • Set RedEnemySprite instance variable Hitpoints to 100.
    • Set RedEnemySprite instance variable Attack to 12.
    • Create RedEnemySprite at SpawnLocationSprite position.

    Like in this example, anything like RedEnemySprite, KnightEnemySprite, MonsterEnemySprite or GhostEnemySprite need to be send to the same function so that instead of RedEnemySprite, it will do that. Otherwise there is the need to create the same three events for each enemy like this.

    So is it possible to send a sprite through a parameter or variable so that different ones can be passed through it and to act on it ?

  • no you can't, but you can pass to the function a parameter that represents the sprite that you want to create, then comparing it with all the possible values, you can create sub conditions for each variant

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can add all such sprites to a family, this will allow to optimize some of your code.

    But you'll still need to have separate event for creating each of the sprite types.

    Construct 3 allows creating objects by their name - Create "RedEnemy".

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