Drag and Drop
cap

Hi All,

 

Sry for the naive question / bad coding: I wanted to drag all of my objects in x,z using wade.iso. Since I want to disable the drag/panning of the world tiles during object selection, I just thought of adding a flag when the pertinent object is MouseDown;

    //( from this.init)    objects.onMouseDown = function()    {        // Flag the object to avoid world camera moving,  only object translation during drag. Remove object from position.        SELECT = 1        objects.setVisible(false);        return true    }    wade.addEventListener(objects, 'onMouseDown');      this.onMouseUp = function(eventData)    {        // Return the world manipulation flag, show object in new position after dragging.        SELECT = 0        var worldCoords = wade.screenPositionToWorld(wade.iso.getTerrainLayerId(), eventData.screenPosition);        var cellCoords = wade.iso.getCellCoordinates(worldCoords.x, worldCoords.y);        objects.setVisible(true);        wade.iso.moveObjectToCell(objects, cellCoords.x , cellCoords.z);        };

This works, but only once. The second time I click the object in the new position wade_1.1.1.js complains "TypeError: b is undefined" and does not drag the object from its new position (the rest of the script runs business as usual).

 

This is the third attempt in a series of failed scripts for dragging, so I will appreciate it if you could point me in the right direction, even if the matter and hand seems trivial :). Also do you mind explaining how wade.iso.getObjectsInCell(cell.x, cell.z) works? Sometimes is seems it returns more than one Object, how to choose between then?

 

thanks!

 

CA

Comments 1 to 15 (17 total)
Gio

Hi

 

I have tried your code (by adding it to the isometric example game, and applying it to the witch character). The good news is: it works perfectly :) The bad news is, there must be something else that is going wrong with your code - but it isn't in the bit of code that you posted, that part is absolutely fine. Are you able to share more of your code so I can have a closer look and help you find the problem?

 

wade.iso.getObjectsInCell returns an array of objects - it's possible that there is more than one object in a single cell. However it is not possible for more than one object with collisions to be in the same cell. Anyway, that function always returns an array of objects. If you need to know what each object is, I'd suggest giving your objects some names (using SceneObject.setName() and SceneObject.getName()). Alternatively, you could just set a flag on the objects that you care about, such as: object.isAMonster = true, and then check that flag, if that makes sense.

 

I would also recommend using the latest version of WADE (1.1.2).

cap

Thanks Gio! Could you just attach the change you made in iso.js? I just tried adding the piece of code  to it  myself without success.

Gio

Ok, so this is what I've done in the isometric sample game. Everything is relative to witch.owner because in that game, the variable witch points to the IsoCharacter Behavior, not the SceneObject. So the SceneObject is witch.owner.

 

Right at the top of App:

var select = 0;

At the bottom of the init function:

witch.owner.onMouseDown = function()        
{
    select = 1;
    witch.owner.setVisible(false);
    return true;
};        
wade.addEventListener(witch.owner, 'onMouseDown');        
this.onMouseUp = function(eventData)        
{            
    select = 0;            
    var worldCoords = wade.screenPositionToWorld(wade.iso.getTerrainLayerId(), eventData.screenPosition);            
    var cellCoords = wade.iso.getCellCoordinates(worldCoords.x, worldCoords.y);            
    witch.owner.setVisible(true);            
    wade.iso.moveObjectToCell(witch.owner, cellCoords.x , cellCoords.z);        
};

And finally, at  the top of the App's onMouseMove function we don't want to do anything if we're dragging the object, so:

if (select)  
{ 
    return; 
}

Let me know how that goes... is there any reason why you hide and then show the object again?

cap

Hi. Thanks. With the witch isocharacter works like a charm. I was trying to apply this to *all* my iso objects (e.g. house, plants, etc). Upon defining the house as house = wade.iso.create... and replacing "witch.owner" with "house" I am able to reproduce the same error; it works once and then I get the message "TypeError: b is undefined". For the time being, I will change all the objects to isocharacters, see if that works.

 

PS. I wanted to hide the object to have custom animations while I am dragging the objects from one place to another.

cap

Fixed: the objectData should not have a gridSize defined. Thanks again!!

cap

Hi, sry for the massive posting of naive issues. I have still not figured out how to use the array that "objects = wade.iso.getObjectsInCell(cell.x, cell.z)" returns. I want to choose the object at the top of the array, and have tried getting its name via "objects[0].getName()" but this is of course wrong. Do you maybe have an example? Thanks so much.

Gio

OK, first of all you should be able to move any iso objects around - you shouldn't need to do anything special with the gridSize or gridMap of the object. Thanks for reporting the problem, it's most definitely a bug.

 

I managed to replicate the problem, and have found not one, but two (!) bugs in the code that updates the positions of iso objects, when the objects are larger than one cell. We can push out a new version of wade.iso to fix these bugs, and should be able to do this in the next couple of days (there is a new release of WADE coming up too, so we should be able to release this at the same time):

 

BugFix (B07): Moving objects larger than one cell on the map can cause inconsistencies in the map data

BugFix (B08): It isn't possible to move an object with a collision map larger than one cell into target cells that were already occupied by the same object

 

In what way does getName() not work? Are you setting a name for the objects? You can do this in the SceneObject's constructor, using SceneObject.setName(), or if you are creating an iso object via wade.iso.createObject(), you can add a name field to its instance data.

 

So for example:

house = wade.iso.createObject(houseData, {x:14, z: 15}, {name: "home sweet home"});
var objectsInCell = wade.iso.getObjectsInCell(14, 15);
​​​​​​​console.log(objectsInCell[0].getName()); // prints "home sweet home"

 

Gio

WADE ISO 1.1.1 released - those problems should have been fixed :)

echar

Link to isometric sample game Witch ?

Gio

Hi

As you can tell from the date of the original post, it's quite and old one. While we try to maintain backwards compatibility as much as possible, the isometric plug-in had a good overhaul with version 3 and I think some of that code will no longer work now.

I have put a zip with the witch demo here anyway, I hope it's somewhat useful even if not current.

echar

 

You can initiate many values in statement 1 (separated by comma):

for (var b = "n s w e ne nw se sw".split(" "), c = 0; c < b.length; c++) wade.loadImage("images/witch_Idle_iso_" + b[c] + ".png"), wade.loadImage("images/witch_Walk_iso_" + b[c] + ".png")

Very nice code.

echar
  • Different rotation, the same thumbnails. Why?
Gio

Looking at your comment above, it just occurred to me that I may have uploaded a file with the wrong source in it, i.e. just the minified one.

I have now replace that file with a more readable source (just download it again).

Regarding the rotations: I think you've just found a bug in the editor. Thanks for letting us know, it will be fixed in 3.2.

echar

I have isometric object with  custom property isFlower:true, but object on the scene is without this property. Why?

 

Gio

In the tile editor, you are setting a property for the sprite, not the scene object.

There is currently no way to set object properties in the tile template (from the editor, you could do this in code). The only way, at present, is to create instances of your object, then set properties on each instance. Or add a custom behavior that copies custom properties from the sprite to the object - I wouldn't recommend it though, too much of a hack.

But it sounds like it would be very useful to have this ability in the tile editor, I'll try to add it in the next version.

Post a reply
Add Attachment
Submit Reply
Login to Reply