Jump to content

My sprite just won't stay still


RunFish
 Share

Recommended Posts

Hello. I've been using Phaser now for the last few months and I love it, but I've run into a bit of an issue with texture packer and atlas'. I know its important to look before you ask, but because I'm not sure how I would search my issue I feel I have to post about it.

 

Here it is. I have a sprite sheet I've made with texture packer and an atlas. It loads up just fine in my game but when I call a frame that is larger than my 'standing' sprite the sprite seems to scoot to the left. Now I understand that that the reason for this is the area takes the size of the largest sprite in the sheet, so I tried making sure that all the sprites had the same dimensions, but I'm still having the issue. I've set my anchor point to the center of the sprite already as well.

 

Any suggestions or tips would be great. Thank you

Link to comment
Share on other sites

Is there an example uploaded anywhere we can see?

 

Sure. I'm using a place holder sprite right now, but I have the same issue with my other sprites as well. Here is a link to it.

Simple controls. Move with arrow keys. Space bar to "shoot". You will see when he does the "shoot" he moves back.

 

http://billrogers.com/graboid/Dredd/

 

I'm sure this is an easy fix. I'm just kind of at a lose of what it could be. Thank you so much.

Link to comment
Share on other sites

I'm fairly new to Phaser, but a cursory look at the behavior and your player sheet, it looks to me like the frames are aligning to the right, which feels a little unusual given that top left is 0,0.  If there's nothing you can do about that, is there a way you can make your standing/walking sprite the same width as your "shooting" sprite?

Link to comment
Share on other sites

player.png

 

huggz is totally right..  this is a simple problem with the anchor..  your sprites are not in the same width..  it is not right aligned.. it has the anchor at 0.5  that's the default for every physics enabled sprite and it's good.. that way you can mirror the sprite along the y axis and it will not move..  in your case it would be better to set the anchor back to 0 

mysprite.anchor.setTo(0,0.5);

should do it..  to be exactly sure i would need a jsfiddle to demonstrate :)

Link to comment
Share on other sites

player.png

 

huggz is totally right..  this is a simple problem with the anchor..  your sprites are not in the same width..  it is not right aligned.. it has the anchor at 0.5  that's the default for every physics enabled sprite and it's good.. that way you can mirror the sprite along the y axis and it will not move..  in your case it would be better to set the anchor back to 0 

mysprite.anchor.setTo(0,0.5);

should do it..  to be exactly sure i would need a jsfiddle to demonstrate :)

 

Perfect! Thank you! That does just what I wanted it to do.

 

But a new issue has come up. Pressing left allowed the player to shoot left. After the anchor point change when I pressed left its a big flip the other direction. I know the fix for this would be like you said, making sure that the sprites are the same width and right aligned. My question is on how to do that. Do I simply make sure that each png is the same size and that his body is in the same place for each one? Because I thought I had done that, but still had the same issue.

 

Thanks again btw. A lot of great info. And as a side note the phaser community is great from everything I've seen here.

 

UPDATE:

 

My quick fix on this was just having his anchor point change when he is shoot left. It works and looks just fine. But I cant help but feel that this is kind of a bulky fix.

Link to comment
Share on other sites

this is a bulky fix but if it works why not.. normally you would make sure that every frame in the spritesheet or every image of the same item in your atlas is the exact same size and that the rotation point is in the center of the image AND the character - that means in the middle of the chest in your case... arms or weapons not included because they can/should flip whereas the characterbody should rotate around its center (because thats where the anchor will be when you activate physics...)

Link to comment
Share on other sites

this is a bulky fix but if it works why not.. normally you would make sure that every frame in the spritesheet or every image of the same item in your atlas is the exact same size and that the rotation point is in the center of the image AND the character - that means in the middle of the chest in your case... arms or weapons not included because they can/should flip whereas the characterbody should rotate around its center (because thats where the anchor will be when you activate physics...)

 

Wonderful. After going back and making the changes suggested about centering everything is working smooth (and no more of that bulk fix). Thanks again all of you.

Link to comment
Share on other sites

Another possibility could be to make the arms independent of the body, and change them out for walking/shooting.  Doing that you won't be copying the body each time you need him to perform a new type of action (thinking future).  In the end, what you would have for a sprite sheet would be an arm-less man in the 3 different positions and 2 different types of arms, one extended and one down by his side.  Depending on what direction he's walking you can then swap the visibility on the appropriate arms.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...