Posted: 22nd Sep 2011 17:35
Hello all

I am new to the forum. I have try out the APP Game Kit and I was wondering does it have 2D Drawing commands?

Posted: 22nd Sep 2011 18:27
It doesn't have any drawing commands right now, but I think TGC may add some in the future. You can add your voice to calling for this feature at the bug/request board here.
Posted: 23rd Sep 2011 4:13
Thanks rich...

It is possible to make own 2D Drawing Commands?
Posted: 23rd Sep 2011 6:33
Only by using sprites to fake it. You could have an entire screen of tiny sprites gridded to fit and then show hide the ones you mouse over for instance. Or scale a sprite along an axis to draw a line etc. Theres plenty of room for improvising.
Posted: 23rd Sep 2011 10:55
You could have an entire screen of tiny sprites gridded to fit and then show hide the ones you mouse over for instance.

Nice simple idea but surely quite slow? If not that's a great solution.

I'm using stretched sprites for boxes and lines from a white 1x1 pixel image. That way if you use "setSpriteColor" you can edit everything including the alpha of the sprite. I store all my sprites in an array and delete them when I don't need them any more... it's pretty neat really but some basic commands would be great.
Posted: 23rd Sep 2011 13:59
Hi Noob, check out this thread:

http://forum.thegamecreators.com/?m=forum_view&t=189234&b=41

Posted: 23rd Sep 2011 14:13
That's pretty darned amazing Impetus73! Nice...

Shows what you can do without line commands for sure, my only worry is that you may have shown TGC we don't really need the 2D commands if we think about it...
Posted: 23rd Sep 2011 15:55
Haha baxslash, we DO need them, this manual way of doing it is a hassle, and Lee had some ideas for how to make a drawing instruction set, by using predefined sprites at high res, he were babbeling about a "module" to AppGameKit that would deal with it.
Posted: 23rd Sep 2011 22:41
@baxslash, I haven't tried it but I did do a stress test with agk in the first few days. I got over 26,000 sprites on screen before the FPS dropped below 60. Perhaps I should post it to see what other get So I think it is fairly capable in that area. You wouldn't be able to go high res, but a semi low res screen should work. But yeah, not the most efficient way, just a quick example really to give an idea of other ways to fake drawing commands.
Posted: 24th Sep 2011 2:00
Thanks Impetus73 and I will check that
Posted: 24th Sep 2011 12:14
26000 sprites? I don't think so, I have found that any sprites above 16384 will not physically show, even if you can define them, and run commands on them. only 16384 individual sprites will show on screen at the same time, the rest is invisible. try make alot of sprites at the size of 1x1 pixel, put them on the screen, and see that it stops after 16384.
Posted: 24th Sep 2011 20:21
I doing Twister Demo but cant get two Twister on the screen...

does anyone know why?

+ Code Snippet
// Initialize display
SetVirtualResolution    (800,600)
SetClearColor           (0,0,0)
SetOrientationAllowed   (0,0,1,1)
SetResolutionMode       (2)
SetSyncRate             (60,1)
SetBorderColor          (200,200,200)

Global a#
Global x1#
Global x2#
Global x3#
Global x4#
Global ang#=0
Global amp=7

global Pos1=175
global Pos2=375

// Initialize "bitmap"
global dim pixel[359,299]
for l1=0 to 359
    for l2=0 to 299
        pixel[l1,l2]=createsprite(void)
        setspritesize(pixel[l1,l2],1,-1)
        setspriteposition(pixel[l1,l2],l1,l2)
        setspritecolor(pixel[l1,l2],random(0,150),random(0,150),random(0,150),255)
    next l2
next l1
// Display help
print("Press Q to exit program")
print("Press C to clear screen")
sync()

sleep(1000)


