Author Topic: Moving Sprites  (Read 820 times)

Brian Reynolds

  • Newbie
  • *
  • Posts: 20
    • View Profile
Moving Sprites
« on: December 22, 2022, 02:16:19 am »
I am trying to move a sprite continuously by holding down one of the four Arrow keys but I can only get the sprite to move one pixel at a time.
Could someone offer a suggestion on how to do it.
I'm sure I did this a few years ago but my memory loss keeps increasing with my age.
Brian Reynolds.
« Last Edit: December 22, 2022, 02:18:31 am by Brian Reynolds »

Chris Boss

  • Administrator
  • Newbie
  • *****
  • Posts: 49
    • View Profile
Re: Moving Sprites
« Reply #1 on: December 22, 2022, 09:36:27 am »
The EZ_MoseSP command works well but you have to have the sprite index rather than a name.
use the EZ_GetFastSPIndex function to get the sprite index.

Code: [Select]
     FOR I&=1 TO 10
          ' move each sprite 8 pixels in both directions
          EZ_MoveSP SpriteIndex&(I&), 8, 8, 1
     NEXT I&

Chris Boss

  • Administrator
  • Newbie
  • *****
  • Posts: 49
    • View Profile
Re: Moving Sprites
« Reply #2 on: December 22, 2022, 09:42:09 am »
The Canvas control does not respond to key presses.

You may want to preprocess the keyboard events before they get sent to other controls.

I would venture to say your problem may be more associated with how you handle the keyboard events rather than actually moving the sprite.


Brian Reynolds

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Moving Sprites
« Reply #3 on: December 23, 2022, 08:56:37 pm »
I apologise for posting this absurd question on something I have done many times some years ago and had simply forgotten.

I do, however, have a real problem with moving Sprites as I don't seem to be able to use IF ---- THEN before moving a sprite. This code doesn't work but if I REM out the IF THEN and END IF  lines it works okay. The trouble is, that without the IF ---- THEN it will also move other sprites.

Code: [Select]
         IF Sname$="LeftSP" OR Sname$="RiteSP" THEN
            EZ_MoveSprites Sname$, -1, 0, 1  ' Move Left
         END IF

I have also tried moving the code to a subroutine but it still doesn't work with the IF ---- THEN but works without it.

Any suggestions?


Chris Boss

  • Administrator
  • Newbie
  • *****
  • Posts: 49
    • View Profile
Re: Moving Sprites
« Reply #4 on: December 24, 2022, 09:39:35 pm »
One thing I have learned from experience is that often the problem not what we initially think.

It may be possible that earlier code being executed causes a problem in later lines of code, but all we see is where the problem 'appears" to be.

This is why it is helpful to post larger blocks of code so I can see the "big picture"

Also it is helpful at times to try to recreate the problem in a simple test program with only the core task you are attempting. Such recreations often show up whether there really is a bug (ie. say in EZGUI) or whether we are possibly doing something wrong in our actual app.

You might want to try a simple test app with just the bare minimum to demonstrate your problem. Then post the entire test app here and we can discuss it in detail.