At 7:50 PM -0500 2/17/05, Heinz J. Gattringer wrote:
I tried following code to select the object the user has clicked on
in the Rb3DSpace MouseUp event (MouseDown simply returns true):
Dim which as Object3D
dim id as integer
which=me.FindObject(x,y)
if which=nil then return
for id=0 to NumMyObjects // this property stores the number of
user-controlable objects in the game
if MyObjectsArray(id)=which then exit
next
if id=NumShips+1 then Return
and so on // the rest of the code handles the change over to the
selected object , which i hoped to be MyObjectsArray(id).
If your goal is just to pass the action off to the object, you could simply do:
which = me.FindObject(x,y)
if which IsA MyObjects then
MyObjects(which).HandleMouseUp x,y
end if
or whatever you want to call the "HandleMouseUp" function in your
MyObjects class.
And in general, you should write your code in such a way that this
*is* all you have to do -- the index of an object in some global
array really shouldn't matter.
But oops, remember that FindObject will never return a Group3D; it
will only return an individual object (which may be inside a group).
Then you may have to search for the parent in some way.
The thing is, the 3D geometry of all the Group3D objects stored in
MyObjectsArray is the same (they are cloned). Because of this I
suspect the comparison "if MyObjectsArray(id)=which" resolves to
true for all the objects in the array, and thus I was always ending
up with the index id=0, which missled me to believe all the indexes
of the Group3D objects were 0.
Hmm. I'd like to see the code where you set that up. I don't
believe you can clone an entire group, but you can clone an
individual (non-group) Object3D. And indeed you should, where you're
using the same geometry in multiple places. But in that case, each
one is a unique object, and your MyObjectsArray(id)=which test would
be true for only one of them.
But again, I'm suspecting that you really don't need to care what the
indexes are anyway -- you should just see if the thing clicked is one
of your custom object types, typecast it accordingly, and invoke a
method on it.
Yes, confirmed that too, so I would need to do a comparison to the
gunturret-coordinates too, but I was hoping to avoid this. I don't
like to many if, if ,if lines in my code.
Right, that's an indicator that there's probably a better way.
Best,
- Joe
--
REAL World 2005 - The REALbasic User Conference
March 23-25, 2005, Austin, Texas
<http://www.realsoftware.com/realworld>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
|