mercredi 14 décembre 2016

Create levels of a Game containing many elements in javafx 8

I'm novice in javaFX and just started to create a plateform car game in 2D. My goal is to create levels with many elements (Element is an abstract class) like Dirt, Rocks etc ... These elements will be ImageView stored in a Pane. Here is the my code for the moment :

ArrayList elementList = new ArrayList<ImageView>();
    for (int i = 0; i < 5; i++)
    {
        Terre t = new Terre(new Image("/images/dirt.jpg"));
        t.initSetting(t.getImageElement(),50,50,755); //image,height,width,position in the Pane
        px = px+300;
        double py = 350 * Math.random() + 600;   
        region.getChildren().add(t.getImageElement()); //region is the Pane
        t.getImageElement().setLayoutX(px);
        elementList.add(t.getImageElement());
    }

But I think there's maybe a simplest way to proceed. I've thought to use the flight weight pattern to modelize such things but i don't know how to implement this... Here is an extract of my class diagram to help you to understand my problem ->Click Here

Thank you for your future help !!

Aucun commentaire:

Enregistrer un commentaire