Have ground follow character to reduce lag


#1

@Rawrbear
This is another technique I haven't mentioned yet.
When making a 2D platformer, you can have just 1 block/piece of ground always at a characters X position.
You can code the ground to change Y positions when between certain X positions of ground like in this demo I linked.
You could pretty much use trails to draw the ground or walls for an entire 2d level.
And since the code is only checking if a character bumps 1 shape, the code runs quickly, instead of having the character bumping everything, and filling the screen with sprites for the ground/walls etc
https://c.gethopscotch.com/p/y97l8ctwj


#2

Well, you could use this method. But what if your character needed to jump over some sort of pit? You'd have to move the block out of the way somehow, right? Would be pretty hard to code, if you ask me, unless you use spikes or something.


#3

Yes that's what the changing of the y position can be used when between certain X positions.
Like the pits between 200-300
When the character is between 200-300 , the platform can be at 300 at the edge of the pit to land on when the pairs jumped over

Sorry, I mean you can have the blocks Y position anywhere so it's not beneath the character when the characters X is between 200-300


#4

Excuse my non-thinking, it's 10:58 back in America CTZ and I'm surprisingly tired.

That's true. What advantages are in this method compared t-

Oh, you don't need to place ground! Neat!


#5

Might use this method in a platformer sometime in the nearby future, never thought of that!


#6

Mainly lag. The less sprites on screen when using bumps/touches anything, the quicker the game runs.
I coded a simple run/jump Mario type level and used bumps anything for when touching the ground.
The game lagged badly .
If I used this technique I wouldn't have that problem.


#7

I do not think that you need a new topic for this.


#8

Any new coding technique should have a topic so others can learn.
Like, for example ,topics about using cos/sine to draw circles.
As @Rawrbear mentioned, he and most likely no one else has thought about or used the technique I showed.


#9

No, I'm not trolling you. And I do not think people will find the name of this topic is something that they might be interested in, maybe you should considering to make a topic just for coding tips that you might not know. Because it seems like your helping @Rawrbear. That should be posted in Talk To A Hopscotcher (Take 2).


#10

I probably should have replied to @Rawrbear on his collab topic.
Funny, ppl who (appear) to like me hardly respond or invite me to collabs or discussions.
And ppl like you will discuss matters with me.
Okay, I'm switching to "Reverse" mode.


#11

Hmm Let's see. {goes to look through forum} 287 topics not related to coding. 1 topic related to coding. I think this topic is ok!

Posting topics about relevant coding techniques that all Hops can use should be encouraged. Nice post & good idea @Stradyvarious. A buried reply in another topic would have made the idea much less visible & harder to find again. Thank you for sharing.

Maybe just edit the OP & move this bit to the end so it's more obvious that you're communicating an idea to all Hops


#12

Segueing back to being on topic, while I really like this concept I could see it potentially being difficult to implement in some scenarios. Just to hopefully increase someone's "tool kit", I'll mention that middle ground (pun intended) does exist between using all individual ground elements & a single ground element that follows the character.

For example, 3 platforms could be coded as a long text string
"-------- --------
-------"
This carries the lag penalty of a single object & may be easier in some scenarios. The text may have minimal visibility and/or may be co-located with a drawn platform. But this is not as elegant as @Stradyvarious's moving ground solution.

This is an example (though not a 2D platformer) where I've used long text strings to avoid numerous individual objects. There are not 95 individual collisions (bombs) to detect but only 7 on this level
https://c.gethopscotch.com/p/y93sqakhk


#13

It's completely fine to make topics about certain coding styles or strategies. I see it all the time on legit coding forums.

@TheRealBlah, please, could you be a bit more polite about telling people where to have topics and where to not? :slight_smile:


#14

I Really like your project.
The artwork for the blue bob character looks very professional .
If you weren't an engineer you could have been a commercial artist.

I haven't really used strings except when using Tynker to keep track of what text the player has input for names,answers etc
My idea is to have 1 horizontal shape for the floor and 1 vertical shape for a wall.
Then if there's a wall or obstacle to run into, the vertical shape set it's position at the end of the ground and the character bumps back off the vertical shape when bumping into it.

Using "set position" to move and "checking" X/Y position of a Sprite would be even less laggy than using bumps.
It depends how skilled the coder is.


#15
Off topic comments

Thanks. You're too kind. Just the "Blue Bob character" alone probably took me 20 hrs to code, but I'm not really much of an artist. Just very detail oriented. I found an image I liked and painstakingly created a similar coded version.

BTW, you recall the topic about creating an array using a single variable? I was able to put that to use in the full Blue Ball project. I needed to record the binary state of 10 events on different levels of the game. I could have created hidden clones each with a different value, but didn't want to add any more objects (lag) than absolutely necessary. So I encoded the data as a summation of (binary value)*2^(level) and decoded it at the end to display the data when additional clones wouldn't matter. As Hannibal would say "I love it when a plan comes together" :smile:

I really like this idea & will definitely keep this in mind for potential use in future projects :smiley:


#16

You could use this technique if you have a small level or something, because what will happen if the are 2 platforms at the same X coordinate? I guess you could have 2 different real platforms and split the canvas in half and one gets all the trails >387 and the other one gets the ones <387