// Main loop (Press Q to exit, C to clear screed)
do
    For a=1 To 600 Step 2
			x1=((Sin((a/amp)+ang))*100)+300
			x2=((Sin((a/amp)+ang+90))*100)+300
			x3=((Sin((a/amp)+ang+90*2))*100)+300
			x4=((Sin((a/amp)+ang+90*3))*100)+300


			If x1<x2
			   drawline (x1-Pos1,a,x2-Pos1,a,255,0,255)

  			   drawline (x1+Pos2,a,x2+Pos2,a,255,0,255)
			EndIf

			If x2<x3
			   drawline (x2-Pos1,a,x3-Pos1,a,0,0,255)

			   drawline (x2+Pos2,a,x3+Pos2,a,0,0,255)
   			EndIf


			If x3<x4
			   drawline (x3-Pos1,a,x4-Pos1,a,0,255,0)

			   drawline(x3+Pos2,a,x4+Pos2,a,0,255,0)
			EndIf


			If x4<x1
			   drawline(x4-Pos1,a,x1-Pos1,a,255,255,0)

			   drawline(x4+pos2,a,x1+pos2,a,255,255,0)
			EndIf
    Next

	ang=ang+2
    If ang=360 Then ang=0


    // Check for input
    if getrawkeypressed(67) then cls(0,0,0)
    if getrawkeypressed(81) then exit
    sync()
loop
// Safe exit in case of loop exit
end

function cls(r,g,b)
    for l1=0 to 359
        for l2=0 to 299
            plot(l1,l2,r,g,b)
        next l2
    next l1
endfunction

function plot(x,y,r,g,b)
    if x<0 or x>359 or y<0 or y>299 then return
    setspritecolor(pixel[x,y],r,g,b,255)
endfunction

function drawline(x1,y1,x2,y2,r,g,b)
    dx=abs(x2-x1)
    dy=abs(y2-y1)
    if x1<x2 then sx=1 else sx=-1
    if y1<y2 then sy=1 else sy=-1
    err=dx-dy
    do
        plot(x1,y1,r,g,b)
        if x1=x2 and y1=y2 then exit
        e2=2*err
        if e2>-dy
            err=err-dy
            x1=x1+sx
        endif
        if e2<dx
            err=err+dx
            y1=y1+sy
        endif
    loop
endfunction


It work so well with other programming language and I want to make work on AppGameKit
Posted: 25th Sep 2011 6:54
I have tested that out impetus73, I hadn't noticed it on my stress test as I just left it to run until it fell below speed. It still however continued to make sprites until it had slowed down below 60fps, even if it wasn't displaying them. But yes indeed you are correct, 1 pixel sprites do seem to stop at just over 16000.
Posted: 25th Sep 2011 10:08
Noob, I have not tested it yet, but I think your problem is that you are not using floats! add an # after every variable, and I think it would work better.

EDIT: ups! Your trying to add 107341 sprites on the screen at the same time, the max is 16384.

You shold rather try your demo using my other line drawing function, the one that uses stretched sprites instead of a pixel bitmap emulation like this one. Max practical resolution with this one is 160*100 pixels. The sprite stretch has no practical limitation on resolution as I know of.
Posted: 25th Sep 2011 10:27
ok, here is the converted version, it has some error you will have to figure out, since I'm not sure how the ressults were gonna be.

+ Code Snippet
// Initialize display
SetVirtualResolution    (800,600)
SetClearColor           (0,0,0)
SetOrientationAllowed   (0,0,1,1)
SetResolutionMode       (2)
SetSyncRate             (60,1)
SetBorderColor          (200,200,200)

Global a#
Global x1#
Global x2#
Global x3#
Global x4#
Global ang#=0
Global amp=7

global Pos1=175
global Pos2=375

// Display help
print("Press Q to exit program")
sync()
sleep(1000)

