TouchEvent3d examples

Software: Away3D 4.x

young_buddha, Newbie
Posted: 19 May 2014 11:20 AM   Total Posts: 2

hi

i am making a game for ios/android and need to get TouchEvents working for away3d objects. I am creating for instance a Cube with 6 faces (6 PlaneGeometry meshes), and setting up touchevent3d.Touch_BEGIN on each face.. but i cant seem to record the touches in the simulator (i havent tried on ios). The mouseevent3d works fine and register on each face of the cube.

Are there any examples of how to use TouchEvent3D (on mesh objects if possible)


What might I be missing ?

Am using away3d 4.1.6

regards
sid
-

   

John Brookes, Moderator
Posted: 19 May 2014 04:27 PM   Total Posts: 732   [ # 1 ]

No idea with the simulator as I dont use it.
But basic touch is…

Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
...
mesh.pickingCollider = PickingColliderType.AS3_BEST_HIT;
mesh.mouseEnabled = true;
mesh.addEventListener(TouchEvent3D.TOUCH_BEGIN, touchBegin);
mesh.addEventListener(TouchEvent3D.TOUCH_MOVE, touchMove);
mesh.addEventListener(TouchEvent3D.TOUCH_END, touchEnd);

Note if your using multiviews (sharedProxy) touch doesn’t work.

 

   

young_buddha, Newbie
Posted: 20 May 2014 12:37 PM   Total Posts: 2   [ # 2 ]

hey john

thanks for the reply.

Still not working for me though i have followed the above. It doesnt work in simulator (though MouseEvents3D work just fine), doesnt work in IOS. But on android i see that it is working but incorrectly.

I basically have a rubiks cube with 27 cubes and 6 plane faces each which have a touch event on them. On android the touch seems to register outside each cube face usually around top leftish. As a result it detect touch on a cube other than the one i touched.

I am attaching the files if its possible to check, else the relevant code is below. Else if someone can give working examples would be great.

public class MultiMaterialCube extends ObjectContainer3D
 {
  
private var iconArr = new Array('Atom','FireBall','FlashIcon','Music','SmileyIcon');

  protected var 
faceFront:Mesh;
  protected var 
faceBack:Mesh;
  protected var 
faceTop:Mesh;
  protected var 
faceBottom:Mesh;
  protected var 
faceLeft:Mesh;
  protected var 
faceRight:Mesh;
  private var 
faceNames:Array = ['faceFront','faceBack','faceTop','faceBottom','faceLeft','faceRight'];
  protected var 
cubeContainer:ObjectContainer3D = new ObjectContainer3D  ;
  protected var 
mergedMesh:Mesh;

  
import flash.ui.Multitouch;
  
import flash.ui.MultitouchInputMode;

  public function 
MultiMaterialCube(width:Number=100,height:Number=100,depth:Number=100,frontMat:MaterialBase=null,backMat:MaterialBase=null,topMat:MaterialBase=null,botMat:MaterialBase=null,leftMat:MaterialBase=null,rightMat:MaterialBase=null,mergeMeshes:Boolean=false):void
  {
   Multitouch
.inputMode MultitouchInputMode.TOUCH_POINT;
   
mouseEnabled true;
   
mouseChildren true;

   var 
textureArr = new Array  ;
   for (var 
06f++)
   
{
    
var ClassReference:Class = getDefinitionByName(iconArr[Math.floor(Math.random() * iconArr.length)]) as Class;
    var 
bd1:BitmapData = new BitmapData(64,64,false,0xFFFFFFFF);
    
bd1.draw(new ClassReference  );
    var 
tm:TextureMaterial = new TextureMaterial(Cast.bitmapTexture(bd1));
    
textureArr.push(tm);
   
}

   
var defaultMaterial:ColorMaterial = new ColorMaterial(0x666666,.5);
   var 
geom:PlaneGeometry = new PlaneGeometry(64,64,64,1); 

// --------------xx
 
faceFr Mesh(geom,textureArr[0] || defaultMaterial);   
   
faceFront.= -32;
   
faceBack = new Mesh(geom,textureArr[1] || defaultMaterial);    
   
faceBack.32;
   
faceTop = new Mesh(geom,textureArr[2] || defaultMaterial);    
   
faceTop.32;
   
faceBottom = new Mesh(geom,textureArr[3] || defaultMaterial);    
   
faceBottom.= -32;
   
faceLeft = new Mesh(geom,textureArr[4] || defaultMaterial);    
   
faceLeft.= -32;
   
faceRight = new Mesh(geom,textureArr[5] || defaultMaterial);    
   
faceRight.32;

   var 
faceStr:String;
   
faceBack.mouseEnabled faceFront.mouseEnabled faceTop.mouseEnabled faceBottom.mouseEnabled faceLeft.mouseEnabled faceRight.mouseEnabled true;
   
this.mouseEnabled this.mouseChildren true;
   for 
each (faceStr in faceNames)
   
{

    this
.addChild(this[faceStr]);
    
this[faceStr].mouseEnabled true;


    
this[faceStr].pickingCollider PickingColliderType.AS3_FIRST_ENCOUNTERED;
    
//PickingColliderType.AS3_FIRST_ENCOUNTERED;;
    //PickingColliderType.PB_BEST_HIT;
    //this[faceStr].addEventListener(MouseEvent3D.MOUSE_DOWN, meshMouseDown);
    //this[faceStr].addEventListener(MouseEvent3D.MOUSE_UP, meshMouseDown);
    
this[faceStr].addEventListener(TouchEvent3D.TOUCH_BEGIN,meshMouseDown);
   
}
  }
  
//this[faceStr].addEventListener(TouchEvent3D.TOUCH_END, meshMouseDown);
 
};
};

public function 
meshMouseDown(e:Event)
{
 trace
("meshMouseDown");
 var 
ClassReference:Class = getDefinitionByName(iconArr[Math.floor(Math.random() * iconArr.length)]) as Class;
 var 
bd1:BitmapData = new BitmapData(64,64,false,0xFFFFFFFF);
 
bd1.draw(new ClassReference  );
 var 
tm:TextureMaterial = new TextureMaterial(Cast.bitmapTexture(bd1));

 
e.target.material tm;


regards
sid

 

 

File Attachments
rubiknew.rar  (File Size: 1251KB - Downloads: 0)
   

John Brookes, Moderator
Posted: 21 May 2014 05:04 PM   Total Posts: 732   [ # 3 ]

Here’s a simple test that traces, so debugging needed.
https://gist.github.com/JohnBrookes/df44633d811ced515361

That works on android and on my touch screen.
I don’t have any apple kit to hand to test, but should still work.

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X