How do I most efficiently track sprite movement?

Just started using Construct 2? Post your questions here

Post » Tue Mar 18, 2014 9:14 pm

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
B
3
G
1
Posts: 9
Reputation: 318

Post » Wed Mar 19, 2014 2:12 am

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
B
56
S
21
G
3
Posts: 602
Reputation: 6,612

Post » Wed Mar 19, 2014 3:22 am

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?
B
3
G
1
Posts: 9
Reputation: 318

Post » Wed Mar 19, 2014 6:52 am

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.
B
56
S
21
G
3
Posts: 602
Reputation: 6,612

Post » Wed Mar 19, 2014 6:48 pm

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!
B
3
G
1
Posts: 9
Reputation: 318


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests