I'm trying to have a sprite swap places with another spri开发者_Python百科te. So far I think I can somehow use the slope between the two sprites' original location to move them, but I'm lost as to how to increment their position along that slope.
You'll need to create a vector between the two sprites, normalize it, multiply that normalized vector by how much you want the sprite to move per frame, then add that vector into the sprite you are moving's location. You didn't specify a language, so here is a little pseudo code:
var p1 = sprite1.location
var p2 = sprite2.location
var vec = p2.subtract(p1)
vec.normalize()
vec.multiply(6) // I want it to advance 6 units per move
while (sprite1.location != sprite2.location) // best to check with some epsilon
  sprite1.location = sprite1.location.add(vec)
end
                                        
                                        
                                        
                                        
                                        
                                        
                                        
                                        
 加载中,请稍侯......
      
精彩评论