Game Pad out of sprites - Test -

Operator
Posts: 138
Joined: Mon May 06, 2013 5:52 am

Re: Game Pad out of sprites - Test -

Post by Operator »

Hello Tantrixx,
I guess you want the sprite (walker)
to rember it's last position (frame x)
so that when you change direction
it will continue in the "correct" frame
and not start at a fix frame as coded,
right?

Tantrixx
Posts: 119
Joined: Sun Nov 22, 2015 11:24 am
My devices: iPhone 5

Re: Game Pad out of sprites - Test -

Post by Tantrixx »

Operator wrote:Hello Tantrixx,
I guess you want the sprite (walker)
to rember it's last position (frame x)
so that when you change direction
it will continue in the "correct" frame
and not start at a fix frame as coded,
right?
Hello Operator. For example, I pressed the button to the right, moving sprite, I let go of the button sprite changed to frame 22. I pressed the button to the left, let go, sprite changed to frame 17. I apologize for my English :)

Operator
Posts: 138
Joined: Mon May 06, 2013 5:52 am

Re: Game Pad out of sprites - Test -

Post by Operator »

If you run the snippet and start walking
to the right then the first/start frame is #24
as long as you keep touching right it will
cycle/start over after reaching frame #31...,
if you release the button it will stop...
Then touch left and the first frame should be
frame #16... so if you see frame #17 then
because you were not able to stop/release
your finger "earlier"...

Guess you are tracking the sprite frames,
-->
slow down the loop by increasing the pause
time...
PAUSE 0.05 'adjust IF req.
change to
PAUSE 0.3 'adjust IF req.
so that you can almost step one frame by
just tipping...

Tantrixx
Posts: 119
Joined: Sun Nov 22, 2015 11:24 am
My devices: iPhone 5

Re: Game Pad out of sprites - Test -

Post by Tantrixx »

:) I find it difficult to explain. the game is a hero, and when the button is released, it does not it freezes with raised foot and stops. I want to do the same. when the button is released, the sprite is replaced by the hero who stopped smoothly. I want to say thank you for such an interesting example. I'm still just learning to program.

Operator
Posts: 138
Joined: Mon May 06, 2013 5:52 am

Re: Game Pad out of sprites - Test -

Post by Operator »

So you want the walk cycle to end in the
standing position (both feet on the ground)
when direction button is released or at least
that the frame shown when walker stops is
the standing position frame...?

Tantrixx
Posts: 119
Joined: Sun Nov 22, 2015 11:24 am
My devices: iPhone 5

Re: Game Pad out of sprites - Test -

Post by Tantrixx »

Operator wrote:So you want the walk cycle to end in the
standing position (both feet on the ground)
when direction button is released or at least
that the frame shown when walker stops is
the standing position frame...?
Yes :)

Operator
Posts: 138
Joined: Mon May 06, 2013 5:52 am

Re: Game Pad out of sprites - Test -

Post by Operator »

Replace the main loop of the snippet with
this...walker will stop in standing position,
but not if button A or B is pressed at the
same time... hope this helps

Code: Select all

LOOP: 'main
TIME RESET
i = i+1
bA$=""
bB$=""

IF pad_touch("up") AND inbounds() THEN
  'walk up
  start_frame = 8
  i_sp_up = (i_sp_up + 1)%8
  SPRITE "walker" FRAME start_frame+i_sp_up
  y = y-DY
  drw_sprite()
  last_dir$ = "up"
END IF

IF pad_touch("down") AND inbounds() THEN
  'walk down
  start_frame = 0
  i_sp_down = (i_sp_down + 1)%8
  SPRITE "walker" FRAME start_frame+i_sp_down
  y = y+DY
  drw_sprite()
  last_dir$ = "down"
END IF

IF pad_touch("left") AND inbounds() THEN
  'walk left
  start_frame = 16
  i_sp_left = (i_sp_left + 1)%8
  SPRITE "walker" FRAME start_frame+i_sp_left
  x = x-DX
  drw_sprite()
  last_dir$ = "left"
END IF

IF pad_touch("right") AND inbounds THEN
  'walk right
  start_frame = 24
  i_sp_right = (i_sp_right + 1)%8
  SPRITE "walker" FRAME start_frame+i_sp_right
  x = x+DX
  drw_sprite()
  last_dir$ = "right"
END IF

'if walker stops adopt standing positions
IF pad_touch.tx=-1  THEN 'no pad touch
  IF last_dir$ = "right" THEN 
    SPRITE "walker" FRAME 24
  END IF
  IF last_dir$ = "left" THEN 
    SPRITE "walker" FRAME 16
  END IF
  IF last_dir$ = "up" THEN 
    SPRITE "walker" FRAME 8
  END IF
  IF last_dir$ = "down" THEN 
    SPRITE "walker" FRAME 0
  END IF
  drw_sprite()
END IF 

IF butA_touch() THEN
  NOTES MIDI 0,9,60,127
  bA$=" Button >A< pressed"
END IF

