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

2013/5/6

inserting an object at a button

Hawx_ Hawx_

2013/5/6

#
I'm trying to add a "Plasma" at the character , is this right? ( this code is in the actor) I know I need to use getWorld(). but I forgotten what to do.
  public void shoot()
    {
        if (Greenfoot.isKeyDown("space"))
        {
           
        Plasma plasma = new Plasma();
        addObject(plasma, getX(), getY());
        
    }
}
Hawx_
JetLennit JetLennit

2013/5/6

#
Is this in an actor or world class?
Hawx_ Hawx_

2013/5/6

#
actor class
JetLennit JetLennit

2013/5/6

#
Try
public void shoot()
    {
        if (Greenfoot.isKeyDown("space"))
        {
           
        Plasma plasma = new Plasma();
        getWorld().addObject(plasma, getX(), getY());
        
    }
}
Hawx_ Hawx_

2013/5/6

#
It's compiling with no errors but it's not spawning any plasma. Any ideas?
JetLennit JetLennit

2013/5/6

#
Have you called shoot in the act method?
Hawx_ Hawx_

2013/5/6

#
thannks for reminding me , I forgot to put it in there. :D
holla holla

2013/5/6

#
i dont think so :) /Edit: happens alot to me. like forgetting simple things
You need to login to post a reply.