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 / Trying to not get mad about moving and cycling my sprite..

Author
Message
Alduce
21
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 18th Oct 2012 18:52 Edited at: 18th Oct 2012 18:53
Hello again,
I made a little demo.
A little man can be moved in the 8 directions using the PC arrow keys.

Here the main loop code:


You can check yourself my code, I attached the RAR folder containing files and media (collision2.cbp is file you need to load)

Ok, here the problems:

1) From the code you can notice that if you move up the sprite so it should start to cycling the animation frames.. but nothing

2) I make some print to see what direction the sprite is doing.
If you go up,left,right,down so the "move_up","move_down","move_left","move_right" variables will get 1.
If you don't push any keys so these variables will get 0
BUT!
If, for example, I push the up and right arrow keys both so I see just move_up = 1, the other involved variable (move_right) remaining 0... but the sprite correctly going in diagonal up/right direction...

I am trying to understand the logic needed to correct these 2 problems but I can't to exit from a stuck condition..

Attachments

Login to view attachments
Funnell7
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 18th Oct 2012 19:02
There are many ways you could optimise this, but just to alter your code slightly, try this...



This is only pseudo code as I'm at work and could only do this in Notepad
Alduce
21
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 18th Oct 2012 19:29 Edited at: 18th Oct 2012 19:29
Ehhh thanks dude, your code works great!!
before of your help I tried a lot of solutions but nothing...
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 18th Oct 2012 20:49
Funnel7 nailed the problem with why you didn't see the animation running. Your code kept resetting the animation to the first frame. Which meant you'd never get past the first frame. His mod check to see if it was not already running before making the call.

Cheers,
Ancient Lady
AGK Community Tester
Alduce
21
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 18th Oct 2012 23:29 Edited at: 18th Oct 2012 23:33
Yes Ancient Lady and I back to get troubles with that!

First problems solved by Funnell7 but now I have another BIG problem:

My actual code:


So, you tell my code is continuing to reset.. yeah.. but I don't understand WHY!! and now I have this problem :

If you move the sprite in one direction and later you release the movement key so you obtain the right work.


BUT follow this example:
FIRST PROCEDURE (NOT WORKING GOOD)
1) you press up key and the sprite go up with up movements
2) while you pressing up key you press right too
3) you leave up key while you pressing right
4) while you pressing right you start to press down
5) you leave right key while you pressing down key
6) while you pressing down key you start to press left key
7) you leave down key while you pressing left key
8) while you pressing left key you start to press up key

IF you make this procedure you see that yes, the sprite moving in XY coords correctly but it cycling ONLY the UP MOVEMENT frames



But If you try to do the following you will get right result:
SECOND PROCEDURE (WORK GOOD)
1) you move up then stop (you can see the up frames and sprites going up)
2) you move right then stop (you can see the right frames and sprites going right)
3) you move down then stop (you can see the down frames and sprite going down)
4) you move left then stop (you can see the left frames and sprite going left)
Only in this way I obtain my frames right for the actual direction.



I tried ALL dudes to solve the first procedure I know I am not a good programmer but DAMN! I can't to obtain that while I change direction so the new direction frames take the places of the old direction frames

Help :\


Ps: Attached the project folder, load collision2.cbp to start)

Attachments

Login to view attachments
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 18th Oct 2012 23:54
This is because you only start the animation if the animation has stopped. (if GetSpritePlaying(SpriteA) = 0)

If the animation is playing for one direction, and you move another way, the animation does not stop and so the new animation does not play.

A better idea might be to have the current direction in one variable and the last direction in another. When these are different, you know to start a new animation.

A good way to do this is to set up constants for each direction using powers of two'

and more constants for the key presses

this makes the keyboard routine easy to follow

This routine allows for all four keys to be pressed at once though it is not possible to move in all four directions at once.

Next you check to see if the direction has changed and only if it has do you change the animation.
Alduce
21
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 19th Oct 2012 00:06 Edited at: 19th Oct 2012 00:07
Dude your code works fine!

But If I try to touch I make error.. I have no chanches..

I tried to apply this modification.. simply to obtain the movement in XY coords too but..
it's not work and believe me, I don't have any ideas why.. .Should work because if the CASE UP is running SO WHY the movement command did not work
:
Alduce
21
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 19th Oct 2012 00:12 Edited at: 19th Oct 2012 00:14
DONE DUDE!!!! THANK YOU SO MUTCH!!!

(thank you all dudes! I will try to avoid to bombing you with my help requests as much as possible!, your help is fantastic!)

Login to post a reply

Server time is: 2024-05-04 07:49:33
Your offset time is: 2024-05-04 07:49:33