IF butB_touch() THEN
  NOTES MIDI 0,9,62,127
  bB$=" Button >B< pressed"
END IF

dT = dT+(TIME())
FIELD "FPS" TEXT "loops/sec: "&STR$(FLOOR(i/dT))&" "&bA$&bB$

IF i> 500 THEN
  i=0
  dT=0
END IF

PAUSE 0.05 'adjust IF req.
GOTO LOOP

Tantrixx
Posts: 119
Joined: Sun Nov 22, 2015 11:24 am
My devices: iPhone 5

Re: Game Pad out of sprites - Test -

Post by Tantrixx »

Operator wrote:Replace the main loop of the snippet with
this...walker will stop in standing position,
but not if button A or B is pressed at the
same time... hope this helps

Code: Select all

LOOP: 'main
TIME RESET
i = i+1
bA$=""
bB$=""

IF pad_touch("up") AND inbounds() THEN
  'walk up
  start_frame = 8
  i_sp_up = (i_sp_up + 1)%8
  SPRITE "walker" FRAME start_frame+i_sp_up
  y = y-DY
  drw_sprite()
  last_dir$ = "up"
END IF

IF pad_touch("down") AND inbounds() THEN
  'walk down
  start_frame = 0
  i_sp_down = (i_sp_down + 1)%8
  SPRITE "walker" FRAME start_frame+i_sp_down
  y = y+DY
  drw_sprite()
  last_dir$ = "down"
END IF

IF pad_touch("left") AND inbounds() THEN
  'walk left
  start_frame = 16
  i_sp_left = (i_sp_left + 1)%8
  SPRITE "walker" FRAME start_frame+i_sp_left
  x = x-DX
  drw_sprite()
  last_dir$ = "left"
END IF

IF pad_touch("right") AND inbounds THEN
  'walk right
  start_frame = 24
  i_sp_right = (i_sp_right + 1)%8
  SPRITE "walker" FRAME start_frame+i_sp_right
  x = x+DX
  drw_sprite()
  last_dir$ = "right"
END IF

'if walker stops adopt standing positions
IF pad_touch.tx=-1  THEN 'no pad touch
  IF last_dir$ = "right" THEN 
    SPRITE "walker" FRAME 24
  END IF
  IF last_dir$ = "left" THEN 
    SPRITE "walker" FRAME 16
  END IF
  IF last_dir$ = "up" THEN 
    SPRITE "walker" FRAME 8
  END IF
  IF last_dir$ = "down" THEN 
    SPRITE "walker" FRAME 0
  END IF
  drw_sprite()
END IF 

IF butA_touch() THEN
  NOTES MIDI 0,9,60,127
  bA$=" Button >A< pressed"
END IF

IF butB_touch() THEN
  NOTES MIDI 0,9,62,127
  bB$=" Button >B< pressed"
END IF

dT = dT+(TIME())
FIELD "FPS" TEXT "loops/sec: "&STR$(FLOOR(i/dT))&" "&bA$&bB$

IF i> 500 THEN
  i=0
  dT=0
END IF

PAUSE 0.05 'adjust IF req.
GOTO LOOP
Thank you, Оperator, everything turned out. I did everything I knew, I tried :) Sprite 8 8 motion goes slowly at first, then accelerates. Pause is 0.08 as it should be?

Operator
Posts: 138
Joined: Mon May 06, 2013 5:52 am

Re: Game Pad out of sprites - Test -

Post by Operator »

The "update" just showed the walker in
standing position when stopped without resetting the counters of the cycles...!
As I guess you want it more realistic..(?)
Just reset the cycle counters: i_isp_X
when the walker stopped...

Change this part:

Code: Select all

'if walker stops adopt standing positions
IF pad_touch.tx=-1  THEN 'no pad touch
  IF last_dir$ = "right" THEN 
    SPRITE "walker" FRAME 24
  END IF
  IF last_dir$ = "left" THEN 
    SPRITE "walker" FRAME 16
  END IF
  IF last_dir$ = "up" THEN 
    SPRITE "walker" FRAME 8
  END IF
  IF last_dir$ = "down" THEN 
    SPRITE "walker" FRAME 0
  END IF
  drw_sprite()
  'reset the cycling counters so walker
  'will always start in its first direction
  'frame
  i_isp_up = 0 
  i_isp_down = 0
  i_isp_right = 0
  i_isp_left = 0 
END IF 
Pause set to 0.03 works good for me,
on my iPhone 4 /iOS 6.1... 8-)

Hope this helps...

Tantrixx
Posts: 119
Joined: Sun Nov 22, 2015 11:24 am
My devices: iPhone 5

Re: Game Pad out of sprites - Test -

Post by Tantrixx »

https://www.dropbox.com/sh/w7upr465fw2j ... 369Wa?dl=0
Operator, in Dropbox link to your code and my sprite. I then add lateral movement. Can mr.K tell?
mr.Kibernetik, there sprite 8 by 8. the motion as if he accelerates. When pick up speed, the next movement is moving normally. iPhone 5. How do I make right move at maximum speed.

Post Reply