Here is my way of onReleased alternative ...
I am sure there is something more elegant and better Kjell and JPH are using...
KeyPress' onReleased alternative
Moderator: Moderators
KeyPress' onReleased alternative
- Attachments
-
- MouseReleased.zgeproj
- (2.25 KiB) Downloaded 784 times
Hi turshija,
Attached ( both exe and source ) is the system I have been using* for quite some while now. The example uses the following structure.
Input[Slots,Keys,Events]
- Slots being the amount of Player Slots you want to support.
- Keys being the amount of Keys you want to check.
- Events being the amount of Events each Key uses.
Since there's currently no function to read out the length of one of the dimensions a array has, the lengths are stored in Constants. In the example this is InputSlots = 2 ( for 2 Players ), InputKeys = 4 ( 4 Keys each, Arrow keys for P1 / WASD for P2 ) and InputEvents = 4 ( 4 Events per Key ).
Event[0] is just the current state of the Key, in Event[3] ( which is referred to as InputEvents-1 ) the state of the Key as it was the last frame is stored, while Event[1] is reserved for a OnPressed event, and Event[2] for OnReleased.
The EXE uses a low framerate ( 15 fps ) to make the OnPressed / OnReleased and LastFrame values more easy to distinguish.
Have fun ~
K
*Didn't work in Beta 1.9.4 because of a 3D Array bug, make sure you get 1.9.5
Attached ( both exe and source ) is the system I have been using* for quite some while now. The example uses the following structure.
Input[Slots,Keys,Events]
- Slots being the amount of Player Slots you want to support.
- Keys being the amount of Keys you want to check.
- Events being the amount of Events each Key uses.
Since there's currently no function to read out the length of one of the dimensions a array has, the lengths are stored in Constants. In the example this is InputSlots = 2 ( for 2 Players ), InputKeys = 4 ( 4 Keys each, Arrow keys for P1 / WASD for P2 ) and InputEvents = 4 ( 4 Events per Key ).
Event[0] is just the current state of the Key, in Event[3] ( which is referred to as InputEvents-1 ) the state of the Key as it was the last frame is stored, while Event[1] is reserved for a OnPressed event, and Event[2] for OnReleased.
The EXE uses a low framerate ( 15 fps ) to make the OnPressed / OnReleased and LastFrame values more easy to distinguish.
Have fun ~
K
*Didn't work in Beta 1.9.4 because of a 3D Array bug, make sure you get 1.9.5
- Attachments
-
- Input.zip
- (40.72 KiB) Downloaded 757 times
Since the 2009 Beta release and the introduction of the "For-statement" you can just use ZExpressions ( without any repeat components ) to reset and process the values. So for the provided example ..
Reset
Code: Select all
for(U=0; U<Input.SizeDim1; ++U)
{
for(V=0; V<Input.SizeDim2; ++V)
{
Input[U,V,Input.SizeDim3-1] = Input[U,V,0];
for(W=0; W<Input.SizeDim3-1; ++W)
{
Input[U,V,W] = 0;
}
}
}
Code: Select all
for(U=0; U<Input.SizeDim1; ++U)
{
for(V=0; V<Input.SizeDim2; ++V)
{
if(Input[U,V,0] == 1 && Input[U,V,Input.SizeDim3-1] == 0){Input[U,V,1] = 1;}
if(Input[U,V,0] == 0 && Input[U,V,Input.SizeDim3-1] == 1){Input[U,V,2] = 1;}
}
}
K
- jph_wacheski
- Posts: 1005
- Joined: Sat Feb 16, 2008 8:10 pm
- Location: Canada
- Contact:
single slot input setup
I have started using this setup for all my input,. as it provides a greater detail with the OnPressed, OnReleased, and LastFrame info. However I did not have a use for the 'slots' (is that for a split-screen two player game?) so just to simpify it a bit, I hacked that part off,. . find this attached for those who are interested in the same.
Thanks for your logic work Kj!
Thanks for your logic work Kj!
- Attachments
-
- Input_single_slot.zip
- .zgeproj
- (1 KiB) Downloaded 655 times
iterationGAMES.com
Hey jph,
Yea, you only need the additional dimension when your game supports more then one player, otherwise a 2D Array is sufficient.
By the way, there's a slight performance benefit when you're using local variables opposed to global. Also, when dealing with Keyboard / Joypad Button input, integers ( since booleans aren't supported ) are more appropriate then floats.
+ I use RST / UVW / XYZ variable combinations in relation to their according array dimensions, so for a 2D Array I'd go with U and V ( not V & W )
K
Yea, you only need the additional dimension when your game supports more then one player, otherwise a 2D Array is sufficient.
By the way, there's a slight performance benefit when you're using local variables opposed to global. Also, when dealing with Keyboard / Joypad Button input, integers ( since booleans aren't supported ) are more appropriate then floats.
+ I use RST / UVW / XYZ variable combinations in relation to their according array dimensions, so for a 2D Array I'd go with U and V ( not V & W )
K