This site requires JavaScript, please enable it in your browser!
Greenfoot back
iban
iban wrote ...

2017/4/1

Button Fire / Button shoot

1
2
3
iban iban

2017/4/1

#
i want make game space shoot. but all control use the button and logic mouseClicked. the problem, i'am want creat button fire / button shoot but i dont know the coding. please help me !!!!!
Super_Hippo Super_Hippo

2017/4/1

#
I don't really understand what you mean. Do you want to create a visible button in your world which you have to press with your mouse to shoot?
iban iban

2017/4/2

#
public void shoot() { if (Greenfoot.mousePressed(shoot.class)) { getWorld().addObject(new bullet(), getX(), getY()); } }
iban iban

2017/4/2

#
whay that not work?
iban iban

2017/4/2

#
i want make all control with button with methode mouse clicked/ mouse pressed.. not isKeyDown(). please help me :)
danpost danpost

2017/4/2

#
iban wrote...
public void shoot() { if (Greenfoot.mousePressed(shoot.class)) { getWorld().addObject(new bullet(), getX(), getY()); } }
'shoot.class' is not a valid parameter for the 'mousePressed' method. You must supply an Actor or World object -- not a class. You could also use 'null' and then figure out if the object of the action is indeed a 'shoot' object:
1
if (Greenfoot.mousePreesed(null) && Greenfoot.getMouseInfo().getActor() instanceof shoot)
iban iban

2017/4/2

#
that code i must put in class buttonshoot or bullet mr? i not understand. i'am very new in greenfoot, i'am sorry :(
danpost danpost

2017/4/2

#
iban wrote...
that code i must put in class buttonshoot or bullet mr? i not understand. i'am very new in greenfoot, i'am sorry :(
I would say it would go either in your subclass of World or in the class of whatever you may have that is shooting the bullet. Either way, in the act method.
iban iban

2017/4/2

#
i put in buttonshoot. but this error. i'm very newbee , not understand mr.
danpost danpost

2017/4/2

#
iban wrote...
i put in buttonshoot. but this error. i'm very newbee , not understand mr.
You need to supply what error you got (copy/paste the entire error output) and then show the code in question (the entire class).
iban iban

2017/4/2

#
i think a must send my project to you mr. can i know your email?? i send to email pleaseee:)
iban iban

2017/4/2

#
the problem only one more again. i can't shoot use button shoot, i not understand
iban iban

2017/4/2

#
this class bullet =================================================================== import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) public class peluru extends Actor public void act() { setLocation(getX()+5, getY()); } }
iban iban

2017/4/2

#
this class buttonshoot. just empty because i not understand ================================================= import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class tambak here. * * @author (your name) * @version (a version number or a date) */ public class tambak extends Button { /** * Act - do whatever the tambak wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { } }
iban iban

2017/4/2

#
this class roket ===================== import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class roket here. * * @author (your name) * @version (a version number or a date) */ public class roket extends Actor { /** * Act - do whatever the roket wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { } }
There are more replies on the next page.
1
2
3