I need little example

Thank you, it’s very clear with ElementEmitter, I will see what i will get from HitCalculator :wink:

1 Like

so it’s working like a charm ;D
if someone will need collision method, it is here:
someone can rewrite in nicer way (sorry I don’t have coding industry practice)
[java]
public void checkBulletCollsiionsForPlayerBullets() {
if (player != null && active) {
for (QuadData bullet : player.getWeapon().getEmitter().getParticles().getQuads().values()) {
if (player.getWeapon().getEmitter().getParticle(bullet.index).active) {
Iterator<AnimElement> iter = enemyController.getAllBugs().iterator();
while (iter.hasNext()) {
AnimElement animEl = iter.next();
if (animEl.getPositionX() < bullet.getPositionX() && animEl.getPositionX() + animEl.getDimensions().x > bullet.getPositionX() &&//check x
animEl.getPositionY() < bullet.getPositionY() && animEl.getPositionY() + animEl.getDimensions().y > bullet.getPositionY()) {//check y
handelBugAndBulletCollission(animEl, bullet);
iter.remove();
}
}
}
}
}
}

private void handelBugAndBulletCollission(AnimElement bug, QuadData quad) {
    bug.removeFromParent();
    player.getWeapon().getEmitter().removeParticle(player.getWeapon().getEmitter().getParticle(quad.index));
    Bug b = (Bug) bug;
    player.addScore(b.getScoreWorth());
}

[/java]

1 Like

I have one more question : is it possible animated bug, with addAction(), (I have added SplineAction() object), to make look in way in which bug is flying ?
My bug is flying, it was really easy to set up, but now i want to make him look in front, if you now what i mean.

I have tried RotateByAction object, it is working, but i think it would be difficult too set up for each path, maybe somehow it is possible to make it automatically?

@SetasSan said: I have one more question : is it possible animated bug, with addAction(), (I have added SplineAction() object), to make look in way in which bug is flying ? My bug is flying, it was really easy to set up, but now i want to make him look in front, if you now what i mean.

I have tried RotateByAction object, it is working, but i think it would be difficult too set up for each path, maybe somehow it is possible to make it automatically?

I think I would directly call AnimElement.setRotation() during the AnimElement’s update loop and potentially use lookAt(nextVectorInPath) to determine which direction they should be looking towards. You’ll need to *FastMath.RAD_TO_DEG I believe as I chose to use degrees in rotation.

So… I guess I would set up an actual JME Quad and in the update loop of the AnimElement, move the quad to the position of the AnimElement, use lookAt to find the rotation, then set the rotation based on this. I’m pretty sure I used a similar technique to fake particle physics for the emitter system (FX Builder one) and it worked really well.

2 Likes

how i can getNextVectorInPath path ?
SplineAction is not giving such a method.
I have used node

[java]
public class Bug extends AnimElement {
private Node pointer = new Node();
private SplineAction track = new SplineAction();

public void animElementUpdate(float f) {

pointer.lookAt(new Vector3f(getPosition().x, getPosition().y, getPositionZ()), Vector3f.UNIT_Y);
pointer.setLocalTranslation(getPosition().x, getPosition().y, getPositionZ());

setRotation(pointer.getLocalRotation().getX() *FastMath.TWO_PI* FastMath.RAD_TO_DEG);

}
}

[/java]

This is how I rotating, but it’s working until bug is turning back, then bug is in lowest point and should go back it’s starts twisting and coming almost in backward position

@SetasSan said: how i can getNextVectorInPath path ? SplineAction is not giving such a method. I have used node

[java]
public class Bug extends AnimElement {
private Node pointer = new Node();
private SplineAction track = new SplineAction();

public void animElementUpdate(float f) {

pointer.lookAt(new Vector3f(getPosition().x, getPosition().y, getPositionZ()), Vector3f.UNIT_Y);
pointer.setLocalTranslation(getPosition().x, getPosition().y, getPositionZ());

setRotation(pointer.getLocalRotation().getX() *FastMath.TWO_PI* FastMath.RAD_TO_DEG);

}
}

[/java]

This is how I rotating, but it’s working until bug is turning back, then bug is in lowest point and should go back it’s starts twisting and coming almost in backward position

Ah… good point. Perhaps check to see if the current position is greater than or less than the formation position to ensure the bug doesn’t flip around like that.

And you are also correct about no method being available there for retrieving the points in the path. I should probably make that accessible as I can see multiple uses for it without thinking very long about it :wink: For the time being, how are you initially defining the path? Do you have a way of leveraging that?

I have created path easy way ;D
[java]
public class MoveTrack {

private AnimLayer animLayer;
private float h;
private float w;
private ArrayList&lt;Vector2f&gt; listTopRigh = new ArrayList&lt;Vector2f&gt;();
private ArrayList&lt;Vector2f&gt; listTopLeft = new ArrayList&lt;Vector2f&gt;();

public MoveTrack(AnimLayer animLayer) {
    this.animLayer = animLayer;
    w = animLayer.getWidth() / 100; 
    h = animLayer.getHeight() / 100;     
    listTopRigh = createTrackFromTopList();
    listTopLeft = reverseTrackX(listTopRigh);
}

public ArrayList&lt;Vector2f&gt; getListTopRight() {
    return listTopRigh;
}

public ArrayList&lt;Vector2f&gt; getListTopLeft() {
    return listTopLeft;
}

private ArrayList&lt;Vector2f&gt; createTrackFromTopList() {
    ArrayList&lt;Vector2f&gt; list = new ArrayList&lt;Vector2f&gt;();
    list.add(new Vector2f(w * 70, h * 105));
    list.add(new Vector2f(w * 70, h * 50));
    list.add(new Vector2f(w * 10, h * 50));
    list.add(new Vector2f(w * 0, h * 30));
    list.add(new Vector2f(w * 20, h * 0));
    list.add(new Vector2f(w * 20, h * 0));    
    return list;
}

private ArrayList&lt;Vector2f&gt; reverseTrackX(ArrayList&lt;Vector2f&gt; from) { 
    ArrayList&lt;Vector2f&gt; to = new ArrayList&lt;Vector2f&gt;();
    for (Vector2f vect : from) {
        Vector2f newPos = new Vector2f();
        newPos.x = animLayer.getWidth() - vect.x;
        newPos.y = vect.y;
        to.add(newPos);
    }
    return to;
}

}
[/java]

