Dragging the bars vertically it's possible to jump one right past the
other fairly easily. Does anyone know of an approach that might help
this sort of tunnelling behavior?
I tried changing the multisample property all the way up to 1000 and
it only made the movement a bit choppy, but didn't seem to affect the
prevalence of tunnelling.
Alec - I noticed that changing the px and py properties directly do
not change the underlying sprite x,y properties. Shouldn't these
change when px or py are changed?
Thanks,
-Ans
This is the source, notice that I have a different class called
DrawingContainer in place of Sprite (for the sprite property in
AbstractItem) so that I can access the underlying particle through
mouse events:
------------------------------------------------------------
Main.as
------------------------------------------------------------
package
{
import org.cove.ape.*;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.Sprite;
public class Main extends Sprite
{
private var dragging : RectangleParticle;
public function Main()
{
stage.frameRate = 60;
addEventListener(Event.ENTER_FRAME, run);
APEngine.init(1/4);
APEngine.container = this;
APEngine.addMasslessForce(new Vector(0,0));
var defaultGroup:Group = new Group();
defaultGroup.collideInternal = true;
var rp:RectangleParticle = new RectangleParticle(250,300,300,50,0,false);
defaultGroup.addParticle(rp);
var rp2:RectangleParticle = new RectangleParticle(250,50,300,50,0,false);
defaultGroup.addParticle(rp2);
rp.sprite.addEventListener( MouseEvent.ROLL_OVER , rollOverHandler );
rp.sprite.addEventListener( MouseEvent.ROLL_OUT , rollOutHandler );
rp.sprite.addEventListener( MouseEvent.MOUSE_DOWN , mouseDownHandler );
rp.sprite.addEventListener( MouseEvent.MOUSE_UP , mouseUpHandler );
rp.multisample = 10;
rp2.sprite.addEventListener( MouseEvent.ROLL_OVER , rollOverHandler );
rp2.sprite.addEventListener( MouseEvent.ROLL_OUT , rollOutHandler );
rp2.sprite.addEventListener( MouseEvent.MOUSE_DOWN , mouseDownHandler );
rp2.sprite.addEventListener( MouseEvent.MOUSE_UP , mouseUpHandler );
rp2.multisample = 10;
APEngine.addGroup(defaultGroup);
}
private function run(evt:Event):void
{
APEngine.step();
APEngine.paint();
}
private function mouseMoveHandler( event : MouseEvent ) : void
{
dragging.px = mouseX;
dragging.py = mouseY;
dragging.sprite.x = mouseX;
dragging.sprite.y = mouseY;
}
private function mouseDownHandler( event : MouseEvent ) : void
{
//var p : RectangleParticle = event.target as RectangleParticle;
dragging = DrawingContainer(event.target).owner as RectangleParticle;
stage.addEventListener( MouseEvent.MOUSE_MOVE , mouseMoveHandler );
}
private function mouseUpHandler( event : MouseEvent ) : void
{
dragging = null;
stage.removeEventListener( MouseEvent.MOUSE_MOVE , mouseMoveHandler );
}
private function rollOverHandler( event : Event ) : void
{
event.target.alpha = .5;
}
private function rollOutHandler( event : Event ) : void
{
event.target.alpha = 1;
}
}
}
------------------------------------------------------------
DrawingContainer.as
------------------------------------------------------------
package org.cove.ape
{
import flash.display.Sprite;
public class DrawingContainer extends Sprite
{
public var owner : AbstractItem;
public function DrawingContainer( owner : AbstractItem )
{
super();
this.owner = owner;
}
}
}
------------------------------------------------------------
AbstractItem.as - line 174
------------------------------------------------------------
changed from
_sprite = new Sprite();
to
_sprite = new DrawingContainer(this);
I'm about to try something like this myself.
Paul
-Ans
I've usually adjusted the stiffness up close to 'rigid' to get the
feel I want, but still I'd guess that it helps to not have a colliding
particle (the one you grab and attach to the mouse) moved so
authoritatively with the mouse location.
But with the speed that Alec is updating APE, he may have already
added a "mouseGrabber" class. :-)
As Paul mentioned, the way to go is to use a 'mouse spring'. The
problem with setting the position directly is that it takes the
particles out of the physical environment of the engine. I suspect
this is why you see mouse springs a lot in the other engines. Also,
the issue with multisampling is that it takes into account the
previous and current position of a particle, and setting px and py
automatically sets prev and curr to the same value. It's something id
like to revisit at some point -- maybe when I'm doing the built in
mouse events, since it would be nice to be able to just drag something
around without a spring and have it work correctly.
On a slightly different subject, I really think you'd be better off
using a class for your dragable rectangle. You'd end up with cleaner
code and you wouldn't have to alter the engine either. Have a look at
these two classes, the main one and the separate class for the
DragRect.
----------------
package {
import org.cove.ape.*;
import flash.events.Event;
import flash.display.Sprite;
[SWF(width="800", height="600", backgroundColor="#336699")]
public class DragTest extends Sprite {
public function DragTest() {
stage.frameRate = 60;
addEventListener(Event.ENTER_FRAME, run);
APEngine.init(1/4);
APEngine.container = this;
var defaultGroup:Group = new Group(true);;
var drA:DragRect = new DragRect(250,300,300,50);
defaultGroup.addParticle(drA);
var drB:DragRect = new DragRect(250,50,300,50);
defaultGroup.addParticle(drB);
APEngine.addGroup(defaultGroup);
}
private function run(evt:Event):void {
APEngine.step();
APEngine.paint();
}
}
}
----------------
package {
import flash.events.MouseEvent;
import org.cove.ape.RectangleParticle;
public class DragRect extends RectangleParticle {
public function DragRect(x:Number, y:Number, width:Number,
height:Number) {
super(x, y, width, height, 0);
sprite.addEventListener(MouseEvent.MOUSE_UP, mouseUp);
sprite.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
sprite.addEventListener(MouseEvent.ROLL_OUT, rollOut);
sprite.addEventListener(MouseEvent.ROLL_OVER, rollOver);
}
private function mouseUp (mevt:MouseEvent):void {
sprite.stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMove);
}
private function mouseDown (mevt:MouseEvent):void {
sprite.stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMove);
}
private function rollOut (mevt:MouseEvent):void {
mevt.target.alpha = 1;
}
private function rollOver (mevt:MouseEvent):void {
mevt.target.alpha = 0.5;
}
private function mouseMove (mevt:MouseEvent):void {
px = mevt.stageX;
py = mevt.stageY;
}
}
}
---------
DragRect is now responsible for its own events, you dont have to add
them each time. Also, you gain the scope of the events being within
the class, and because of that you don't have to do any stuff with
'owner'.
Thanks,
Alec
I would like to have the effect of dragging a particle around
directly, as opposed to having it look like the particle is being
dragged by a rubber band. I imagine I could set the "mouse spring" to
have no elasticity, but would I still run into the problem of
tunnelling do you think since a particle dragging at the speed of the
cursor will be moving faster than one that is being tugged around by
an elastic spring?
Alec, sorry if you've mentioned this before, but when do you hope to
have the mouse events included?
-Ans
As far as the mouse events, I'm not sure. I'm working on collision
events and forces for the 0.5 release, and after that angular
constraints. Mouse events might show up around 0.7. Until then youll
have to do it by using the objects sprite (as you've been doing).
-Alec
On Jun 26, 3:29 pm, "anselm bradford" <anselmbradf...@gmail.com>
wrote:
> Thanks for the advice Paul and Alec,
>
> I would like to have the effect of dragging a particle around
> directly, as opposed to having it look like the particle is being
> dragged by a rubber band. I imagine I could set the "mouse spring" to
> have no elasticity, but would I still run into the problem of
> tunnelling do you think since a particle dragging at the speed of the
> cursor will be moving faster than one that is being tugged around by
> an elastic spring?
>
> Alec, sorry if you've mentioned this before, but when do you hope to
> have the mouse events included?
>
> -Ans
>
Thanks,
-Ans
var sc:SpringConstraint = new SpringConstraint(p1,p2,1);
sc.restLength = 0.1;
HTH,
Alec
On Jun 26, 7:46 pm, "anselm bradford" <anselmbradf...@gmail.com>
wrote:
> Huh, how do I set the length of a spring constant to be very short? I
> created a non-collidable particle for the mouse and attached it to one
> of the rectangles, but how do I make it shorter than the default that
> appears when stiffness is set to 1?
>
> Thanks,
> -Ans
>