[Tutorial] Simple Improvement for Drawing Pads (HD Draw: 2X the Segments)


#1

Reposting/reformatting as a stand-alone tutorial since it was in a topic that was deprecated


First, you have to understand that the normal code for a pen only draws every other frame . That’s because the When :iphone:Is Pressed rule has a null frame before it will execute again. Meaning, it waits 1 frame before it will start over. That in turn means the Draw a Trail only runs at 30 FPS instead of 60 FPS

Here’s an example project I made a while back to demonstrate this “bug”

Twice the standard number of curves can be accomplished with 1 object (no clones) and only a simple modification of the usual pen code like this:

First, we add 2 rules so we get a variable that is set to 1 when the device is pressed and 0 when it isn’t pressed. The wait block is because the conditional rule doesn’t have the null frame of the When Pressed rule so the wait block keeps the 2 rules synchronized,

image

Then we add the usual When :iphone:Is Tapped

image

Last, and here’s the key part, we modify the usual When :iphone:Is Pressed so it doesn’t leave the rule until the device isn’t pressed. We do this with recursion (notice the custom ability refers to itself). The Check If just checks the Pressed variable and loops within the HDdraw custom ability instead of looping the When :iphone:Is Pressed rule. This avoids the null frame and lets the Draw a Trail run at 60 FPS

image

Here’s the HDdraw code in an example project:

Happy coding :grinning:


#2

I should add that doing this

image

instead of the When :iphone:Is Pressed with recursion should logically work and be even simpler, but it doesn’t. I believe having Draw a Trail as the last block in a conditional rule also creates a null frame.


#3

woah this is awesome, thanks!


#4

:clap: :clap: Bravo m8

Very helpful


#5

Nice!


#6

What is HD draw?
How does it differ?


#7

It draws a line segment twice as often as the standard method of drawing like a pen.