GameDev Xmas Challenge – Hour 9: Drawing now works!

Only one hour this time around so still a bit behind but it’ll catch up eventually. This hour however has been super-productive as drawing directly to the texture with touch input now works! Still a few knickknacks to hammer out and the drawing isn’t exactly pretty, but it’s getting there.


GIF

The logic to figure out what pixels to set based on touch input is fairly easy. PlayerControllers provide an

GetInputTouchState(...)

 function which gives the touch position in screen space (in pixels relative to the resolution) and the player controller also contains a function to convert screen space coordinates to world space based on the camera’s view. Putting stuff together you basically do this:

  1. Get input position in screen space (S)
  2. Convert S to world space (W)
  3. Get actor bounds and center (B and C)
  4. Get the world space diff (D) between W and C (W – C)
  5. Divide D by B to get the touch position as a percentage (P) of the drawing area
  6. Remap P from range (-1, 1) to (0, 1) to compensate for the pivot being in the center of the drawing area and not in the top-left
  7. Multiply P by the texture size (T) to get the absolute pixel on the texture touched!
PixelPos = ((W - C) / B) * T

The functional blueprint section looks like this:

Touch input to texture pixel conversion
Touch input to texture pixel conversion

The next step is probably either to link this drawing to the player markers or make the drawing prettier and crush out some bug-related crashes.

 Time-lapse up as usual!

func-data=”width is 560, between char 14 and 18″

About Kenth Ljung

2012 Programming