Hi forum!,
I have this one image of a gun, and a gun with a muzzle flash, and I have it set up so when I click, the image of blank gun changes to the image of the shooting gun. This is the code I am using:
[java] if (name.equals("Shoot") && !keyPressed){
guiNode.attachChild(gun);
creategun();
}
else {
createmuzzleFlashGun();
audio_gun.playInstance();
}[/java]
The methods here creategun(); and create muzzleflashGun(); just change the image used for the guiNode.attachChild(gun);
So now I have a problem: When I hold the mouse button down the gun with the muzzle flash stays there, which is unrealistic behaviour, as real guns dont have constant fire coming out the end
Does anyone have any ideas?
Help appreciated!
Live long.
add a Control to your gun that keeps track of the time when it was added (buy the person clicking) and then it can track each frame to see if a certain amount of time has passed.
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:custom_controls
The problem is, both my guns are called gun, like so:
[java]Picture gun = new Picture(“gun”);
private void creategun() {
gun.setImage(assetManager, “Interface/ak1.png”, true);
gun.setWidth(settings.getWidth()/2);
gun.setHeight(settings.getHeight()/2);
gun.setPosition(settings.getWidth()-settings.getWidth()/2, 2);
}
private void createmuzzleFlashGun() {
gun.setImage(assetManager, “Interface/ak2.png”, true);
gun.setWidth(settings.getWidth()/2);
gun.setHeight(settings.getHeight()/2);
gun.setPosition(settings.getWidth()-settings.getWidth()/2, 2);
}[/java]
So I’ll have to change the way i’ve done this, won’t I
Nope. that has nothing to do with the control suggestion.
Dude, you are stubborn :P! You code like a Pascal programmer xD.
Maybe you can create a float “timer” and a boolean “shoot”, put it in the update() loop
[java]if(shoot){
if(timer>=0.5f){
shoot=false;
//“what you want to change after 0.5 sec”
}else{timer+=tpf;}}
[/java]
and this when the shoot is activated
[java]shoot=true;
timer = 0.0f;[/java]
Kernproblem
@kernproblem said:
Maybe you can create a float "timer" and a boolean "shoot", put it in the update() loop
[java]if(shoot){
if(timer>=0.5f){
shoot=false;
//"what you want to change after 0.5 sec"
}else{timer+=tpf;}}
[/java]
and this when the shoot is activated
[java]shoot=true;
timer = 0.0f;[/java]
Kernproblem
This is essentially what @sploreg was suggesting the original poster do in a control.... otherwise every object you have to have that same calculation and if statement versus just adding a single control to it.