Hi,
Which tutorial are you trying to follow?
Is it the one I wrote?
Here:
https://forum.thegamecreators.com/thread/225869The code looks familiar, so I suspect you may be.
The reason the Draw commands don't work is because in the time since I wrote that, TGC have updated AppGameKit to allow the use of alpha channels in the draw commands. It's a great update but it breaks any code created before the update.
The fix is to place FF after 0x in the colour definition to state that you want full opacity. (the order is Alpha, Blue, Green, Red)
For example:
The hexadecimal for full green in the old system was
0x00FF00 (no blue, full green, no red)
Now it is:
0xFF00FF00 (full opacity, no blue, full green, no red)
Of course, you don't have to use hexadecimal at all. You could use the MakeColor() commands instead.
So, the first bit of code you were trying but couldn't get to work should now read:
+ Code SnippetSetDisplayAspect(1)
SetWindowSize(960, 540, 0)
SetScissor(0, 0, 0, 0)
//~ SetVirtualResolution(100, 100)
//~ SetScissor(0, 0, 0, 0)
//~ SetWindowSize(960, 540, 0)
do
x = GetScreenBoundsLeft()+1
DrawLine(x, 0, x, 100, 0xFF00FF00, 0xFF00FF00)
x = 0
DrawLine(x, 0, x, 100, 0xFF0000FF, 0xFF0000FF)
x = 50
DrawLine(x, 0, x, 100, 0xFFFF00FF, 0xFFFF00FF)
x = 100
DrawLine(x, 0, x, 100, 0xFF0000FF, 0xFF0000FF)
x = GetScreenBoundsRight()-1
DrawLine(x, 0, x, 100, 0xFF00FF00, 0xFF00FF00)
Sync()
loop
I have updated the original tutorial to reflect the changes TGC made when they updated AGK's draw commands.
As for the lines at the edge being slightly in from the edges, that's because they are being drawn at one 'unit' in. Since we are using the percentage system that is one percent of the screen width (which increases in size as the screen width increases).
You could insert it it by a floating point amount to get it closer to the edge but if you stick with drawing directly at the screen bounds they will run along the edge of the screen - just off it. That's because we're using integers in a floating point environment. Admittedly, not the best example to use in a tutorial!
If you really want to draw a line directly along the edge of the screen then you need to use floats in your calculations and you need to determine the size of the pixels used on your device, then offset the edge by the pixel width.
Like this:
+ Code SnippetSetDisplayAspect(1)
SetWindowSize(1000, 500, 0)
SetScissor(0, 0, 0, 0)
//~ SetVirtualResolution(100, 100)
//~ SetScissor(0, 0, 0, 0)
//~ SetWindowSize(960, 540, 0)
x as float
pixelWidth as float
pixelWidth = (GetScreenBoundsRight() - GetScreenBoundsLeft()) / GetWindowWidth() //Using GetWindowWidth() here because this example is for a windowed environment. Use GetDeviceWidth() if using on a mobile device
do
x = GetScreenBoundsLeft()
DrawLine(x+pixelWidth, 0, x+pixelWidth, 100, 0xFF00FF00, 0xFF00FF00)
x = 0
DrawLine(x, 0, x, 100, 0xFF0000FF, 0xFF0000FF)
x = 50
DrawLine(x, 0, x, 100, 0xFFFF00FF, 0xFFFF00FF)
x = 100
DrawLine(x, 0, x, 100, 0xFF0000FF, 0xFF0000FF)
x = GetScreenBoundsRight()
DrawLine(x-pixelWidth, 0, x-pixelWidth, 100, 0xFF00FF00, 0xFF00FF00)
Sync()
loop
Give me a shout if you have any other questions