// Main loop (Press Q to exit)
do
    For a=1 To 600 Step 2
			x1=((Sin((a/amp)+ang))*100)+300
			x2=((Sin((a/amp)+ang+90))*100)+300
			x3=((Sin((a/amp)+ang+90*2))*100)+300
			x4=((Sin((a/amp)+ang+90*3))*100)+300

			If x1<x2
			   drawline (a,x1-Pos1,a,x2-Pos1,a,255,0,255)
  			   drawline (a+1000,x1+Pos2,a,x2+Pos2,a,255,0,255)
			EndIf

			If x2<x3
			   drawline (a,x2-Pos1,a,x3-Pos1,a,0,0,255)
			   drawline (a+1000,x2+Pos2,a,x3+Pos2,a,0,0,255)
   			EndIf

			If x3<x4
			   drawline (a,x3-Pos1,a,x4-Pos1,a,0,255,0)
			   drawline (a+1000,x3+Pos2,a,x4+Pos2,a,0,255,0)
			EndIf

			If x4<x1
			   drawline (a,x4-Pos1,a,x1-Pos1,a,255,255,0)
			   drawline (a+1000,x4+pos2,a,x1+pos2,a,255,255,0)
			EndIf
    Next

	ang=ang+2
    If ang>360 Then ang=ang-360

    // Check for input
    if getrawkeypressed(81) then exit
    sync()
loop
// Safe exit in case of loop exit
end

function drawline(id,x1,y1,x2,y2,r,g,b)
    // Create the line sprite
    if getspriteexists(id)=0 then createsprite(id,0)
    a=atan((x2-x1)/(y2-y1))
    if x1=<x2
        sx=x1
    else
        sx=x2
    endif
    if y1=<y2
        sy=y1
    else
        sy=y2
    endif
    w=sqrt((x2-x1)^2+(y2-y1)^2)
    setspritesize(id,w,2)
    setspriteangle(id,a+10)
    setspriteoffset(id,0,0)
    setspritepositionbyoffset(id,sx,sy)
    setspritecolor(id,r,g,b,255)
endfunction
Posted: 25th Sep 2011 13:18
I simplified and modified the code abit, was it something like this you wanted to do?



+ Code Snippet
// Initialize display
SetVirtualResolution    (800,600)
SetClearColor           (0,0,0)
SetOrientationAllowed   (0,0,1,1)
SetResolutionMode       (2)
SetSyncRate             (60,1)
SetBorderColor          (200,200,200)

ang#=0.0
amp#=7.0
Pos1=100
Pos2=700
r=255
g=0
b=255
// Display help
print("Press Q to exit program")
sync()
sleep(1000)

// Main loop (Press Q to exit)
do
    t=t+1
    if t=100
        t=0
        r=random(100,255)
        g=random(100,255)
        b=random(100,255)
    endif
    For a=1 To 640 Step 1
        x1#=((Sin((a/amp#)+ang#))*100)
	x2#=((Sin((a/amp#)+ang#+90))*100)
	x3#=((Sin((a/amp#)+ang#+180))*100)
	x4#=((Sin((a/amp#)+ang#+270))*100)

	drawline (a,x1#+Pos1,a-40,x2#+Pos1,a-40,r,g,b)
   	drawline (a+1000,x3#+Pos2,a-40,x4#+Pos2,a-40,r,g,b)
    Next

    ang#=ang#+2
    If ang#>360 Then ang#=ang#-360

    // Check for input
    if getrawkeypressed(81) then exit
    sync()
loop
// Safe exit in case of loop exit
end

function drawline(id,x1,y1,x2,y2,r,g,b)
    // Create the line sprite
    if getspriteexists(id)=0 then createsprite(id,0)
    a=atan((x2-x1)/(y2-y1))
    if x1=<x2
        sx=x1
    else
        sx=x2
    endif
    if y1=<y2
        sy=y1
    else
        sy=y2
    endif
    w=sqrt((x2-x1)^2+(y2-y1)^2)
    setspritesize(id,w,2)
    setspriteangle(id,a+10)
    setspriteoffset(id,0,0)
    setspritepositionbyoffset(id,sx,sy)
    setspritecolor(id,r,g,b,255)
endfunction