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

2018/4/25

Character Selection Trying to Spawn Character in Different World

OfficerRiot OfficerRiot

2018/4/25

#
I want when I click on one of my character icons it to spawn my character in a different world this is what I have so far but it seems like it does nothing at the moment. import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class DookuIcon here. * * @author (your name) * @version (a version number or a date) */ public class DookuIcon extends Actor { World a = new MyWorld(); /** * Act - do whatever the DookuIcon wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if (Greenfoot.mouseClicked(this)) a.addObject(new Dooku(), 350, 500); } }
danpost danpost

2018/4/25

#
OfficerRiot wrote...
I want when I click on one of my character icons it to spawn my character in a different world this is what I have so far but it seems like it does nothing at the moment. << Code Omitted >>
You have yet to set the new MyWorld object active using the setWorld method of the Greenfoot class. You may want to consider using a local variable inside the if block instead of a field for the new world. World objects, mainly due to the size of their images, take up a lot of memory and with multiple icons creating and retaining a world (the exact same type world) in each seems like a bit much and there is no need for any MyWorld world to be created before an icon is clicked on.
You need to login to post a reply.