|
Post by Rosy on Nov 8, 2020 4:56:45 GMT -6
Could use a more detailed explanation of Canvases, they don't seem to work as described. It is not stated that moving, changing the height and width causes the window contents to shift, stretch and constrict. I don't know what the difference between canvas and viewport is. SetCanvasViewport seems to overwrite the entire canvas, SetCanvasOffset does nothing for positive values and strange effects for negative values.
|
|
|
Post by tbird on Nov 8, 2020 8:22:14 GMT -6
Have you looked at the examples that come with RC? I am not sure if what you need is there I am away from my pc.
|
|
|
Post by Rosy on Nov 8, 2020 11:22:12 GMT -6
A few. There, the viewport coincided with the canvas. I wanted to do scrolling by shifting the canvases.
|
|
|
Post by tbird on Nov 8, 2020 20:24:36 GMT -6
Sorry I missed the reply, does the beast demo use the canvases? I can't remember.
Sorry I am not much help, other then setting the main canvas I don't use them much in my game demos or my engine.
|
|
|
Post by johnno56 on Nov 9, 2020 5:10:15 GMT -6
Ah. Beast. Uses two canvases... I don't think it uses viewports...
J
|
|
|
Post by n00b on Nov 9, 2020 13:15:50 GMT -6
Here is a quick canvas example. Use the arrow keys to move around.
WindowOpen(0, "Canvas Demo", WINDOWPOS_CENTERED, WINDOWPOS_CENTERED, 640, 480, 0)
canvas_x = 100 canvas_y = 100
canvas_w = 640 canvas_h = 480
viewport_x = 0 viewport_y = 0
viewport_w = 100 viewport_h = 100
'This Canvas will fill the entire window CanvasOpen(0, 640, 480, 0, 0, 640, 480, 0) Canvas(0) SetColor(RGB(0,255,0))
'This line will draw a box around the viewport of the canvas created below Rect(canvas_x-1, canvas_y-1, viewport_w+2, viewport_h+2)
'This canvas will be the same size as canvas #0 but its viewport will only be 100 x 100 CanvasOpen(1, canvas_w, canvas_h, canvas_x, canvas_y, viewport_w, viewport_h, 0) Canvas(1) ClearCanvas
SetColor(RGB(0,0,255)) CircleFill(100, 100, 50)
'Set canvas #0 in the background 'Note: Canvases will be drawn in order from highest being in the background to lowest being in the foreground 'Canvas order can be from 0 (foreground) to 7 (background) SetCanvasZ(0, 7)
'Set canvas #1 as the next canvas to be drawn after canvas # 0 SetCanvasZ(1, 6)
While Not Key(K_ESCAPE) If Key(K_RIGHT) And (viewport_x+1) < canvas_w Then viewport_x = viewport_x + 1 ElseIf Key(K_LEFT) And (viewport_x-1) >= 0 Then viewport_x = viewport_x - 1 End If If Key(K_DOWN) And (viewport_y+1) < canvas_h Then viewport_y = viewport_y + 1 ElseIf Key(K_UP) And (viewport_y-1) >= 0 Then viewport_y = viewport_y - 1 End If 'Move the offset of the canvas view SetCanvasOffset(1, viewport_x, viewport_y) Update Wend
|
|
|
Post by rosy on Nov 11, 2020 10:07:43 GMT -6
I still don't know if I understand it correctly.
I made this example:
xmax = 990
ymax = 750
title$ = "Window and Multiple Canvases?"
WindowOpen(1,title$,0,0,xmax,ymax,0)
CanvasOpen(1,570,420,20,20,370,220,0)
s1=570
w1=420
x1=20
y1=20
vx=370
vy=220
loadFont(1,"../zx81.ttf",64)
'Font(arial)
Canvas(1)
setColor(rgb(30,30,30))
RectFill(0,0,570,420)
setColor(rgb(160,160,160))
DrawText("Canvas(1)",50,50)
'prints("Canvas(1)")
update()
Canvas(1)
do
if key(k_left) then
s1=s1-1
'vx=vx-1
x1=x1-1
end if
if key(K_right) then
s1=s1+1
'vx=vx+1
x1=x1+1
end if
if key(k_up) then
w1=w1-1
'vy=vy-1
y1=y1-1
end if
if key(K_down) then
w1=w1+1
'vy=vy+1
y1=y1+1
end if
SetCanvasViewport ( 1, x1+100, y1+50, vx, vy )
SetCanvasOffset ( 1, x1, y1 )
DrawText("Canvas1",5,5)
update
loop until key(K_ESCape)
I tried with or without SetCanvasViewport and SetCanvasOffset. It acts weird ...
The manual is very short, the analysis of examples takes 10x more time, it discourages the use of the language ...
|
|
|
Post by n00b on Nov 11, 2020 15:12:20 GMT -6
rosy I will try to explain how canvases work. * A canvas is a drawing surface. * The canvas can be as large as you want but only the viewport of the canvas will be visible in the window. * The Location of the viewport ( viewport_x and viewport_y ) is where the viewport will be drawn in the window. Refer to CanvasOpen() in the manual for how to set this up. Look at this picture. Even though the canvas above is a 600 x 400 drawing surface, the viewport is only a 200 x 200 area which is offset at (0, 0) which is the top left of the canvas. Refer to SetCanvasOffset() in the manual for how to change the offset of the canvas. Here is what that would look like when its drawn. Here we are taking the same canvas and just changing the offset of where the viewport is looking at on the canvas. Notice the viewport is still in the same location in the window and the area of the canvas inside the viewport is what is changing. And here is what the change in offset will draw on this image.
|
|
|
Post by rosy on Nov 12, 2020 4:05:31 GMT -6
But it should be in the manual explaining which manual does what exactly. In my example, the change in offset did not change. It is similar in the example shown in the video: www.youtube.com/watch?v=rjTk-2OH0XcA SetCanvasViewport compresses the contents of the window, and there is nothing in the manual about that.
|
|
|
Post by n00b on Nov 12, 2020 9:16:04 GMT -6
A SetCanvasViewport compresses the contents of the window, and there is nothing in the manual about that. The manual is constantly evolving. johnno56 could tell you what the manual was like 5 years ago. It was a PDF file with a list of functions and almost no explanation for what they did. I make improvements to the manual with every release but it does take time. SetCanvasViewport is not your problem. Your problem is SetCanvasOffset(). SetCanvasOffset() is setting where the viewport will look at your canvas from. If this is less than zero then your image will start to stretch because you are trying to draw a part of the image that doesn't exist. It will cause errors trying to draw if you set the offset where its trying to draw past the end of the image. Try adding these if statements before you call SetCanvasViewport() or SetCanvasOffset() in your example: If (x1 + vx) >= 570 Then x1 = 570 - vx ElseIf x1 < 0 Then x1 = 0 End If If (y1 + vy) >= 420 Then y1 = 420 - vy ElseIf y1 < 0 Then y1 = 0 End If This code just makes sure x1 and y1 are never less than zero and they are never greater than the size of the canvas. Basically if your viewport width is 370 and your canvas width is 570 then your x offset should never be greater than 200 -> ( 570 - 370 ).
|
|
|
Post by rosy on Nov 12, 2020 11:25:10 GMT -6
and what SetCanvasViewport does?
|
|
|
Post by n00b on Nov 12, 2020 12:21:11 GMT -6
SetCanvasViewport changes the position of the viewport in the window and the size of the viewport.
Here is some examples:
This code will set the viewport at (100, 20) in the window and sets the viewport or the area of the canvas that is drawn to a width of 200 pixels and a height of 200 pixels. This means that a 200 x 200 area of the canvas will be drawn on the window at the (x,y) position (100, 20).
SetCanvasViewport(0, 100, 20, 200, 200)
The canvas should always have a size that is greater than or equal to the size of the viewport. The part of the canvas that the viewport starts drawing from is the offset. If the offset is (0, 0) then it will start drawing from the top-left pixel of the canvas and draw 200 pixels from there. Moving the offset scrolls to a new position on the canvas and draws 200 pixels from where the offset is.
|
|