Move Sprite based on Array values

Get help using Construct 2

Post » Sat Aug 24, 2013 7:20 pm

I have an Array with values in it and I want to move a Sprite based on those values. I'm trying to use a "For each element" statement to retrieve the values for the x position of the Sprite after I press a key. The Sprite moves but only to the last position in the Array. Am I missing something? like a Next statement?



B
21
S
8
G
3
Posts: 73
Reputation: 4,200

Post » Sat Aug 24, 2013 8:12 pm

The for each in array is just like a loop.
It all runs within that event, that tick.
Image ImageImage
B
168
S
50
G
164
Posts: 8,236
Reputation: 105,591

Post » Sun Aug 25, 2013 4:10 am

Thank you, Newt. Thats what I thought. So is the logic right? When a key is pressed it should run thru the the Array and retrieve the values? I know there are values in the Array because I can see them with the awesome debugger that Constuct now has.
B
21
S
8
G
3
Posts: 73
Reputation: 4,200

Post » Sun Aug 25, 2013 1:30 pm

@dinofun

It looks to me like it's correct. It is just running through all of the positions faster than you can see. You need to set a timer to delay it going to each position (run the loop every x seconds instead).
B
103
S
38
G
19
Posts: 962
Reputation: 17,986

Post » Sun Aug 25, 2013 5:38 pm

Can't seem to slow it down at all with any kind of timer. Maybe using an array is not the right way to do what I'm trying to do. I want to click and hold the mouse button down somewhere on the screen, move it around some and then at a later time make a Sprite follow that same path that I made with the mouse. Anyone know of a good way to capture and store mouse movements?
B
21
S
8
G
3
Posts: 73
Reputation: 4,200

Post » Sun Aug 25, 2013 8:12 pm

One way to do it would be to add a "wait array.curX*1.0 seconds" action right above the set position action. Just change the 1.0 to how many seconds each position should have.
B
91
S
31
G
103
Posts: 5,238
Reputation: 67,762

Post » Mon Aug 26, 2013 4:44 am

Thanks R0J0hound
I'm still having issues so I think maybe it might be something in the way the Array is being filled. I'm going to make sure that part of it is correct before trying to move the Sprite. Appreciate your help muchly.
B
21
S
8
G
3
Posts: 73
Reputation: 4,200

Post » Mon Aug 26, 2013 5:40 pm

Having a loop with a pause between iteration kind of defeats the purpose of the loop altogether. I'd use a variable to keep track of the index instead of curX and do the positionning with the timer behavior or something equivalent.
B
67
S
28
G
24
Posts: 970
Reputation: 18,675

Post » Mon Aug 26, 2013 6:29 pm

The new timer behavior would work nicely here.
Image ImageImage
B
168
S
50
G
164
Posts: 8,236
Reputation: 105,591

Post » Fri Sep 06, 2013 5:54 am

Never could get it to work and have moved on to something different. Thank you guys for all your help.
B
21
S
8
G
3
Posts: 73
Reputation: 4,200

Next

Return to How do I....?

Who is online

Users browsing this forum: Darth Crusher and 2 guests