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

Get help using Construct 2

Post » Wed Dec 24, 2014 1:58 am

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):
[b]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 ?
B
5
S
1
Posts: 22
Reputation: 417

Post » Wed Dec 24, 2014 2:12 am

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.
B
42
S
21
G
31
Posts: 685
Reputation: 20,321


Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go and 9 guests