Just a few words on 2D Draw Commands...
2D Draw Commands like Dot, Line, Box, etc. are slow. I just discovered they are really super slow.
I was timing various parts of my game, like physics, Ai, etc. So I can knuckle down and make things faster, where needed. I saw that the 3rd Person Camera was taking 0ms (less than 1ms) to update positions. However 1st Person Camera would take like 6ms or more. I was like damn I do way more to the 3rd Person Camera but why's it like 100 times faster?
Dot Screen Width() / 2, Screen Height() / 2, RGB(255,255,255)
I cheaped out and used a single white pixel for a cross-hair. I was going to get around to making a proper cross-hair. That one pixel was taking 6ms to draw.
Perspective: That's like going from 60fps to 44fps or 30fps to 25fps.
One white dot. So don't use them. Not even once.
I could paste a cross-hair image a hundred times and still get better fps.
Example Code Below:
`Handle 1st Person Camera
Function Camera_FirstPerson(MyIndex)
frameSpeed# = FrameX#(0)
Dot Screen Width() / 2, Screen Height() / 2, RGB(255,255,255)
MyObject = aOBJ(0) + MyIndex
NewX# = LIMB Position X(MyObject, 7)
NewY# = LIMB Position Y(MyObject, 7) + 0.6
NewZ# = LIMB Position Z(MyObject, 7)
Camera_XYZA#(0,0) = WrapValue(Camera_XYZA#(0,0) + (Button_SecJoyX(0) * frameSpeed#))
Camera_XYZA#(1,0) = WrapValue(Camera_XYZA#(1,0) + (Button_SecJoyY(1) * frameSpeed#))
OffsetY# = Camera_XYZA#(0,0)
OffsetX# = Camera_XYZA#(1,0)
Position Camera 0, NewX#, NewY#, NewZ#
Rotate Camera 0, WrapValue(OffsetX#), WrapValue(OffsetY#), Object Angle Z(MyObject)
Rem Hide Head
Actor_ShowHead(MyIndex, 0)
EndFunction
Rem Handle 3rd Person Camera
FUNCTION Camera_3rdPerson(MyIndex)
MyObject = aOBJ(0) + MyIndex
frameSpeed# = FrameX#(0)
px# = object position x(MyObject)
py# = object position y(MyObject) + 20.0
pz# = object position z(MyObject)
pa# = wrapvalue(object angle y(MyObject))
scdis# = 25.0
rem Calc camera position and angle
ca#=wrapvalue(pa#)
cx#=newxvalue(px#,ca#,scdis#)
cz#=newzvalue(pz#,ca#,scdis#)
cy#=newyvalue(py#,0,scdis#)
dx# = cx# - Camera Position X(0)
dy# = cy# - Camera Position Y(0)
dz# = cz# - Camera Position Z(0)
mX# = (dx# / 6.0) * frameSpeed#
mY# = (dy# / 6.0) * frameSpeed#
mZ# = (dz# / 6.0) * frameSpeed#
If abs(mX#) > abs(dx#) then mX# = dx#
If abs(mY#) > abs(dy#) then mY# = dy#
If abs(mZ#) > abs(dz#) then mZ# = dz#
scX# = Camera Position X(0) + mX#
scY# = Camera Position Y(0) + mY#
scZ# = Camera Position Z(0) + mZ#
ObjHeight# = Actor_GetHeight(MyIndex)
CamTargetY# = Object Position Y(MyObject) + ObjHeight#
position camera 0,scX#,scY#,scZ#
Camera_EnforceCollison(Object Position x(MyObject), CamTargetY#, Object Position Z(MyObject), scX#, scY#, scZ#)
Camera_EnforceBounds()
point camera 0, object position x(MyObject), CamTargetY#, object position z(MyObject)
Actor_ShowHead(MyIndex, 1)
ENDFUNCTION
Thought I'd spice things up with a screenshot.