[Solved] pixel-perfect platform engine using loops

Get help using Construct 2

Post » Sun Apr 07, 2013 12:44 am

EDIT. SOLVED thanks to @Magistross and @retrodude and @newt:


.capx
https://dl.dropbox.com/u/28087823/Construct%20Examples/pixel-perfect%20engine%20with%20loops%20-%20no%20slope/jumpy3.capx

playable here:
https://dl.dropbox.com/u/28087823/Construct%20Examples/pixel-perfect%20engine%20with%20loops%20-%20no%20slope/index.html

____________________________

Hi everyone!

I'm Christina. Long time lurker, first time posting.

I've been disappointed with the lack of pixel-perfect controls in Construct2, since I have my sights on making a simple metroidvania as practice, and I really need to save time by using small pixelart sprites.

This (http://69.24.73.172/scirra/forum/viewtopic.php?f=8&t=1095) custom platform engine by Kayin is awesome , but when translated into C2, it suffers from the 1-pixel inaccuracy problem (http://www.scirra.com/forum/platform-object-sinks-into-solid-ground-bug_topic57004.html)

I managed to find an old trustworthy MMF2 method by Damian (http://damiansgames.com/post/6923285368/making-a-platformer-in-multimedia-fusion-2-or-games) and successfully ported it into C2.

I had to make the player sprite's bounding box one pixel smaller on each side (player sprite is 25x25px, player bounding box is 23x23px), but other than that it works great. I'm sure I could clean it up a little, especially those "direction" variables.

If anyone wants to take a look, the project is here

https://dl.dropbox.com/u/28087823/Construct%20Examples/pixel-perfect%20engine%20with%20loops%20-%20no%20slope/index.html

and .capx is here

https://dl.dropbox.com/u/28087823/Construct%20Examples/pixel-perfect%20engine%20with%20loops%20-%20no%20slope/test%20movement%20with%20actual%20loop.capx

So!

1st Question: is there any way to implement slopes in an engine like this? I mean small, 1-pixel steps, that the player sprite can climb, like Kayin's. Check the .capx , that small pixel-high bump on the floor is enough to completely stop the player sprite - which is good, it means pixel-perfect collisions are working. I tried using a slopeDetector sprite, but it kept thinking the walls were slopes. Perhaps I'm missing something.

2nd question: does anyone know why this engine won't play nice with dt? I tried introducing 60*dt instead of 1px steps and movement immediately becomes erratic. Jump strength becomes random as well. Does using pixel-perfect collision loops come at a price?


Glad to be here :)christina2013-04-21 00:45:09
B
19
S
7
G
2
Posts: 188
Reputation: 2,846

Post » Sun Apr 07, 2013 1:04 am

[QUOTE=christina] Hi everyone!

I'm Christina. Long time lurker, first time posting.

I've been disappointed with the lack of pixel-perfect controls in Construct2, since I have my sights on making a simple metroidvania as practice, and I really need to save time by using small pixelart sprites.

This (http://69.24.73.172/scirra/forum/viewtopic.php?f=8&t=1095) custom platform engine by Kayin is awesome , but when translated into C2, it suffers from the 1-pixel inaccuracy problem (http://www.scirra.com/forum/platform-object-sinks-into-solid-ground-bug_topic57004.html)

I managed to find an old trustworthy MMF2 method by Damian (http://damiansgames.com/post/6923285368/making-a-platformer-in-multimedia-fusion-2-or-games) and successfully ported it into C2.

I had to make the player sprite's bounding box one pixel smaller on each side (player sprite is 25x25px, player bounding box is 23x23px), but other than that it works great. I'm sure I could clean it up a little, especially those "direction" variables.

If anyone wants to take a look, the project is here

https://dl.dropbox.com/u/28087823/Construct%20Examples/pixel-perfect%20engine%20with%20loops%20-%20no%20slope/index.html

and .capx is here

https://dl.dropbox.com/u/28087823/Construct%20Examples/pixel-perfect%20engine%20with%20loops%20-%20no%20slope/test%20movement%20with%20actual%20loop.capx

So!

1st Question: is there any way to implement slopes in an engine like this? I mean small, 1-pixel steps, that the player sprite can climb, like Kayin's. Check the .capx , that small pixel-high bump on the floor is enough to completely stop the player sprite - which is good, it means pixel-perfect collisions are working. I tried using a slopeDetector sprite, but it kept thinking the walls were slopes. Perhaps I'm missing something.

2nd question: does anyone know why this engine won't play nice with dt? I tried introducing 60*dt instead of 1px steps and movement immediately becomes erratic. Jump strength becomes random as well. Does using pixel-perfect collision loops come at a price?


Glad to be here :)[/QUOTE]

Edit: I Foregot to welcome you to the forums

But anyways, I'm not sure about your second problem, but is this what your looking for in your first problem?

Link:
https://www.dropbox.com/s/0fwfwbe8f5jhoew/jumpy..capx

If so then I can explain how this works retrodude2013-04-07 01:09:05
B
18
S
4
G
3
Posts: 436
Reputation: 4,801

Post » Sun Apr 07, 2013 1:30 am

Hi retrodude, thanks for the welcome.

Yes, I'm trying to make "player" climb that big step just by going to the right.

Hmmm just had an idea.. Maybe I can make a high bump detector sprite and a low bump detector sprite... If the high *and* low bump detectors are overlapping an obstacle, then don't let "player" move. But if only the low bump detector sprite overlaps an obstacle, then assume it's a step and stand on it. So "player" can tell the difference between a wall and a step. I'll test this!

What was your idea?

Edit: oh I see! You made a smaller step, on frame 2 of the platform animation. OK, how does this help? Do a check of if FramePlaying=2 -> set player.Y -=1 ?

https://dl.dropbox.com/u/28087823/Construct%20Examples/pixel-perfect%20engine%20with%20loops%20-%20no%20slope/jumpy2.capx

It worked!!! This is so cool, thank you retrodude!!christina2013-04-07 02:06:03
B
19
S
7
G
2
Posts: 188
Reputation: 2,846

Post » Sun Apr 07, 2013 2:02 am

[QUOTE=christina] Hi retrodude, thanks for the welcome.

Yes, I'm trying to make "player" climb that big step just by going to the right.

Hmmm just had an idea.. Maybe I can make a high bump detector sprite and a low bump detector sprite... If the high *and* low bump detectors are overlapping an obstacle, then don't let "player" move. But if only the low bump detector sprite overlaps an obstacle, then assume it's a step and stand on it. So "player" can tell the difference between a wall and a step. I'll test this!

What was your idea?

Edit: oh I see! You made a smaller step, on frame 2 of the platform animation. OK, how does this help? Do a check of if FramePlaying=2 -> set player.X -=1 ?

https://dl.dropbox.com/u/28087823/Construct%20Examples/pixel-perfect%20engine%20with%20loops%20-%20no%20slope/jumpy2.capx

It worked!!! This is so cool, thank you retrodude!![/QUOTE]

Np but I think I must have read something wrong because I didn't realize that you wanted the player climb the step when pressing right. However it seems you pretty much solved your own problems so nice job
B
18
S
4
G
3
Posts: 436
Reputation: 4,801

Post » Sun Apr 07, 2013 2:05 am

don't sell yourself short, you pretty much solved this one! And it needs just one event!

if player is overlapping platform
and FramePlaying=/=0 -> set player.Y -=1

I think this is quite a robust engine already. Now if we could figure why dt is so unpredictable with this one...christina2013-04-07 02:07:35
B
19
S
7
G
2
Posts: 188
Reputation: 2,846

Post » Mon Apr 08, 2013 3:24 am

Hmm.
This is very weird.

Can anyone confirm this?
https://dl.dropbox.com/u/28087823/Construct%20Examples/pixel-perfect%20engine%20with%20loops%20-%20no%20slope/test%20movement%20with%20actual%20loop.capx

I've set the (25x25pixel) player's bounding box to be 23x23, providing 1 pixel of padding (otherwise player is stuck) The code works great, all collisions are pixel perfect.

If I change lines 12-15 to take dt into account,
(for example if I change 'Set Xdirection to 1' into 'Set Xdirection to 60*dt'), collisions become very erratic. There's a random pixel-wide gap between 'player' and platforms/walls. And if I reset the 'player' bounding box to 25x25, 'player' doesn't move at all, possibly because the condition for standing still is satisfied (i.e. don't make a move if moving will result in overlapping a platform)

Does anyone know the inner workings of this? I suspect it's the collision detection, but I may be missing something in code.

I can't stress this enough: the code runs *perfectly* when I leave dt out of it. @Ashley? Someone? No rush, I'm just obsessed with finding out if it can be helped. If not, does anyone know if it is a logical compromise to leave dt out of a game? Would it be game-breaking?

Thanks in advancechristina2013-04-08 15:46:26
B
19
S
7
G
2
Posts: 188
Reputation: 2,846

Post » Mon Apr 08, 2013 2:48 pm

I should also mention, the code only works correctly for odd pixel sizes. For example 25 works, 26 doesn't
B
19
S
7
G
2
Posts: 188
Reputation: 2,846

Post » Mon Apr 08, 2013 4:07 pm

My guess would be that the hotspot is different on an odd sized box.
There is no pixel perfect solution for an even sized poly because there is no one center point.
Again that's just a guess, I haven't checked out the capx.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Mon Apr 08, 2013 4:11 pm

@newt: You're probably right. Thanks! I don't mind basing an engine on odd size tiles at all, I was just puzzled
B
19
S
7
G
2
Posts: 188
Reputation: 2,846

Post » Mon Apr 08, 2013 4:23 pm

If you want to use dt, don't change line 12-15. Change the lines that are affecting speed, namely lines 10 and 11. Also, change the loop condition "xLoopIndex <> 0" to "abs(xLoopIndex) > 1" (same thing for the y loop).

I did those changes and everything runs fine !
B
46
S
17
G
18
Posts: 847
Reputation: 13,802

Next

Return to How do I....?

Who is online

Users browsing this forum: Kagubro and 15 guests