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

2016/11/9

Spawning an object to a particular side of another object?

cmdshepard cmdshepard

2016/11/9

#
so im in the middle of developing a crappy space based game where little ships fly around and shoot other ships. sounds simple right? but whenever i use the fire button the slug always comes out of the top. i need to figure out how to make the slug exit a particular side on the frigate class. any ideas?
danpost danpost

2016/11/9

#
cmdshepard wrote...
so im in the middle of developing a crappy space based game where little ships fly around and shoot other ships. sounds simple right? but whenever i use the fire button the slug always comes out of the top. i need to figure out how to make the slug exit a particular side on the frigate class. any ideas?
You can position it after adding it to the world. For example to have a slug start 20 pixels to the right of center of the frigate:
Slug slug = new Slug(); // create slug
addObject(slug, getX(), getY()); // add slug to world at frigate location
slug.setRotation(getRotation()); // match rotation of frigate
slug.turn(90); // turn right
slug.move(20); // move 20 pixels
slug.turn(-90); // turn left
cmdshepard cmdshepard

2016/11/11

#
cheers bro! Ill give it a try
cmdshepard cmdshepard

2016/11/11

#
should i add this in class frigate or slug?
Super_Hippo Super_Hippo

2016/11/11

#
In the frigate class.
danpost danpost

2016/11/11

#
Super_Hippo wrote...
In the frigate class.
And line 2 should be:
getWorld().addObject(slug, getX(), getY());
cmdshepard cmdshepard

2016/11/11

#
alright, cheers again chaps
You need to login to post a reply.