On Sun, 2012-05-06 at 10:50 -0700, Jason 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.
> 
> However, the Bezier Path seems to think 0, 0 is where ever the Missile
> has spawned, not absolute position on the screen.

That's because 0,0 is the relative position of the Missile to the Mother
ship sprite. You need to take a look at the Node's point_to_world()
function [1], that can calculate the position in the actual world,
taking into account the rotation and position of the sprite you're
spawning the missile from. Like so:

# Within the Mother ship code:
missile = cocos.sprite.Sprite('missile.png')
# Will put the missile in the middle of the Mother ship:
missile.position = self.point_to_world((0, 0))
# Now add the missile to the background layer, not to the unit's sprite.
# Depends on your code, but I do:
self.game.background.add(missile, z=1)
# (self.game is a reference to the game scene, background is a layer)

[1] http://cocos2d.org/doc/api/cocos.cocosnode.CocosNode-class.html

Regards,

Ivo

-- 
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