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

Get help using Construct 2

Post » Sat Jul 26, 2014 1:55 pm

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 ??
B
9
S
2
Posts: 108
Reputation: 1,010

Post » Sat Jul 26, 2014 2:46 pm

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.
ImageImageImage
B
71
S
22
G
240
Posts: 3,734
Reputation: 133,994

Post » Sat Jul 26, 2014 5:20 pm

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??
B
9
S
2
Posts: 108
Reputation: 1,010

Post » Sat Jul 26, 2014 5:58 pm

You would still create 100 sprites, but each with a different frame. The instance variable would still apply to each instance, uniquely.
ImageImageImage
B
71
S
22
G
240
Posts: 3,734
Reputation: 133,994

Post » Sun Jul 27, 2014 6:33 pm

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???
B
9
S
2
Posts: 108
Reputation: 1,010

Post » Sun Jul 27, 2014 7:30 pm

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.
B
86
S
43
G
71
Posts: 601
Reputation: 43,619


Return to How do I....?

Who is online

Users browsing this forum: suzannegrey and 31 guests