Help simplifying my code

Discussion and feedback on Construct 2

Post » Fri Aug 08, 2014 1:04 am

I know there must be an easier way to set this up. I am spawning platforms that scroll to the left. Each platform has an instance variable which tells the platform weather or not it should have a box sitting on it and which type that box should be. The problem I am having is that I have to define each action for each platform. For instance, if I wanted to add a different box type, I would have to go to each platform setup and add that box type to it. It just seems like a waste of time, plus the code is getting really messy.
I have attached a simplified CAPx of my project to this thread. My actual game is much more complex and has a lot more platform calls, but this should be able to illustrate my problem. Please help!
You do not have the required permissions to view the files attached to this post.
B
6
S
1
Posts: 28
Reputation: 554

Post » Fri Aug 08, 2014 2:34 am

Not exactly sure what you're looking for. But sounds like it might be functions.

https://www.scirra.com/manual/149/function
B
88
S
43
G
71
Posts: 601
Reputation: 43,669

Post » Fri Aug 08, 2014 2:50 am

You don't need separate objects. Use one object with different frames. Then you just create the object showing the appropriate frame. This will make life much easier.
ImageImageImage
B
71
S
22
G
259
Posts: 3,794
Reputation: 143,704

Post » Fri Aug 08, 2014 1:30 pm

That's an interesting solution. I was thinking I would have to set up a loop of some kind. I'll try setting up one object with multiple frames and see how that works out. It should definitely reduce some of my code.
B
6
S
1
Posts: 28
Reputation: 554

Post » Fri Aug 08, 2014 7:04 pm

So far this is working great. Very elegant workaround, thanks for the tip Blackhornet!
B
6
S
1
Posts: 28
Reputation: 554


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 8 guests