0 Favourites

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

  • 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 ?

  • Construct 3

    Buy Construct 3

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

    Buy 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)
Similar Topics Posts Views Last Post
Unread hot topic
0 Favourites
Sprite Font Generator - v3
368 112,286
RetroDaddy's avatar
RetroDaddy
Unread hot topic
86 28,707
St4rDu57's avatar
St4rDu57
Unread hot topic
99 10,136
karshinkoff's avatar
karshinkoff