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

2014/11/30

getOneObjectAtOffset

Revan Revan

2014/11/30

#
Hello I am making a card game similar to hearthstone, very basic of course, and I ran across a problem when I try to determine if a player is dragging his card on top of another to attack it. if(player.myTurn() && player.cardOnTable(this) && Greenfoot.mouseDragEnded(this) && counter == 1){ //card owner's turn && the card is currently on his table && card has spent at least 1 turn on table Actor target = getOneObjectAtOffset(mouse.getX(), mouse.getY(), Actor.class); target is always null, I have tried it with offset coord but it stays null Actor target = getOneObjectAtOffset(xOffset, yOffset, Actor.class); any ideas how to get it working?
Revan Revan

2014/11/30

#
My Table is 600x400 with 1 pixel cells I have tried changing it into 6x4 with 10000 pixel cells: super(6, 4, 10000); so that each card would occupy exactly 1 cell but I end up with a much larger table
Revan Revan

2014/11/30

#
            xOffset = getX()-mouse.getX();            
            yOffset = getY()-mouse.getY();
            if(player.myTurn() && player.cardOnTable(this) && Greenfoot.mouseDragEnded(this) && counter == 1){ //card owner's turn && the card is currently on his table && card has spent at least 1 turn on table
                Actor target = getOneObjectAtOffset(xOffset, yOffset, Actor.class);
                if (target == null){
                    setLocation(50,50);
                } 
danpost danpost

2014/11/30

#
I think you may have created the offset value with the wrong sign. Try changing lines 1 and 2 to:
xOffset = mouse.getX()-getX();
yOffset = mouse.getY()-getY();
Revan Revan

2014/11/30

#
Omg! that did it, thank you so much!! This doesn't matter now, but I am curious, shouldn't those 2 worlds be the same size? super(600, 400, 1); super(6, 4, 10000);
danpost danpost

2014/11/30

#
Revan wrote...
shouldn't those 2 worlds be the same size? super(600, 400, 1); super(6, 4, 10000);
Actually, NO. 'super(600, 400, 1)' would be the same size as 'super(6, 4, 100)'. Cellsize is a 2-dimensional value; that is, the height and width of a single cell will be cellsize pixels long. So, using 'super(w, h, c)' the total size is '(w*c)*(h*c)'. The big difference between a world of 'super(600, 400, 1)' and 'super(6, 4, 100)' is that an actor can be in one of 240000 locations in the first and only in 24 locations in the latter.
You need to login to post a reply.