Pixel-precise custom movement on a grid.

Get help using Construct 2

Post » Fri Jan 06, 2012 1:13 pm

Hi,
I'm planning to make a grid system for a turn based game and searched through the forums to check what was done before, reading all the links in the how-to thread but the most detailed example I were able to find was from the Construct Classic era which is fine as CC turned out to be a familiar experience after using C2:

related topic

The example I linked above was probably before the time tiled backgrounds were implemented and I have no desire to place tons of empty sprites, bogging down cpu resources to create a grid so I'm thinking about moving objects in relative distances from where they were previosly or maybe keep possible x,y values in arrays and move sprites to them using the rex_moveto behaviour. However I prefer the stock behaviours as they might be less prone to bugs as more people use them and fixes are guaranteed to arrive (not that rex_moveto behaviour isn't cool as it is, just forcing myself to do things the intended way).

I'm going for the relative distance approach but having a problem: I'm never able to produce consistent results using custommovement to stop a sprite after moving a set number of pixels (in this case, 84). The result is unpredictable in the runtime and different in every case. I tried to set the x location of the sprite to floor() and int() of itself on every tick but this only removes the trailing digits and doesn't guarantee I'm going to get multiples of 84 every time. I'm assuming this is due to the delta timing features within the custommovement behaviour but I may be wrong on this.

Attached is a .capx that has an event disabled to show what I'm getting normally. Enable that events to see what I'm intending to end up with. I believe my current *fix* of the matter is a dirty hack and is doomed to cause collision related troubles in the long run or maybe I'm just being paranoid and this is how it's supposed to be like. I'd love to hear what experts can say on this matter.

Thanks :)Wronghands2012-05-27 13:02:13
B
47
S
3
G
5
Posts: 56
Reputation: 4,630

Post » Fri Jan 06, 2012 1:40 pm

Ok, after looking at you code, I would recoment, that you use the "every tick" event to move the sprite by "x" and check if the desired delta value is reached...
B
42
S
19
G
12
Posts: 723
Reputation: 13,911

Post » Fri Jan 06, 2012 4:16 pm

Last edited by Yann on Sun Sep 14, 2014 11:16 am, edited 1 time in total.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Fri Jan 06, 2012 4:51 pm

Nice example Yann.
B
86
S
14
G
9
Posts: 101
Reputation: 9,912

Post » Fri Jan 06, 2012 7:22 pm


Thank you for the replies. :)

[QUOTE=Weishaupt] Ok, after looking at you code, I would recoment, that you use the "every tick" event to move the sprite by "x" and check if the desired delta value is reached...[/QUOTE]

I'm not really sure what you meant but I'm interested to hear more :/

[QUOTE=Yann] http://dl.dropbox.com/u/23551572/C2/gridMovement.capx[/QUOTE]

Thanks, that's a very good example and I'll surely make use of instance variables like you did but rotating the sprites unintentionally rotates the pixel data within them and I'll have to find a workaround that doesn't use the angle parameter at all. This is what I mean.

Also if I understood correctly, even if you "Substract speed*dt from move" it may return a negative value and we may need to use the fix you already provided. IMO If there was a way to limit the maximum frame rate without using dt, I'd just drop the dt and all the hassle that comes with it. Inconsistent sprite movement speeds vs. sprite movements that don't stop accurately = I'd take the first one any day. I'm still feeling illiterate about it even after reading the available resources here but I just don't see how dt might come in handy in the case of turn based, non action oriented scenarios. I'm an interface designer, not a programmer, previous flash user and certainly not a flash fan. C2 with its brilliant event system helps me do what flash with all its weird elitist script driven ugly face didn't. Oddly enough timing was never an issue in flash and everything was fps driven. Or at least, it was never the user's responsibility to be bothered with whatever sorcery laid underneath. I know that C2 is new and yet incomplete and I'm not going to be alienated by this; probably learn more in time and keep supporting it but some way of simplifying these kind of issues is kinda required to keep non coders interested especially if they're attracted by "no coding required" slogan. I bet a couple behaviours will appear in some months and C2 will suddenly start catering people like me that aren't coders and are interested in making a 2d game that isn't action related or in real time.

Unrelated bug report for the devs:
I think I've come across an interesting Construct 2 bug on this example. Try creating an action from "textch" on every tick like I did with the other variables and text objects and set its text to the player's instance variable "checked" It'll work, the preview will work but it won't save! Next time you load the file the action will be gone. Looks like boolean instance variables have a problem with saving when called into text objects.
B
47
S
3
G
5
Posts: 56
Reputation: 4,630

Post » Fri Jan 06, 2012 8:06 pm

@Wronghands: For bug reports prefer to make them in the bugs forum following the instructions on how to report bugs. This is the better way to be sure that @Ashley treats/fixes it.

Be sure to post though, I reproduced the bug according to your steps.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Fri Jan 06, 2012 9:37 pm

Just keep the dt, it's not only a framerate thingy, it makes the movement smooth and consistant. And the substraction is what makes the movement pixel precise. It's not a fix it's just manual rounding. So I strongly suggest you keep it that way. One tiny action is not what we can call "a hassle" in my opinion.

Also, for the angle, I already thought about that. I could have simply used an instance variable. But it's just a sprite. It's just an object with angle and position. Nobody said you had to use the same object for graphically eye-candy stuff.
Just set the 'Player' sprite to invisible, and just make your character follow the position (and not the angle) of this 'Player' sprite.

And for the bug you talked about, I would guess that it's a type issue. booleans aren't string nor number. What is displayed in text should be strings or number converted into strings. C2 might not handle what is called type casting from boolean to string.
Yann2012-01-06 21:38:51
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Sat Jan 07, 2012 12:52 am

[QUOTE=Yann]
Also, for the angle, I already thought about that. I could have simply used an instance variable. But it's just a sprite. It's just an object with angle and position. Nobody said you had to use the same object for graphically eye-candy stuff.
Just set the 'Player' sprite to invisible, and just make your character follow the position (and not the angle) of this 'Player' sprite.
[/QUOTE]

That's simple and effective. Didn't think of it due to lack of experience. :)

I'd like to use mouse controls however and were going to attempt merging what I learned here with Kyatric's pathfinder behaviour, moving tile by tile with the data generated by pathfinder but with the time based animation logic you provided but then again I thought I could just use the default 8 direction behaviour with pathfinder now that you gave me the idea above! This is still well above my head so I'll be heading back to forums quite often. Will try to use this thread to keep things tidy. :) Thanks again.

@Kyatric

Done!Wronghands2012-01-07 00:58:38
B
47
S
3
G
5
Posts: 56
Reputation: 4,630

Post » Sat Jan 07, 2012 1:55 am

@Wronghands: Your issue with the iFrame is maybe not a bug.
Sorry for the misguidance.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Sat Jan 07, 2012 2:00 am

That must be someone else's bug, I never even used iframe in C2 :)
B
47
S
3
G
5
Posts: 56
Reputation: 4,630

Next

Return to How do I....?

Who is online

Users browsing this forum: Artpunk, DemantDigitalArt and 31 guests