Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / SetSpriteFlip() Problem

Author
Message
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 16th Jan 2016 20:43
Hi.

I busy make a fighting game and need flip animations. but after do this seem some position values can be changed and this problem make exists problem at some actions. I don't want create flip spritesheet instead use SetSpriteFlip() Function because my sprites number are much.

I think this problem is relate to free space in my spritesheet, because my sprites are power of two.



Anyone know how can fix it?


Thanks.
haliop_New
User Banned
Posted: 17th Jan 2016 04:07
hi man
it did took my sometime to fix your image...
but other then that there is no problem..

zip attached, fixed image and project file with working code \
2 modes, one with play animation and the other by playing animation using SetSpriteFrame
SetSpriteFlip works flawless

Attachments

Login to view attachments
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 17th Jan 2016 09:09
You have to make sure that the center of your character is in the center of the image. If the character for example is too far back in the image it will look like he jumps forward when the sprite is flipped.
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 17th Jan 2016 11:03
@haliop_New

Quote: "
hi man
it did took my sometime to fix your image...
but other then that there is no problem..

zip attached, fixed image and project file with working code \
2 modes, one with play animation and the other by playing animation using SetSpriteFrame
SetSpriteFlip works flawless
"


Thanks , it's great work. Tonight I check one thing about my sprites and if there is any problem I ask again here.

@Digital Awakening

Thanks, Yes you Right.

Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 17th Jan 2016 19:08
how can make power of two spritesheet? I used some tool for do this but sometimes I can't make power of two spritesheet for some sprites. for example I have 7 single sprites with (183 x 204) size . now how can make power of two without free space? (Like sprite in haliop_New project in second post) ?

Thanks.
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 17th Jan 2016 19:44
1) Create a power of 2 image.
2) Paste in your sprites.

You can do this with your favorite art package, or with a app designed for making sprite sheets, or programmatically. For example, you can create your Power Of 2 image using a function like this:

Usage: MyNewImage = createblankimage(1024,1024)



Then you can paste you pre-loaded images into this new image using something like:



Make sure your x/y offsets place the sprite images so they fit in the middle of a power of 2 box (in your example above, you could paste your first images with a x offset of 36, and y of 26 so it appears in the middle of a 256x256 square within your new atlas.).

V2 T1 (Mostly)
Phone Tap!
Uzmadesign
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 19th Jan 2016 07:29
Thanks CJB for your code.
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 21st Jan 2016 17:35
seem SetSpriteFlip() good not work because I set my sprites to center of spritesheet and work very well before Flip. but after Flip, my sprites have older problem.
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 21st Jan 2016 19:40
I use art package to create sprite sheets, just set a grid and paste in! Simple
The Amiga and Amos were great!
My website LEAP - Download Paint Pot here!
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 21st Jan 2016 21:06
Quote: "I use art package to create sprite sheets, just set a grid and paste in! Simple "


I used several tools even Photoshop and created my custom grid a paste my sprites in it but the problem still exists.

in this project I need use Flip Sprites but I was very annoyed.

this is my PSD fIle , please tell me where is the problem?



Thanks.

Attachments

Login to view attachments
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 22nd Jan 2016 10:03
your images are not in the centre of each sub-image. They need to be exactly in the centre of the sub-image so they don't jump from left to right when flipping the sprite. Haliop_New has already given you an example of what you need to do.
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 22nd Jan 2016 12:30 Edited at: 22nd Jan 2016 17:09
This file is an example, I test several ways. I think your mean is like below file. if your answer is yes, it won't work correctly.

Attachments

Login to view attachments
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 23rd Jan 2016 16:11 Edited at: 23rd Jan 2016 16:13
I set my images to center of each sub-image, but the problem also exists.

my images are to center of each blue lines in Photoshop.

Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 7th Feb 2016 18:51
I tested haliop_New Example and see it can flip any sprite after press Enter key. while my code is seem right but don't work correctly, so I wrote an example code for show it here and find problem. I attached my project and thanks for someone who can help me.

Attachments

Login to view attachments
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 7th Feb 2016 20:18
You need to keep your hero's center into the center of the image and not move him around like you do in the above image.
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 8th Feb 2016 03:14
Quote: "You need to keep your hero's center into the center of the image and not move him around like you do in the above image."


Really I don't understand what is your mean about "You need to keep your hero's center into the center of the image". already I attached a PSD file but anyone don't tell me it's correct or not. if possible please show me how should move my hero's.

Thanks.

CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 8th Feb 2016 08:50
Imagine the flip command works like a mirror down the very centre of the sprite. If your character is off to one side of the centre line, then you will notice it jump from side to side when you flip the image. Your character (the little person) MUST be exactly in the centre if you don't want it to jump about when flipping. In your example above, the two stickmen in the bottom two images are very obviously not in the centre of their respective box. In fact, the top three aren't quite in the centre either, but they are closer.
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 8th Feb 2016 12:53
Quote: "Imagine the flip command works like a mirror down the very centre of the sprite. If your character is off to one side of the centre line, then you will notice it jump from side to side when you flip the image. Your character (the little person) MUST be exactly in the centre if you don't want it to jump about when flipping. In your example above, the two stickmen in the bottom two images are very obviously not in the centre of their respective box. In fact, the top three aren't quite in the centre either, but they are closer."


already I test all way even set my sprites to center but really it don't work. I don't think this problem is relate to center of image because I test it this two stickman Images in haliop_New Example Project but it work very well.
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 8th Feb 2016 13:20
As the others are saying you need to put the sprite in the centre of the boxes. You need to use something like Photoshop or Gimp and reposition the images to all be in the centre of their boxes and that doesn't mean the image with the fire to be in the centre but just the man. So his left and right sides are exactly equal on each side.
Example:
The bottom 2 images need to be far more over to the right so the fire/light will be on the edge of it's box.

Can't explain it more than that other than loading up Photoshop and doing it for you which I am sure you can do.

You mention you have tried this?
Can you upload your modified image so we can see both images to see if they are centred.

Cheers.
The Amiga and Amos were great!
My website LEAP - Download Paint Pot here!
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 8th Feb 2016 13:52
Your animations are different widths, yet you are placing them with setspriteposition rather than setspritepositionbyoffset. If you want to flip the sprites, you'll need to have your character in the centre of each frame of the sprite, AND you'll need to use setspritepositionbyoffset to take into account the difference in width. If your animations were the same width, then you wouldn't need to necessarily use byoffset, as the sprite width would match up for the different anitmations, but your character will still need to be in the middle of the frame.

Quote: "if possible please show me how should move my hero's."

Do some experimenting! It only takes a few minutes of trial and error to figure out where you are going wrong.
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 8th Feb 2016 18:00
Quote: "Can you upload your modified image so we can see both images to see if they are centred."


already I attached a PSD file in above but now upload it again. (note: this is one example and I tested many sprite)

if I can fix this problem, I will can try to finish this fighting game.

Thanks.

Attachments

Login to view attachments
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 8th Feb 2016 20:08 Edited at: 8th Feb 2016 20:45
Quote: "already I attached a PSD file in above but now upload it again. (note: this is one example and I tested many sprite)"


Well just had a look at this one you have put on and it is the same as above with images still off centre!


Quote: "if I can fix this problem"


Just change the image in photoshop as mentioned above as you still haven't done this and you will have this problem solved.



Really not sure how else to say that the images are not centred for flipping. Think mirror.


[EDIT]
Quote: "even set my sprites to center but really it don't work"


This is the one I said to show to see how the one you changed with images in centre is different
The Amiga and Amos were great!
My website LEAP - Download Paint Pot here!
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 8th Feb 2016 21:26 Edited at: 8th Feb 2016 21:32
@ CJB
Quote: "Your animations are different widths, yet you are placing them with setspriteposition rather than setspritepositionbyoffset. If you want to flip the sprites, you'll need to have your character in the centre of each frame of the sprite, AND you'll need to use setspritepositionbyoffset to take into account the difference in width."


Thanks.
your right, now i understood why Flip sprite don't work for me. I should use setspritepositionbyoffset instead setspriteposition.
but after set sprites to center, it make cut sprites during play animation.

this is Updated Function:



this is my new spritesheet:

Attachments

Login to view attachments
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 8th Feb 2016 23:57
You really are making life hard for yourself with this

Why don't you just open Photoshop and create a blank image with transparent background, set up a grid with block sizes of something like 128 x 128 or which ever UNIFORM size you want.
All you have to do then is put all the frames in this image centred in each area as mentioned before by everyone but the thing is this time each block will be THE SAME SIZE.

All you have to do then is for example:

SetSpriteAnimation(player,128,128,7)


Then set the sprite offset:

SetSpriteOffset(player, GetSpriteWidth(player)/2, GetSpriteHeight(player))


And when you move or fire etc all you have to do is play the sprite and you don't have to keep using SetSpriteAnimation all the time just play sprite:

PlaySprite(player, playerFPS, playerLoop, 1, 4)



The way you have it the blocks are not uniform and you are guessing the values to set each area making life way to complicated for you. This is why the sprite is jumping around and not clipping correctly.
Just start the image from scratch! Take you 15 to 20 minutes and it's done instead of just keep trying to guess the area value and messing up.

Simple
The Amiga and Amos were great!
My website LEAP - Download Paint Pot here!
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 9th Feb 2016 17:11
I fixed it.

Thanks to those who helped me.
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 9th Feb 2016 17:29
Woohoo!!!!
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 10th Feb 2016 09:04

Login to post a reply

Server time is: 2024-04-27 03:47:12
Your offset time is: 2024-04-27 03:47:12