[Solved] pixel-perfect platform engine using loops

Get help using Construct 2

Post » Mon Apr 08, 2013 5:05 pm

What's wrong with the built-in platform behavior? It's been improved a lot over the past few months, and now even works to sub-pixel accuracy (down to 1/16th of a pixel) with full support for slopes, jump-thrus etc. If there's a particular problem with the built-in Platform behavior we definitely want to fix it, because re-doing all that work in events is extremely hard and pointless if we can make the built-in behavior good enough. The Platform behavior is over 1000 lines of javascript and has been very tough to get right, so I expect you'd really struggle if you want to get the same robustness and accuracy as the built-in behavior using events.Ashley2013-04-08 17:06:32
Scirra Founder
B
357
S
214
G
72
Posts: 22,946
Reputation: 178,228

Post » Mon Apr 08, 2013 6:05 pm

@Magistross thanks for taking the time. Could you share your .capx? Because I tried the same yesterday, and it ruined xSpeed for some reason (-3 going left, +2 going right)and also introduced a 1-pixel gap again. You can see it if you drive 'player' in a corner and keep pushing: it sinks one (or half) a pixel in.



@Ashley

Thanks for taking the time. So, this is the built-in (and awesome, don't get me wrong) platform movement:

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

When the 'player' bounding box is 25x25px, 'player' doesn't even move.
When the 'player' bounding box is 23x23, 'player' moves ok, but again, the 1-pixel gap makes its appearance.


And this is my implementation which works without a glitch always, except when introducing dt (although Magistross may be on to something)

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

It does all I want it to do, and takes advantage of C2's inbuilt bounding box and overlap functions, so your code is definitely not going to waste.

I think this (http://www.scirra.com/FORUM/the-big-timedelta-headache_topic35671_page1.html ) discussion is really really pertinent to the problem, but I can't really parse the ConstructClassic-specific ideas, since I know things are different with C2. I do hope I'm not making a nuisance of myself.christina2013-04-08 18:06:29
B
19
S
6
G
2
Posts: 188
Reputation: 2,744

Post » Mon Apr 08, 2013 6:18 pm

@christina

I don't know if this is what you're looking for, but I have been dealing with the platform behavior and metroid/mario/megaman/cobra genre of games to teach some kids, also, I did my own project with all the learned knowledge.

The equilibrium have been developed to meet a gigantic portion of collision checks and all did with detectors.

On the first step, I give up of using the platform behavior, but since the behavior was updated even more, I changed the code to take advantage of it.

So, I can say with certain baggage, the platform behavior is very precisely now, but, you'll need to think on new ways of checking the environmental conditions.

The only thing I'm working around actually is the vertical speed, because I didn't figured out how to stop the player on a wall after a jump, all my tries finished with player slow sliding the wall. So, I decided to use an invisible sprite with no behavior and set it to meet the player X,Y, and when hit a wall, simple change who is meeting who, and the player stop on the wall =)

Take a look on the sample (I don't know why, but dropbox is doing some weird problems and you'll need to use another navigator to play the game...)

Press on my signature to see the system.
Use the arrow to move, or the mouse.
A is the jump, if I remember right.
Take the box with the mouse.

EDITED:
I forgot about another problem to deal, because the player is not on the ground, in other words, he is on the air or wall, the falling speed will keep updating, and was necessary to set the speed to 0 while on a wall, or climbing a ceil.

I don't know if it make sense, but you'll need to deal with the same thing on your study.

[tube]http://www.youtube.com/watch?v=pJFQftlOdH0[/tube]TELLES08082013-04-08 19:17:42
ImageImageImageImageImageImage
B
92
S
19
G
12
Posts: 1,187
Reputation: 18,261

Post » Mon Apr 08, 2013 6:59 pm

Here's the capx with dt based movement.
B
45
S
16
G
18
Posts: 845
Reputation: 13,668

Post » Mon Apr 08, 2013 7:14 pm

@christina - can you share examples without third party plugins (SpriteFont)? I don't have third party plugins in my dev copy of C2. Also, your screenshots show perfectly aligned sprites don't they? I don't see any pixel alignment issue in them.Ashley2013-04-08 19:15:00
Scirra Founder
B
357
S
214
G
72
Posts: 22,946
Reputation: 178,228

Post » Mon Apr 08, 2013 7:23 pm

[QUOTE=christina] @Magistross thanks for taking the time. Could you share your .capx? Because I tried the same yesterday, and it ruined xSpeed for some reason (-3 going left, +2 going right)and also introduced a 1-pixel gap again. You can see it if you drive 'player' in a corner and keep pushing: it sinks one (or half) a pixel in.



@Ashley

Thanks for taking the time. So, this is the built-in (and awesome, don't get me wrong) platform movement:

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

When the 'player' bounding box is 25x25px, 'player' doesn't even move.
When the 'player' bounding box is 23x23, 'player' moves ok, but again, the 1-pixel gap makes its appearance.


And this is my implementation which works without a glitch always, except when introducing dt (although Magistross may be on to something)

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

It does all I want it to do, and takes advantage of C2's inbuilt bounding box and overlap functions, so your code is definitely not going to waste.

I think this (http://www.scirra.com/FORUM/the-big-timedelta-headache_topic35671_page1.html ) discussion is really really pertinent to the problem, but I can't really parse the ConstructClassic-specific ideas, since I know things are different with C2. I do hope I'm not making a nuisance of myself.[/QUOTE]

@Christina

The collision box of your sprites are the exactly same on all the frames?

The sink symptom is looking like a issue with different collision polygons I had a time ago.

If yes, I concern you to use the animation sprite as animations only, and pin them to an invisible square sprite object, with the collision polygons set to the size you want, so, you can make all your code to work for the invisible sprite and set everything else, like animations, to be pin on that.TELLES08082013-04-08 19:25:01
ImageImageImageImageImageImage
B
92
S
19
G
12
Posts: 1,187
Reputation: 18,261

Post » Mon Apr 08, 2013 10:13 pm

@Magistross that was *brilliant*. Thank you! What a stroke of genius, adding abs() right there! I think we can upload this engine as a tutorial/example. I'll fully annotate it and give credit to you, retrodude, newt and Damian. What do you think?


.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

@Ashley apologies! Please check the new .capx directly above. Pixel perfect in every single aspect, and thanks to Magistross, framerate independent. Supports slopes (by using curved bounding boxes) and ledges you can grab on to.

Screenshot comparison. This is the built-in platform behaviour (notice the sprite having sunk 1 pixel to the right and one pixel toward the bottom)


and this is the pixel-perfect implementation without any sinking pixels



@TELLES0808 great pixelart by the way :) No, the sinking problem is just the 25x25px 'player' sprite using the platform behaviour. It's not animated, and it's only a placeholder that will be invisible. The animated sprite will, as you say, be pinned on this 'player' sprite.

Thank you all!christina2013-04-09 00:04:58
B
19
S
6
G
2
Posts: 188
Reputation: 2,744

Post » Tue Apr 09, 2013 3:44 pm

Haha ! It was nothing really ! I could have just used abs() in the loops condition but I didn't like the idea of having index variables possibly taking negative values...

Nice work with the engine, looking forward to seeing it in action !
B
45
S
16
G
18
Posts: 845
Reputation: 13,668

Post » Tue Apr 09, 2013 4:23 pm

@christina - I don't see a link to a .capx using the platform behavior with no third party plugins. The link in your last post uses a custom movement.

Pixel "sinking" in the built-in platform movement should be considered a bug. I really want to discourage "custom" engines, because a much better solution is to improve the built-in movement to do what you want, instead of making you reinvent a whole complicated engine.
Scirra Founder
B
357
S
214
G
72
Posts: 22,946
Reputation: 178,228

Post » Tue Apr 09, 2013 4:26 pm

For the record, I tried your custom platform movement example, deleted all the events, added the platform behavior, and corrected the collision mask so it's bounding box (it appears to be set to one pixel sunk in). It was pixel perfect, I couldn't find any sinking issues that you describe at all.
Scirra Founder
B
357
S
214
G
72
Posts: 22,946
Reputation: 178,228

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go, anty21ro, Magistross and 19 guests