How do I refer to a sprite object by another sprite object

0 favourites
  • 2 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • I have in my game a weapons store and a player inventory like this:

    Weapons Store:

    Weapon image (sprite)

    " "

    " "

    " "

    and etc.

    Player Inventory:

    Empty cell (sprite)

    " "

    " "

    " "

    and etc.

    Purchase Button (sprite)

    When the player chooses one of the weapons in the weapons store, then another sprite object

    appears on top of the weapon's raw for showing the chosen object (an empty rectangle sprite object).

    When the player clicks the "Purchase" button, I would like the chosen weapon sprite object to appear

    in the parallel player inventory's empty cell.

    Is there any way to refer to the weapon's sprite object through the location of the focus on the chosen weapon to purchase ?

    The only way I see right now is by using the following event (long and cumbersome):

    Event: WeaponFocus (sprite image name) y = 200 Action: WeaponName (sprite) Set position to Cell1 (sprite image name)

    Event: WeaponFocus (sprite image name) y = 230 Action: WeaponName (sprite) Set position to Cell2 (sprite image name)

    Event: WeaponFocus (sprite image name) y = 260 Action: WeaponName (sprite) Set position to Cell3 (sprite image name)

    " "

    " "

    " "

    and etc.

    So if I have for example 40 raws of weapons in the store would I have to add 40 event lines instead of referring to

    the weapon sprite image name automatically by a single type of event ?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I am not too sure if I understand, but it sounds like you are trying to show which weapon the player has selected while being efficient and without having to code very long.

    If that's the case, you could use animation frames. Use a sprite and import all the weapon images into it. So if you have 40 weapons, it will have 0-39 frames. Create a variable to determine which weapon the player is selecting. For example: if player touches on weapon no 5, save it to the variable. Than use the every tick or every x seconds, and tell the weapon image sprite to set animation frame to (yourvariable-1) (you put a minus 1 inside there since your frames start from 0 and not 1). Thought should do the trick while making it easy on the eyes as well. Oh and don't forget in the animation tab of your weapon sprite, set the play speed and playback to 0.

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