long Keypress

Post

Posted
Rating:
#1 (In Topic #2035)
Avatar
Enthusiast
Yogi is in the usergroup ‘Enthusiast’
Hi folks,

I am currently creating a game from the 80s (1978), Space Invaders ("older" people know this of sure 😁).

The first steps have been taken, and some functionality is already in place.

One problem is pressing the left and right keys for moving the defender.
When pressed individually, everything works fine.
When the key is held down, it takes too long for the repeat function to kick in. So the Aliens
shoot me down very often because of this delay.

What I tried without success:
if the key is pressed (left or right in this case) the _keypress() sub is called.
With a public var I set to true in this case I call the moveit sub.
In there I check if the var is true or false.

If true it repeats moving, till the var is set to false in the _keyrelease() event.

Somehow the hole app freezes… ( maybe because of endless calls to _keypress() )

Has anyone an idea to get this running?

I don't want to change the system accessibility values if possible (or If we have to we set the values
back to the default values at the end of the game)

Also what I never encountered before:
I gave the form background color to black, so the menu also gets black, I just did a foreground colour
for better sight, any chance to set the background colour of the menu independently?

Image

Invader.jpg

Invader.jpg


And the last one:
in the keypress sub the key.code for ctrl is not recognised, so I used the key.code I got  as a number,
ctrl is for the shooting,
(Documentation: NEVER use the key values directly, as they change between GUI components. Always use these constants! )

Thanks,
Yogi

 
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Administrator
gbWilly is in the usergroup ‘unknown’
gbWilly leads the usergroup ‘GambOS Contributor’
gbWilly is in the usergroup ‘Blogger’

Yogi said

I am currently creating a game from the 80s (1978), Space Invaders ("older" people know this of sure 😁).

Played that a lot when I was young. Great game. Been thinking often to create this myself, but just too busy with other stuff.

Yogi said

One problem is pressing the left and right keys for moving the defender.
When pressed individually, everything works fine.
When the key is held down, it takes too long for the repeat function to kick in. So the Aliens
shoot me down very often because of this delay.

Change the delay on your system should fix that

Yogi said

I don't want to change the system accessibility values if possible (or If we have to we set the values<br />
back to the default values at the end of the game)

Ok, so change the delay when starting the game from within the game and set it back when closing the game, from within the game.
You will need to dive into where this configuration info is saved and modify it on the fly with some code in your game..
So, some research into how your distro takes care of that will be required and where all this info is stored.
As this is user based, you should not require elevated rights to change this from code.

Yogi said

Also what I never encountered before:
I gave the form background color to black, so the menu also gets black, I just did a foreground colour
for better sight, any chance to set the background colour of the menu independently?
]

These things (customise colors) are all very toolkit related and a pain in the ass. There is no one good solutions.
Did you try setting the form arrangement to fill and add a panel set to expand with a black background and use that as form background instead. That should not interfere with the form menu.

Yogi said

And the last one:
in the keypress sub the key.code for ctrl is not recognised, so I used the key.code I got  as a number,
ctrl is for the shooting,
(Documentation: NEVER use the key values directly, as they change between GUI components. Always use these constants! )
 

Do you have a excerp of the code that manages the keys.
Hard to tell what is happening without seeing any code.

Looking forward tp play this one  :thumbs:

gbWilly
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories


… there is always a Catch if things go wrong!
Online now: No Back to the top
1 guest and 0 members have just viewed this.