isul June 25th, 2018 hi, I want to make a simple physic game. Just drag and drop something. But i don't know to make function to drag a sceneObject and drop it to a position. When it is in the postion, something will happen like object locked or rotation.
var posisi = data.screenPosition;
var bintang = wade.getSceneObject('Lingkaran');
var gerak = wade.isMouseDown();
if (gerak){
bintang.moveTo(posisi.x, posisi.y,5000 )
}
var objekKotak = wade.getSceneObject('Kotak');
var posisiKotak = objekKotak.getPosition;
var posisiBintang = bintang.getPosition;
if (posisiBintang.x == posisiKotak.x && posisiBintang.y == posisiKotak.y){
bintang.setRotation(0.7);
}
The sceneObject can move but nothing happened when it's in target position.
Would you like help me. Thanks before
Gio June 26th, 2018 Hi
I think the problem there is that you need getPosition() with brackets (), as a function call.
However I wouldn't recommend doing it that way, there may be better alternatives.
First of all, if it is NOT a Physics Object, but just a regular Scene Object, you could do this in the object's onMouseDown function:
// store the object position when the mouse button is clicked
this.mouseDownPosition = this.getPosition();
Then listen for a global onMouseMove event and a global onMouseUp event. Not on the object, but globally for the app: this means that these events are fired every time you move and release the mouse, not just when you move and release the mouse on your object. So for example in app.js:
wade.app.onMouseMove = function(data)
{
// don't do anything if we are not dragging the object
if (!_.Lingkaran.mouseDownPosition)
{
return;
}
// get world-space position (in case you want to move the camera, zoom, etc)
var layerId = _.Lingkaran.getSprite().getLayerId();
var worldPos = wade.screenPositionToWorld(layerId, data.screenPosition);
// update position of your object
_.Lingkaran.setPosition(worldPos);
};
wade.app.onMouseUp = function(data)
{
// reset the mouse down position
_.Lingkaran.mouseDownPosition = null;
// check if Lingkaran overlaps Kotak
if (_.Lingkaran.getOverlappingObjects().indexOf(_.Kotak) != -1)
{
_.Lingkaran.setRotation(0.7);
}
};
If it is an actual PhysicsObject using the physics engine, then I would use mouse joints instead. Let me know if that's the case and I can help you with that.