Hey guys,
Im still struggling here with these blasted input zones. I am jogging along fine with everything else (keeping in mind im learning the script as im going) but i just cant get my input zones to show up.
I understand that i have to set them in my PC class, and draw them in the HUD class.... but i want to do this without extending from SimplePC etc etc.
Im extending from FrameworkGame, MobileHUD, GamePlayerController and GamePawn. Am i correct in doing this?
All i want to setup, is 2 joysticks and a few buttons. I understand how everything works but i just cannot for the life of me get them into my game.
I have searched all over the joint and found some helpful links, although they help alot, they also make me want to ask a few more questions.
http://udn.epicgames.com/Three/MobileInputSystem.html#Adding Input Zones
(http://udn.epicgames.com/Three/MobileInputSystem.html#Adding Input Zones)http://forums.epicgames.com/archive/index.php/t-769831.html
(http://forums.epicgames.com/archive/index.php/t-769831.html)To name a few.
Can anyone give me just the basics of what i need in PSEUDO Code to kick me in the right direction, i can fill the rest in, im just unsure as to which pieces of code i actually need
Any help would be greatly appreciated.
ffejnosliw
10-29-2011, 01:35 PM
Can you show what you've done? It's hard to know what you're missing without knowing what you've done so far. All the info for adding zones is there and SimpleGame gives a complete working example.
Yes sure no worries, There are a few parts missing because i scrapped what i had and re did it, but ill comment in what i had ;)
I had a look at simple game but i dont want the sway / breathe motion and im not sure how to take that out.
BasePC.uc
class BasePC extends GamePlayerController config(BasePC);
var MobilePlayerInput MPI;
var MobileInputZone SliderZone;
var MobileInputZone StickMoveZone;
var MobileInputZone StickLookZone;
var MobileInputZone FreeLookZone;
var vector2D ViewportSize;
event InitInputSystem()
{
Super.InitInputSystem();
MPI = MobilePlayerInput(PlayerInput);
}
function SetupZones()
{
local float Ratio;
local float Spacer;
// Cache the MPI
MPI = MobilePlayerInput(PlayerInput);
SetupZones();
StickMoveZone = MPI.FindZone("BaseMoveZone");
StickLookZone = MPI.FindZone("BaseLookZone");
FreeLookZone = MPI.FindZone("UberLookZone");
// The values here were picked after a long process of trail and error. They basically
// represent the collective "it feels right". These work for EpicCitadel. You will want to
// choose values that work for you.
Spacer = (Ratio == 0.75) ? 96 : 64;
Spacer *= (ViewportSize.X / 1024);
LocalPlayer(Player).ViewportClient.GetViewportSize (ViewportSize);
Ratio = ViewportSize.Y / ViewportSize.X;
if (StickMoveZone != none)
{
if (Ratio == 0.75)
{
StickMoveZone.SizeX = ViewportSize.X * 0.12;
StickMoveZone.SizeY = StickMoveZone.SizeX;
StickMoveZone.ActiveSizeX = StickMoveZone.SizeX;
StickMoveZone.ActiveSizeY = StickMoveZone.SizeY;
}
StickMoveZone.SizeX = Spacer + StickMoveZone.SizeX;
StickMoveZone.SizeY = Spacer + StickMoveZone.SizeY;
if (Ratio == 0.75)
{
StickMoveZone.SizeY *= 1.5;
}
StickMoveZone.X = 0;
StickMoveZone.Y = ViewportSize.Y - StickMoveZone.SizeY;
StickMoveZone.CurrentCenter.X = StickMoveZone.X + StickMoveZone.SizeX - (StickMoveZone.ActiveSizeX*0.5);
if (Ratio == 0.75)
{
StickMoveZone.CurrentCenter.Y = ViewportSize.Y - StickMoveZone.SizeY * 0.33;
}
else
{
StickMoveZone.CurrentCenter.Y = StickMoveZone.Y + StickMoveZone.ActiveSizeY * 0.5;
}
StickMoveZone.CurrentLocation = StickMoveZone.CurrentCenter;
StickMoveZone.InitialCenter = StickMoveZone.CurrentCenter;
StickMoveZone.bCenterOnEvent = true;
}
}
defaultproperties
{
}
BaseHUD.uc
class BaseHUD extends MobileHUD
config(BaseHUD);
simulated event PostRender()
{
super.PostRender();
DrawHUD();
}
function DrawBar(String Title,float Value,float MaxValue,int X,int Y,int R,int G,int B)
{
local int PosX;
local int PosY;
local int BarSizeX;
PosX = 20;
PosY = 20;
BarSizeX = 300 * FMin (Value / MaxValue , 1); /* This will change the size of our active rectangle depending on how much health our pawn has*/
/* Displays my ACTIVE rectangle */
Canvas.SetPos(PosX, PosY);
Canvas.SetDrawColor(R, G, B, 200);
Canvas.DrawRect(BarSizeX, 15);
/* Displays my INACTIVE rectangle */
Canvas.SetPos(PosX + BarsizeX, PosY);
Canvas.SetDrawColor(255,255,255,80);
Canvas.DrawRect(300 - BarSizeX, 15); /* 300 = Your desired bar size */
/* Displays the title */
Canvas.SetPos(PosX + 300 + 5, PosY); /* 300 = Your desired bar size */
Canvas.SetDrawColor(R, G, B, 200);
Canvas.Font = class'Engine'.static.GetSmallFont();
Canvas.DrawText(Title);
}
function DrawHUD()
{
if (!PlayerOwner.IsDead())
{
DrawBar("Health:"@PlayerOwner.Pawn.Health$"%",PlayerOwner.Pawn.Health,PlayerOwner.Pawn.HealthMa x,20,20,255,0,0);
}
}
function DrawMobileZone_Joystick(MobileInputZone Zone)
{
local int X, Y, Width, Height;
local Color LineColor;
local float ClampedX, ClampedY, Scale;
local Color TempColor;
if (Zone.OverrideTexture1 != none || JoystickBackground != none)
{
Width = Zone.ActiveSizeX;
Height = Zone.ActiveSizeY;
X = Zone.CurrentCenter.X - (Width /2);
Y = Zone.CurrentCenter.Y - (Height /2);
Canvas.SetPos(X,Y);
// check for override textures
if (Zone.OverrideTexture1 != none)
{
Canvas.DrawTile(Zone.OverrideTexture1, Width, Height, Zone.OverrideUVs1.U, Zone.OverrideUVs1.V, Zone.OverrideUVs1.UL, Zone.OverrideUVs1.VL);
}
else
{
Canvas.DrawTile(JoystickBackground, Width, Height, JoystickBackgroundUVs.U, JoystickBackgroundUVs.V, JoystickBackgroundUVs.UL, JoystickBackgroundUVs.VL);
}
}
// Draw the Hat
if (Zone.OverrideTexture2 != none || JoystickHat != none)
{
// Compute X and Y clamped to the size of the zone for the joystick
ClampedX = Zone.CurrentLocation.X - Zone.CurrentCenter.X;
ClampedY = Zone.CurrentLocation.Y - Zone.CurrentCenter.Y;
Scale = 1.0f;
if ( ClampedX != 0 || ClampedY != 0 )
{
Scale = Min( Zone.ActiveSizeX, Zone.ActiveSizeY ) / ( 2.0 * Sqrt(ClampedX * ClampedX + ClampedY * ClampedY) );
Scale = FMin( 1.0, Scale );
}
ClampedX = ClampedX * Scale + Zone.CurrentCenter.X;
ClampedY = ClampedY * Scale + Zone.CurrentCenter.Y;
if (Zone.bRenderGuides)
{
TempColor = Canvas.DrawColor;
LineColor.R = 128;
LineColor.G = 128;
LineColor.B = 128;
LineColor.A = 255;
Canvas.Draw2DLine(Zone.CurrentCenter.X, Zone.CurrentCenter.Y, ClampedX, ClampedY, LineColor);
Canvas.DrawColor = TempColor;
}
// The size of the indicator will be a fraction of the background's total size
Width = Zone.ActiveSizeX * 0.65;
Height = Zone.ActiveSizeY * 0.65;
Canvas.SetPos( ClampedX - Width / 2, ClampedY - Height / 2);
// check for override textures
if (Zone.OverrideTexture2 != none)
{
Canvas.DrawTile(Zone.OverrideTexture2, Width, Height, Zone.OverrideUVs2.U, Zone.OverrideUVs2.V, Zone.OverrideUVs2.UL, Zone.OverrideUVs2.VL);
}
else
{
Canvas.DrawTile(JoystickHat, Width, Height, JoystickHatUVs.U, JoystickHatUVs.V, JoystickHatUVs.UL, JoystickHatUVs.VL);
}
}
}
defaultproperties
{
}
DefaultGameUDK.ini
[ProjectSS.BaseGame]
+RequiredMobileInputConfigs=(GroupName="BaseGroup",RequireZoneNames=("BaseMoveZone","BaseButtonZone","BaseLookZone","BaseFreeLookZone"))
[BaseMoveZone MobileInputZone]
InputKey=MOBILE_AForward
HorizontalInputKey=MOBILE_AStrafe
Type=ZoneType_Joystick
bRelativeX=true
bRelativeY=true
bRelativeSizeX=true
bRelativeSizeY=true
X=0.05
Y=-0.4
SizeX=0.1965
SizeY=1.0
bSizeYFromSizeX=true
VertMultiplier=-1.0
HorizMultiplier=1.0
bScalePawnMovement=true
RenderColor=(R=255,G=255,B=255,A=255)
InactiveAlpha=0.25
bUseGentleTransitions=true
ResetCenterAfterInactivityTime=3.0
ActivateTime=0.6
DeactivateTime=0.2
TapDistanceConstraint=5
[BaseLookZone MobileInputZone]
InputKey=MOBILE_AForward
HorizontalInputKey=MOBILE_ATurn
Type=ZoneType_Joystick
bRelativeX=true
bRelativeY=true
bRelativeSizeX=true
bRelativeSizeY=true
VertMultiplier=-0.5
HorizMultiplier=0.35
X=-0.2465
Y=-0.4
SizeX=0.1965
SizeY=1.0
bSizeYFromSizeX=true
RenderColor=(R=255,G=255,B=255,A=255)
InactiveAlpha=0.25
bUseGentleTransitions=true
ResetCenterAfterInactivityTime=3.0
ActivateTime=0.6
DeactivateTime=0.2
TapDistanceConstraint=5
[BaseButtonZone MobileInputZone]
InputKey=
Type=ZoneType_Button
bRelativeX=true
bRelativeY=true
X=0.9
Y=0.9
bRelativeSizeX=true
bRelativeSizeY=true
SizeX=0.0625
SizeY=0.0938
Caption="Button"
RenderColor=(R=0,G=128,B=255,A=255)
InactiveAlpha=0.8
bIsInvisible=0
TapDistanceConstraint=32
[BaseFreeLookZone MobileInputZone]
InputKey=MouseY
HorizontalInputKey=MouseX
TapInputKey=MOBILE_Fire
Type=ZoneType_Trackball
bRelativeSizeX=true
bRelativeSizeY=true
X=0
Y=0
SizeX=1.0
SizeY=1.0
VertMultiplier=-0.0007
HorizMultiplier=0.001
Acceleration=12.0
I think im not referencing to them correctly?
ffejnosliw
10-29-2011, 02:33 PM
But where are your .ini file entries for the input zones?
Sorry Jeff,
Added it in the post above. I think i am not referencing to it correctly?
ffejnosliw
10-29-2011, 08:10 PM
Have you tried using log statements to follow the code and see what is going on?
Honestly, if that is your exact code, I would expect the game to crash because you are calling SetupZones() from within SetupZones() which would recurse infinitely.
It did crash a few times, i remember fixing that. I will use some log statements in there to check what is happening.
Am I on the right path though or miles from it? I just need a bit of a point and ill be good to go, im just confused as to how they are called and drawn etc.
Is it like,
DefaultGameUDK.uc (This makes the zone) -----> BasePC.uc (This makes the function or calls it??) -----> BaseHUD.uc (This gives it its appearance)
Or am i missing something? I have read through the UDN countless times, but i cant understand how to implement one with no sway or breathing motion without extending from Simple*.uc etc.
I want to extend from where Simple*.uc extends from so that i can properly learn and remember how it all works.
I get an idea of how it works when i look at the code i am extending from, but i do not remember how it is set out and i keep having to refer back to it :P
Thanks for you help so far! :)
ffejnosliw
10-30-2011, 01:37 AM
Your SetupZones() is never being called in the code above actually. InitInputSystem() in SimplePC calls that function. Your InitInputSystem() does not. The call to SetupZones() inside your SetupZones() should be in InitInputSystem().
I'm not saying that is the only issue, but it jumps out at me. I would compare all your functions to the SimplePC/SimpleGame/SimpleHUD counterparts to see if there are any obvious differences.
Ok thanks for that Jeff, i will have a fiddle with it now.
I see what i am doing wrong, well part of it anyway. I was thinking that having SetupZones() inside SetupZones() would always make it active, therefor they always show. But i see what im doing wrong.
Thanks!
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.