How to create a specific Sprite

0 favourites
  • 5 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • 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:

    [
    	{
    		"itemType": 1
    		,"count": 5
    	}
    	,{
    		"itemType": 2
    		,"count": 3
    	}
    ][/code:1y1ihw4p]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?
  • 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.

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

  • "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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks a lot, i will give it a try. Good to know that there is a way without the nickname-plugin.

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