swift - Animate an SKSpriteNode with textures that have a size different from the original -


i want animate skspritenode using textures sktextureatlas, using skaction.animatewithtextures(textures,timeperframe,resize,restore). however, textures in atlas have size larger original texture (it's character moving). when action run, textures either compressed fit original size of sprite, or recentered when set resize false, changes position of character. want, though, textures anchored @ lower-left corner (or lower-right, depending on direction) position of character doesn't change apart part of texture.

i've tried changing anchor point of sprite prior running action, applies original texture well. also, guess changing size of original texture have impact on physics behaviour, want avoid.

does have suggestion how this?

thanks!

david

this work

  1. edit textures match size of largest sized texture.

just give smaller textures padding using alpha channel give transparent background.

e.g. notice how first texture has lots of negative space (from cartoonsmart.com)

enter image description here

  1. create physics body size in mind. e.g. can load texture without padding , size. position needed onto new , improved texture padding. after create sprite normal new resized textures can

    /// load texture template size let imagetexturesizetemplate = sktexture(imagenamed: texturewithoutpadding)  let bodysize = imagetexturesizetemplate.size()   /// position template texture physics body on texture used   let bodycenter = cgpointmake(0.5, 0.5)  // create physics body let body:skphysicsbody = skphysicsbody(rectangleofsize: bodysize, center: bodyceneter)      self.physicsbody = body 
  2. set resize: false when animate textures.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo