How do I create a dynamic object based on id or sprite name

0 favourites
  • 6 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • I could have around 100 different sprites , and these 100 sprites has different scoring points. My game works like if the user give a integer input as an id then that particular sprite whose id is same will be made and display on the screen... The problem is using "Create Object" provides a list to select the object...which means based on user input id i have to put 100 different type of "if cases" ... e.g.

    if user input 11 then create sprite whose id is 11 .... if 12 then create 12 ...

    Is there any other way to create dynamic object based on user input rather than hardcoding the object list 100 times???If its not available then any other tip or way to achieve the same ??

  • Typically you would have one sprite with 100 frames. Then the frame number corresponds to the input/ID. Assuming that works with what you were planning.

  • not a bad idea , but these each sprites has different sizes and their categories are different from each other they cannot be merge together as frame. Plus suppose if i follow that then again saving each sprite's frame data is not supported by construct2 like say frame1 contain instance variable id 101 and frame2 instance varibale id contain 3....for this i need to create separate dictionary or array.... any more ideas??

  • You would still create 100 sprites, but each with a different frame. The instance variable would still apply to each instance, uniquely.

  • But one thing that we cannot add instance variable based on each frame but per instance so it means i cannot hard code their ids value so at the time of creation i can pick them via their id instead of remembering their frame key. For e.g.

    User has input X

    Create object XYZ

    Get the frame of object XYZ which contain id X

    since i need to create an object dynamically based on user input...what you think???

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • does each sprite have an entirely different set of instance variables, or are you just wanting to set the same set of variables differently for each sprite as it's created?

    if the latter, then sounds like you would use an array containing the id and all the values for each sprite and as the sprite is created, choose the appropriate location in the array and set the corresponding variables from the array.

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