2 Problems: Loop

Get help using Construct 2

Post » Mon Jun 18, 2012 5:00 am

Hi all, i couldn't figure out how to use loop correctly for each enemy patrol.

There 2 problems

1- How to create shadows for each sprite using loop and stop loop when it's done to all sprites have shadows now? I did it but, it appears it won't stop creating objects and causes performance issue.


2- How to fix the wrong angle of motion frames and stop imitating the same frame to sprite #1?


It seems a sprite number #1 does the direction of patrol was correct, besides they were incorrect.


There a .capx


http://dl.dropbox.com/u/76227787/MistakeLoop.capx


Thanks!Joannesalfa2012-06-18 05:01:59
B
96
S
25
G
20
Posts: 3,054
Reputation: 22,642

Post » Mon Jun 18, 2012 7:10 am

1. The system compare condition does no picking so place events 2-5 as sub-events of a "for each Patrol".

2. Duplicate the shadow object in the layout so you have 3 instances. Replace event 6 with:
+Every Tick
--- Shadow: set position to Patrol
B
79
S
24
G
54
Posts: 4,746
Reputation: 40,755

Post » Mon Jun 18, 2012 7:30 am

[QUOTE=R0J0hound] 1. The system compare condition does no picking so place events 2-5 as sub-events of a "for each Patrol".

2. Duplicate the shadow object in the layout so you have 3 instances. Replace event 6 with:
+Every Tick
--- Shadow: set position to Patrol[/QUOTE]

It worked!   

Thank you a lot!

Does there no way to generate shadows according to how many enemies on a layout?
B
96
S
25
G
20
Posts: 3,054
Reputation: 22,642

Post » Mon Jun 18, 2012 8:28 am

Also, i would like to know one more thing, how to make every patrols to wait for 2 or 4 seconds what they choose time before to move? i wouldn't to see these patrols walk in synchronization, it must be desynchronization.
B
96
S
25
G
20
Posts: 3,054
Reputation: 22,642

Post » Mon Jun 18, 2012 6:04 pm

You can create the shadows with events. For the method I gave you just make sure that the number of shadows matches the number of patrol. If the number is less create another, and if it's more delete one.
Another method would be to use an instance variable in the patrol to keep track of the UID of it's shadow.

You can make them move out of sync with a Boolean instance variable and the wait action:

+patrol: is NOT patrolling
+for each patrol
--- patrol: set patrolling to true
--- wait random(2,4) seconds
--- patrol: set angle of motion...
--- patrol: set speed...
--- wait 1 second
--- patrol: stop
--- patrol: set patrolling to false

Of course you could alternatively use a variable to make a timer.
B
79
S
24
G
54
Posts: 4,746
Reputation: 40,755

Post » Mon Jun 18, 2012 9:55 pm

[QUOTE=R0J0hound] You can create the shadows with events. For the method I gave you just make sure that the number of shadows matches the number of patrol. If the number is less create another, and if it's more delete one.
Another method would be to use an instance variable in the patrol to keep track of the UID of it's shadow.

You can make them move out of sync with a Boolean instance variable and the wait action:

+patrol: is NOT patrolling
+for each patrol
--- patrol: set patrolling to true
--- wait random(2,4) seconds
--- patrol: set angle of motion...
--- patrol: set speed...
--- wait 1 second
--- patrol: stop
--- patrol: set patrolling to false

Of course you could alternatively use a variable to make a timer.[/QUOTE]

Ok, i tought loop system can automatically generate quantity of sprites to each other sprites on the layout, actually it doesnt and we should to do manual way like copy each sprite for other sprites.



I implemented with your method about patrol and it worked like a charm. Thanks!
B
96
S
25
G
20
Posts: 3,054
Reputation: 22,642

Post » Tue Jun 19, 2012 4:55 pm

try a 'on create' event for your patrol and make it make its own shadow object. Then every time a patrol is created itll make its own shadow without you havin to keep up with it. Just make sure you store the shadow object thats created with an instance var for that patrol so when the patrols deleted it can delete its shadow in an 'on destroy' event
B
13
S
5
G
2
Posts: 306
Reputation: 3,262

Post » Tue Jun 19, 2012 9:35 pm

[QUOTE=aridale] try a 'on create' event for your patrol and make it make its own shadow object. Then every time a patrol is created itll make its own shadow without you havin to keep up with it. Just make sure you store the shadow object thats created with an instance var for that patrol so when the patrols deleted it can delete its shadow in an 'on destroy' event[/QUOTE]

I've created another event "on destroy" with Pick nth, Instance patrol.IID that automatically destroys the shadow container according to ROJOhound's container from CC code on C2.

Also im curious about "On Created", would you like to make an code example? i'm sorry is quite hard to understand due to logic verb.
B
96
S
25
G
20
Posts: 3,054
Reputation: 22,642


Return to How do I....?

Who is online

Users browsing this forum: MarkThomas, theosciandra and 17 guests