Forum > Android

Slow down drawing

(1/4) > >>

tango13:
Hi all,
I'm using a jDrawingView to draw some simple graphics and I would like to slow down the drawing a bit.
The drawing code is implemented in the onDraw event and things work as expected.
However, if I try to slow the drawing process by inserting some sleep() the effect is not what I'm looking for, the process actually takes more time but I don't see the drawing progressively made, it's all drawn all at once when the function exits.
Is there a way to achieve what I'm trying to do?

Thanks a lot!

lainz:
Use a kind of timer, and draw each part of the drawing at specific time?

loaded:
In my experience you should use Surfaceview for such drawing operations.

The work I did in this way; https://youtu.be/gBS0AMrJ50s

The relevant example will give you an idea.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---....\lazandroidmodulewizard-master\demos\GUI\AppSurfaceViewDemo1

Seenkao:
Для понимания происходящего.
Всё что вы рисуете на экране, будет выводится в любом случае сразу.
Для того чтоб добиться эффекта медленной прорисовки, вам надо рисовать по частям, в каждый момент времени добавляя дополнительные примитивы.
Допустим вы хотите вывести квадрат, круг и треугольник, чтоб они появлялись друг за другом. Вы не можете использовать Sleep для этого в одном кадре.
Вам нужно в первом кадре прорисовать квадрат. Во втором кадре прорисовать квадрат и круг. И в третьем кадре прорисовать квадрат, круг и треугольник. Между кадрами соответственно должны быть достаточные промежутки времени, чтоб это было заметно, тут можете использовать Sleep.

google translate:
To understand what is happening.
Everything that you draw on the screen will be displayed in any case immediately.
In order to achieve the effect of slow drawing, you need to draw in parts, adding additional primitives at each point in time.
Let's say you want to draw a square, a circle, and a triangle so that they appear one after the other. You can't use Sleep for this in one frame.
You need to draw a square in the first frame. In the second frame, draw a square and a circle. And in the third frame draw a square, a circle and a triangle. Between frames, respectively, there should be sufficient time intervals for this to be noticeable, here you can use Sleep.

loaded:
Things are different on Android. Normally, you cannot make any display on the screen before the drawing method is finished.


--- Quote from: Seenkao on April 21, 2022, 08:10:11 am ---To understand what is happening.
Everything that you draw on the screen will be displayed in any case immediately.
In order to achieve the effect of slow drawing, you need to draw in parts, adding additional primitives at each point in time.
Let's say you want to draw a square, a circle, and a triangle so that they appear one after the other. You can't use Sleep for this in one frame.
You need to draw a square in the first frame. In the second frame, draw a square and a circle. And in the third frame draw a square, a circle and a triangle. Between frames, respectively, there should be sufficient time intervals for this to be noticeable, here you can use Sleep.

--- End quote ---
With your method; If you want to draw a drawing containing ~100,000 objects, drawing becomes a nuisance.

But instead;
If you use Surfacaview, which is designed for such work, and a thread owned by surfaceview itself.
Things become very enjoyable.

Navigation

[0] Message Index

[#] Next page

Go to full version