Move Sprite based on Array values

0 favourites
  • 10 posts
From the Asset Store
This is a code so you can see the same skin on all screens (peers). Each peer gets a skin, in addition to 4 directions t
  • 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?

    <img src="" border="0" />

  • The for each in array is just like a loop.

    It all runs within that event, that tick.

  • 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.

  • 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).

  • 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?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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.

  • 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.

  • The new timer behavior would work nicely here.

  • Never could get it to work and have moved on to something different. Thank you guys for all your help.

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