after it i setting path

[java]

public void setFlyType(FlyType ft) {
switch (ft) {
case topLeft:
ArrayList<Vector2f> pathTL = moveTrack.getListTopLeft();
pathTL.add(startPos);
track.setPath(pathTL);
break;
case topRight:
ArrayList<Vector2f> pathTR = moveTrack.getListTopRight();
pathTR.add(startPos);
track.setPath(pathTR);
break;
}

}

[/java]

and before i have created all bugs in map with start position where they should be after action

[java]
private void createAllBugs() {
float eachBugSpaseWidth = animLayer.getWidth() * colWidth / col;
float moveBackInHalf = animLayer.getWidth() * colWidth / col / 2;
float startX = (animLayer.getWidth() - animLayer.getWidth() * colWidth) / 2;
float eachBugHeight = eachBugSpaseWidth;
float startY = animLayer.getHeight() * starFirsColY;
int l = 0;
for (int a = 1; a < rows + 1; a++) {
for (int i = 1; i < col + 1; i++) {
this.createBug(new Vector2f(startX + (i * eachBugSpaseWidth) - moveBackInHalf, startY - (a * eachBugHeight) + moveBackInHalf), “bugas” + l);
l++;
}
}
}
[/java]

so thats it, i don’t think it’s correct way to do all this but it’s working except this twisting thing, I will try to solve it your way

1 Like

it’s little bit silly problem i have but i’m curious how i can iterate your pool in correct way ?
And one more thing i want to make quad with specifick information
[java]
/*

  • To change this template, choose Tools | Templates
  • and open the template in the editor.
    */
    package mygame;

import com.jme3.math.Vector2f;
import tonegod.gui.framework.core.AnimElement;
import tonegod.gui.framework.core.QuadData;
import tonegod.gui.framework.core.util.PoolObjectFactory;

/**
*

  • @author Setas
    */
    public class BrickMaker implements PoolObjectFactory {

    private AnimElement el;
    private int index = 0;
    private String name;
    private String textureName;
    private float x;
    private float y;
    private float w;
    private float h;
    private boolean refreshed =false;

    public BrickMaker(AnimElement el) {
    this.el = el;
    }

    public void refreshData(String name, String textureName, float x, float y, float w, float h){
    this.name = name;
    this.textureName = textureName;
    this.h = h;
    this.w = w;
    this.x = x;
    this.y = y;
    refreshed=true;
    }

    @Override
    public Object newPoolObject() {
    if(!refreshed){
    throw new RuntimeException (“data has been not refreshed”);
    }
    QuadData q = el.addQuad(name, textureName, new Vector2f(x, y),new Vector2f(x / 2, y / 2));
    q.getTextureRegion().flip(false, true);
    q.getTextureRegion().flip(false, true);
    q.setDimensions(new Vector2f(w,h));
    index++;
    refreshed=false;
    return q;

    }
    }

[/java]

but its problem

[java]
brickMaker = new BrickMaker(bricksEl);
bricks = new Pool(brickMaker, ROWS * COLS);

    for (int i = 0; i &lt; COLS; i++) {
        for (int ii = 0; ii &lt; ROWS; ii++) {
            brickMaker.refreshData("Static_Brick_" + i + "/" + ii, texture.textureName, bricWidthInPx * i, brickHeightInPx * ii,
                    bricWidthInPx - marginXInPx, brickHeightInPx - marginYInPx);
            brickMaker.newPoolObject();      
        }
    }

[/java]

then i’m creating bricks (Pool object) it’s creating whole array and casting newPoolObject() but i need add object by myself with specific data, of course it’s possible update data but i don’t know how to iterate pool, because it doesn’t have iterator or function like hasNext()

ok I found how to make pool, by setting size in beginning 0 it’s okay, but still i need iterate somehow, for removing quads from element

I think i’m misunderstood meaningfor this pool

@SetasSan said: ok I found how to make pool, by setting size in beginning 0 it's okay, but still i need iterate somehow, for removing quads from element

I think i’m misunderstood meaningfor this pool

For this case, I would use the same method you used for creating the AnimElements and not use Pool. Then just use AnimElement.getQuads() to iterate over the bricks.

Pool works out well for objects that you need a bunch of but have no really need to track. A good example would be something like an explosion effect. So you preload a number of emitters and just request then as you need to display a new explosion, release the resource after the effect runs.

Using Pool in conjunction with AnimElement allows you to use a single mesh to do something like:

  • You build a Connect the Dots game
  • You have a collection of lines and circles in a single mesh using Pool to separate the two visually different quad types.
  • As the user draws over the dots, you request a circles to display over the dots they have hit and request lines to display between the dots and of course a line that connects to the last dot passed over and stretches to the mouse pointer/finger.

It doesn’t matter which circle/line you get when you request them, as long as it isn’t one that is currently in use.

1 Like