How to create a specific Sprite

Discussion and feedback on Construct 2

Post » Mon May 01, 2017 11:50 pm

Hey folks,

maybe a simple question but i have no idea to handle this.
How do you deal with inventories? Lets say there are hundreds of different items in your game and the player has five of them which you want to show with a little icon and the amount of it. i.e. five tomatos, three bananas, ....
So in json your inventory could be like this:
Code: Select all
[
   {
      "itemType": 1
      ,"count": 5
   }
   ,{
      "itemType": 2
      ,"count": 3
   }
]

How can i map those type-IDs to a specific sprite to spawn it in the inventory layer?
It seems that it is a problem in general to spawn a specific sprite.

How do you handle those use-cases?
B
4
Posts: 15
Reputation: 232

Post » Tue May 02, 2017 2:49 am

Prep: make sprite fill with frames where index corresponds to type-id

sprite set frame to itemType

or

Prep: add list populate where animation names match list items, and list index corresponds to type-id

list set selection itemType
sprite set animation list.selectedText


or

"itemType": 1
"count": 5
"animationName": "bananas"

sprite set animation/frame to array.at(x,y) (will be a bit different than this depend how you choose to set up your array)




you're question is kind broad there are probably dozens of ways to manipulating sprites like this.
B
25
S
16
G
26
Posts: 125
Reputation: 16,103

Post » Tue May 02, 2017 10:50 pm

Thanks for the answer.
So if i understand it correctly i need to use the animation of a single sprite and add frames for each sprite i want to spawn dynamically? So if i want to create i.e. sprite having ID 5 i need to spawn that generic sprite and switch to frame 5? So that could be a solution but would also prevent that those sprites can be animated, right? And also maintaining those sprites would get really nasty. Imagine hundreds of sprites and now you need to add, remove or update some of them.

What i did not understand completly is the 2nd example. is it possible to have different animations for a single sprite and give them names?
I guess the 3rd example addresses the count i mentioned, but i think you might got it wrong. It was not my intention to show different sprites for one or five bananas. the count would be just text.
Or did i get something wrong?
B
4
Posts: 15
Reputation: 232

Post » Wed May 03, 2017 1:51 am

"So if i understand it correctly i need to use the animation of a single sprite and add frames for each sprite i want to spawn dynamically? So if i want to create i.e. sprite having ID 5 i need to spawn that generic sprite and switch to frame 5? So that could be a solution but would also prevent that those sprites can be animated, right? And also maintaining those sprites would get really nasty. Imagine hundreds of sprites and now you need to add, remove or update some of them."

yes, that's correct and it can get messy for larger programs. (be sure to set animation speed to 0)

yes, you can have different animation in a single sprite. if you double click on the sprite to open the sprite editor you will see an animation named default right click to add more animations. you can also use different sprites but if it isn't necessary then extra sprites just clutter things up.

the 2nd method is just a way to make it work without using arrays.

As for the 3rd example I'm just saying you can stick the animation's name into your array and then call it with the .at() method. The count value wouldn't affect the sprite in any way. in plain speak im saying to the pc, "switch the sprite's animation to the value at this spot in the array."

maybe array.at(itemType's x value, itemType's y value + 2) makes more sense?

the 3rd method is probably the best way to set up larger games.
B
25
S
16
G
26
Posts: 125
Reputation: 16,103

Post » Thu May 04, 2017 6:51 am

Thanks a lot, i will give it a try. Good to know that there is a way without the nickname-plugin.
B
4
Posts: 15
Reputation: 232


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 15 guests