Results 1 to 4 of 4
  1. #1
    dutpas is offline Member
    Join Date
    Mar 2016
    Posts
    2
    Rep Power
    0

    Default Problem about locating a froup of objects, before a translation

    Hello,

    I have a starship that is moving by a translateTransition , by key pressed.



    For easing the intersect between mobile objects (starship , bullets, ..) , for each object, I have created a rectangle that includes this object.
    Therefore, for each object, there is a group that contains this object and its rectangle.

    When I want to move the object, I move the group (that indirectly moves object+rectangle)

    Now, when I whant to shut a projectile (bullet) from a starship, I want to get the current position of the starship for initialising the projectile coordinates.

    In practice, the projectile coordinates are wrong (values are older).

    Have you some ideas about this problem?

    Regards

    ----------------------


    class Projectile extends ObjetMobile {

    private Vaisseau vaisseauDeLancement;
    protected Image imgMobile;
    protected ImageView iView;

    // For any mobile (Projectile, starship), its rectangle (enveloppe) is added for managing collisions
    protected Rectangle enveloppe;

    // A mobile with its rectangle are a group
    protected Group groupMobile;


    public Projectile(Vaisseau v) {
    this.vaisseauDeLancement = v;

    imgProjectile = new Image(Main.class.getResourceAsStream("/toto.gif"));
    this.iView = new ImageView();
    this.iView.setImage(this.imgProjectile);

    this.enveloppe = new Rectangle();
    this.enveloppe.setFill(Color.BROWN);

    groupMobile = new Group();
    groupMobile.getChildren().add(this.iView);
    groupMobile.getChildren().add(this.enveloppe);
    }
    }


    /************************************************** ******/
    private Projectile creerProjectile(projectileType pType, envoyeParType e, Vaisseau v) {
    Projectile p = new Projectile(pType, e, v, widthScreen, heightScreen);

    locateProjectileUnderItsStarship(p, v);
    putProjectileOnScreen(p,v);

    return p;
    }


    /************************************************** ******/
    void locateProjectileUnderItsStarship(Projectile pp, Vaisseau v) {
    double[] xy = { 0.0, 0.0 };

    xy = v.getPosXY();
    pp.setPosXY(xy);
    }


    /************************************************** ******/
    void putProjectileOnScreen(Projectile pMiss, Vaisseau v){
    root.getChildren().add(pMiss.getGroupMobile());

    AnchorPane.setLeftAnchor(pMiss.getImageView(), pMiss.getPosX());
    AnchorPane.setTopAnchor(pMiss.getImageView(), pMiss.getPosY());

    pMiss.enveloppe.setX(pMiss.getPosX());
    pMiss.enveloppe.setY(pMiss.getPosY());


    }

    /************************************************** ******/
    double[] getPosXY() {
    double[] T_xy = new double[2];
    T_xy[0] = iView.getX();
    T_xy[1] = iView.getY();
    return (T_xy);
    }



    /************************************************** ******/
    void setPosXY(double[] xy) {
    this.iView.setX(xy[0]);
    this.iView.setY(xy[1]);
    }

    /************************************************** ******/
    static void translater(ObjetMobile o, double[] deplactXY) {
    TranslateTransition translateTransition;

    Group groupM = o.getGroupMobile();

    translateTransition = new TranslateTransition(durationDeplacement, groupM);

    double[] xy = o.getPosXY();

    translateTransition.setByX(deplactXY[0]);
    translateTransition.setByY(deplactXY[1]);
    xy[0] += deplactXY[0];
    xy[1] += deplactXY[1];


    translateTransition.setAutoReverse(false);
    translateTransition.setCycleCount(1);
    translateTransition.setInterpolator(Interpolator.L INEAR);
    translateTransition.play();

    o.setPosXY(xy);

    Rectangle enveloppeDeMobile = o.getEnveloppe();
    enveloppeDeMobile.setX(o.getPosX());
    enveloppeDeMobile.setY(o.getPosY());

    }

  2. #2
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    398
    Rep Power
    5

    Default Re: Problem about locating a froup of objects, before a translation

    The method getPosXY() returns the location of the iView object (image of your bullet) rather than the location of the ship.

  3. #3
    dutpas is offline Member
    Join Date
    Mar 2016
    Posts
    2
    Rep Power
    0

    Default Re: Problem about locating a froup of objects, before a translation

    Quote Originally Posted by benji2505 View Post
    The method getPosXY() returns the location of the iView object (image of your bullet) rather than the location of the ship.
    Thank you very much for your response but:

    The method locateProjectileUnderItsStarship has two parameters: pp (the bullet or "projectile") and v (the ship or "vaisseau"). Therefore, I think my method is correct:
    - I get the ship position
    - then, I copy this ship position to the bullet position, before I launch the bullet

    ==> Other idea about this problem?

    It could be a conflict between the getX method and many successive translateTransitions of the ship (one by second), even if the translateTransitions have been done in a very short duration (setCycleCount(1)) for avoiding real time problems.

    Thank you for your ideas
    Pascal

  4. #4
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    398
    Rep Power
    5

    Default Re: Problem about locating a froup of objects, before a translation

    I read your code differently, but I might be wrong. Can you post the ship class, preferably in code tags?

Similar Threads

  1. Locating a digit within a string
    By ScentOfAWookie in forum New To Java
    Replies: 8
    Last Post: 03-27-2009, 05:23 PM
  2. X / Y Translation Problem
    By SkinnyK in forum New To Java
    Replies: 4
    Last Post: 01-16-2009, 12:20 AM
  3. Problem locating resources on Linux.
    By jimm1 in forum New To Java
    Replies: 1
    Last Post: 01-18-2008, 06:34 PM
  4. Locating the home interface
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-28-2007, 10:42 AM
  5. problem locating file in web application
    By Rem in forum New To Java
    Replies: 0
    Last Post: 11-09-2007, 04:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •