I think this nailed it on the head. I did some relative coordinate
correction and it seems to be working correctly. HOWEVER. the Missile
is NOT a child of the Capitol Ship  (CS) , it's a child of the same
layer that the Capitol Ship belongs to.

I passed in the parent layer to the CS, (thinking I could only add to
the layers, not to other Sprites), then used that layer to add the
missile to it. So I SHOULDN'T have to correct for relative
positioning, correct?

class CapitolShip(Sprite, Seeking):
    def __init__(self, center_x, center_y, radius, target,
parentLayer):
        super( CapitolShip, self ).__init__('capitolShip.png')
        self.position = (center_x, center_y)
        self.cshape = cm.CircleShape(eu.Vector2(center_x, center_y),
radius)

        self.target = target

        self.randomXRangeFromMS = random.randrange(-100, 100)
        self.randomYRangeFromMS = random.randrange(100, 200)
        self.schedule(self.seekAndDestroy)

        self.angle = 0
        self.schedule_interval(self.turnTowardsTarget,.3)

        self.schedule_interval(self.fire,2)
        self.parentLayer = parentLayer
        self.hasFired = False


    def fire(self, dt):
        if(not self.hasFired):
            self.parentLayer.add(Missle(self.position, 10,
self.target),9)
            self.hasFired=True

On May 6, 11:49 am, claudio canepa <[email protected]> wrote:
> On Sun, May 6, 2012 at 2:50 PM, Jason <[email protected]> wrote:
> > I'm writing a little game in cocos2d, trying to use the Bezier Action
> > and Bezier path to make a Missile fired from a Capitol Ship the
> > missile fly at the Mother Ship in a cool, loopy kinda way.
>
> > My problem seems to be what I think is a position isn't what Bezier
> > thinks is a position. I give it the Mothership position, and the
> > Missile starting position (wherever its Capitol Ship is at the time) ,
> > and tell the Missile to make it's way to the Mothership.
>
> If all the entities are direct childs of a Gamelayer or some other node,
> then a Bezier from missile.position (at spawn time) to mothership.position
> (at spawn time) should provide a travel path from missile.position to
> mothership.position.
>
> If thats not true (by example, if missile is child to capitol_ship) then
> you have to do some coordinate changes: all the points in the bezier must
> be in the same coordinate space.
> There it can be handy the CocosNodes methods  point_to_world,
> point_to_local
>
>
>
>
>
>
>
>
>
> > However, the Bezier Path seems to think 0, 0 is where ever the Missile
> >  has spawned, not absolute position on the screen.
> > How can I get the Bezier Path to take absolute position? Here's the
> > bit of code from the Missile class
>
> >    def hitTarget(self):
> >        tx, ty = self.target.position
> >        mx, my = self.position
> > # this bit of code makes the missile do weird things
> > #        path = BezPath( (mx, my), #first point
> > #                  (tx, ty), #end point
> > #                  (mx-10, my-20), #second point
> > #                  (mx-20, my-30)) #third
>
> > #this bit of code makes the Missile spawn correctly, but will I have
> > to calculate the relative position
> > #of the mother ship to make it hit?
> >        path = BezPath( (0, 0), #first point
> >                  (0, 0), #end point
> >                  (-10, -20), #second point
> >                  (-20, -30)) #third
>
> >        self.do(BezAction(path, 2 ))
>
> > --
>
> You need to clarify the parent - child relationship to asses the correctnes
> of your code
>
> claudio
>
> --

-- 
You received this message because you are subscribed to the Google Groups 
"cocos2d discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cocos-discuss?hl=en.

Reply via email to