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 / Smooth Animation

Author
Message
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 21st Nov 2013 21:55
Hi.

How can make smooth Animation? I run my sprite animation in Game-Editor engine and run smooth it, but in AppGameKit don't good show my sprite animation. where is Problem?
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 21st Nov 2013 22:10
It can be a few things. One is issues with vsync. Another could be not properly advancing the movement. Check out the Space Game example that came with AppGameKit and see how they handle sprite movement. That should help a lot. Keep in mind that on some devices where frames are dropped a lot you might still see issue.

Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 21st Nov 2013 22:30 Edited at: 21st Nov 2013 22:33
Quote: "
Check out the Space Game example that came with AppGameKit and see how they handle sprite movement. That should help a lot.
"


I See, but it very Complex and Programming is different with me.

my code is:

Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 21st Nov 2013 22:41
It's hard for me to tell what might actually help you.
If you're using sprite sheets then one issue might be that you don't have enough frames on the sheet (in your case separate images) for it too look smooth when play sprite is happening. Also make sure you set the frame rate on the animation properly. I also like to set my sync rate to some multiple of the animation frame rate so that there's less chance of skipping a frame of the sprite sheet.

Also by adding 2 to the x component you're moving it by 2% of your screen's width (unless you're using virtual resolution).

Another thing you want to be cautious of is the naming of your files. Android is case sensitive and I prefer to use all lower case in file names. Also no spaces.

I'd seriously suggest checking out at least the examples.
There's also some links to Dan Foreman's tutorials on here that will help you tremendously. He also has a book.
And there's a book by Digital Skills that is also available and very detailed.
Without this basic foundation of knowledge you're going to end up writing a bunch of code that you might get to work, but will cause you big headaches when you find it doesn't work on certain devices.

Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 22nd Nov 2013 11:28
Quote: "
It's hard for me to tell what might actually help you.
"


I attached my Project with Sprites. I Need show me how can use smooth animation and why when I release the right or left key for back to Idle animation, at a moment change the sprite size?

really I need Help to work with AppGameKit because I work with other UI engines and think work with visual engines is a little harder.

Attachments

Login to view attachments
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 22nd Nov 2013 15:56


This is the working code.
You had a good start, but were sticking yourself into a corner because of the way you were handling the input. I've made modifications to show you a better way of handling input.

Basic structure should be:
Setup sprites, animations, etc.
Check for input
Set your animation frames
Move
Other actions/effects of the input

A couple other tips that will prevent you from headaches in the future:
Indent your code with every conditional/function - use indenting liberally as well as white space - anything you can do to make your code easier to read, because once you get more than 1,000 lines you'll have a difficult time reading what you've already done and you'll make mistakes because of it.
Use explicit conditionals -
if GetRawKeyState(27) will work, but if confusing because you aren't saying what you expect the output to be in an explicit way.
Always use
if GetRawKeyState(27) = 1 so that you explicitly know what you expect for output. Don't trust that a function will only spit out a 0 or 1 and that a boolean check on the output will work.
Last one - http://digital-skills.co.uk/agkoverview.html. Order it. It is only $17GBP and have great simple examples that will help you through this and keep programming fun. There are a few outdated examples, but if you search for them on here then you'll find the answers. It's well worth the money and you can probably work through it in just a week. Definitely WORK through it though and don't just read it. It'll make you a happy programmer.


Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 23rd Nov 2013 15:23 Edited at: 23rd Nov 2013 15:24
thanks Naphier always your help is useful.
but problem still exist and don't fix any problem.
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 24th Nov 2013 17:22
Did you try the code I posted? It works perfectly on my Windows 7 machine and follows the same principals I have used many times to handle sprite movement. Your original code was not even allowing the sprite to move. All you have to do is copy and paste the code I posted in the above code snippet and it should work fine. If not then I'm afraid I cannot help you further as there must be some issue with your computer.

Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 24th Nov 2013 19:36
my code is work for move sprite. and your code can move the sprite.
my problem is when I release the right or left key for back my sprite to Idle animation, at a moment the sprite change the size. I raised this problem at post 5.
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 24th Nov 2013 20:22
Sorry I don't see that happening. Your code didn't move the sprite at all on my machine so that's what I thought the issue was. It would change the animation, but the sprite would not move or if it did it was only moving 2 pixels with every key press then stopping.

I don't see any sprite size changing, but I do notice that the last frame of his idle animation his feet are a bit higher. In the image there should be transparent pixels above his head and not below his feet. This is much easier to see when you use a sprite sheet instead of single images for each animation frame. I've attached a real quick sprite sheet I threw together to show you how your images are lining up.

Hope this helps. If not then I'll need a much more descriptive explanation of what you are having trouble with.

Attachments

Login to view attachments
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 28th Nov 2013 14:14
Thanks. Yes I see problem in my Sprites. Now how can use Sprite sheet in AppGameKit instead of several sprite?
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 28th Nov 2013 16:19
When you have a sprite sheet, there are 2 options really, one a bit of a pain, and one that's really straightforward.

Option 1:
Make a subimages file to go with the sprite sheet, which designates each sprite on the sheet it's own filename, you specify the filename, and position of the sprite, and then it can be loaded from that sheet with the subimages commands.
This is the tricky option.
The benefit would be that you are not restricted to a set grid - sometimes a sprite will need just a little more space - with a subimages file you can use any area and size or whatever you need to chop your sprites into. It's a lot more work, maybe something that you'd only use if you absolutely have to - say a 2D Streetfighter game for example would probably need this sort of control.

Option 2:
Set the sprites animation to the relevant size and number of frames in the sprite sheet. Like, if you have a sprite sheet with 64x64 sprites on a grid of 8x8, then SetSpriteAnimation(spr,64,64,64) - because there would be 64 sprites (8x8). Then you can simply set the sprites frame to change it.
This is the easy option.

I am the one who knocks...
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 28th Nov 2013 16:50 Edited at: 28th Nov 2013 17:04
Quote: "
if you have a sprite sheet with 64x64 sprites on a grid of 8x8, then SetSpriteAnimation(spr,64,64,64) - because there would be 64 sprites (8x8). Then you can simply set the sprites frame to change it.
This is the easy option.
"


I don't understand your mean. this is my sprite sheet that made it in Photoshop with (226 x 81) size, can you explanation with it?

Thanks

Attachments

Login to view attachments
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 28th Nov 2013 18:05
Well say your sprites are 57x81 - you'd probably want to make that 64x128, or 128x128 to allow for bigger sprites and other animation frames. Anyway, if you have 4 sprites at 57x81 on a 228x81 sprite sheet, you'd set the animation to (57,81,4)... 57 wide, 81 high, and 4 sprites.

Then, you just set the frame of the sprite between 1 and 4.

I am the one who knocks...
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 28th Nov 2013 18:45
Thanks Van B for your help.

but why my Sprite is Blinker? I use below code:

Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 29th Nov 2013 13:55 Edited at: 29th Nov 2013 13:56
I find the Problem. in PlaySprite Function I should Set frame from 1 to 3 and not 4 (PlaySprite ( 1, 5, 1, 1, 3 )).why? because my sprite sheet has 4 animation. do my sprite sheet is not standard? how can make standard sheet?

and I need know another thing that already question in another topic but nobody answer me.

if my player has 3 animation (idle, run, jump), I should createSprite for any animation? I find how can add multi animation for each created Sprite without createSprite for every animation. but I don't Know how can use multi animation with SetSpriteAnimation Function. I want check already problem about snooth animation with sprite sheet instead of several sprite.

Please Guide Me.

Thanks
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 29th Nov 2013 14:59
Well, it depends on the resolution your working in, but if it's at all possible to stick to a single sprite sheet, then do that!

If you have several sprite sheets for a single character, you'll have to swap images and re-setup animation and stuff like that. If you have to use different images for a single sprite, then go with the subimages route, because it would be a pain to have to use 4 frames from this image, 2 from this one, 5 from this one etc etc. If you have to use different images, the best way to retain your sanity would be to pre-cut the images for the frames. Like, load the image and subimage load the 4 frames... so you'd end up with each frame as it's own image, and that means you can set the sprite size to suit different sized images, you'd change the sprite image rather than the frame.

If you can stick to a single sprite sheet, then you need to ensure that each frame is the same size, like 57x81 is not an ideal resolution, it would probably have to be 128x128, to allow for attacks and jumps and other animations. Remember that Final Fight and games of that ilk all had very very complicated sprite sheets - they had to optimize everything, so a sprite sheet image would be crammed full. If you decide on a standard, like a 1024x1024 image per character, that should be big enough for all your chars, it provides 64 frames at 128x128, it's easy to work with and easy to adjust if you need to - that's probably twice the resolution of the original Final Fight sprites. Lay your sprites on that, store it as a PNG and you'll have a much neater workflow. If you do your own sprites or get someone to help - have them use a standard sprite sheet, with the same frame numbers etc... that will make the difference between an enemy being a pain to add, or being really easy. A lot of devices will only support 1024x1024 textures, so having that as a standard makes sense I think. The white space will be compressed down to nothing, so don't worry too much about wasting sprite sheet space.

I am the one who knocks...
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 1st Dec 2013 20:06
Behadasoft, you don't use the AddSpriteAnimationFrame with the SetSpriteAnimation command. Instead you load the image then create the sprite using that image and then set the animation (this assumes that the image loaded has the four frames):


Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 24th Dec 2013 20:18
Thanks

Login to post a reply

Server time is: 2024-11-24 23:47:58
Your offset time is: 2024-11-24 23:47:58