How do I most efficiently track sprite movement?

0 favourites
  • 5 posts
From the Asset Store
Weather Wind Sounds - Mountains contains 10 tracks (3 tracks and 7 seamless loops)
  • So I have been playing around with the preliminary work on an old school RPG that I used to play when I was a kid. And, I have been reading up on various ways of going about creating such a game (or at least starting to).

    Anyway, I have used some examples found on the net to make a sprite that moves in the specific fashion that I want (more of a per-tile movement, a la Final Fantasy etc).

    However, one of the things I want to do, is have the ability in specific layouts to have random battles. I was thinking that the best way to go about implementing such random battles would be to have a counter (instance variable of the sprite moving around) that increases with every successful step taken. However, I have been unable to figure out the best way to do this (or even a reliably functioning way to do this).

    I was thinking of using an invisible sprite, that when overlapped, would generate an increase in the variable, however it will scale up as long as I am overlapping - I can stop moving and it keeps increasing.

    Is there a way I can check to see if I have successfully changed position (perhaps by comparing the self.x and self.y position)?

    Or, there may be another way entirely.

    Link to the project file: http://www.spite.ca/construct2/game.capx

  • I don't know if I understood everything but...

    You can do like you said and add values to your variable using the "Every X seconds" so there's no need to identify if he's running or idle

    then using the expression random ( ) then set the value you've got to another variable that would trigger the encounter

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Sorry if I wasn't clear - I will try to rephrase.

    Basically, in certain areas of layouts I would want to increase a variable's value for every step the character takes.

    I was thinking of creating instance variables that would relate to the characters X and Y values, and then after a move takes, if those values are different than the current X and Y values, then add the value and do the math to check if a battle should take place. I will try and see if that gets me anywhere.

    If using "every x seconds" would accomplish that I would give it a try too, but I don't know how that would work. If you are adding values every X seconds wouldn't that just rack up the value over time regardless of movement?

  • If you really want to increase this value for every step that the character takes, just compare the frames from walking animation. If moving and If frame = 0 -> Add X number to your variable. So everytime that you complete an animation, would be an step. Bu be careful about the animation speed, otherwise you would increase that value too quickly.

  • Thanks for the suggestion! I have been playing around and will figure something out. I may try something animation wise, would have to be tweaked (since the character will only change animation frames once per tile instead entirely per tile), but you have already got me thinking more potential solutions!

    Thank you sir!

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