Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 19:51 28 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : PicoMiteVGA Manual: Graphics Commands and Functions/SPRITE

     Page 2 of 2    
Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9129
Posted: 03:18pm 17 May 2023
Copy link to clipboard 
Print this post

SPRITE SWAP should do what you want. Run the attached and you will see how I do it

MODE 2
MODE 2
Box 0,0,20,30,6,RGB(red)
Sprite read 1,0,0,20,30
Box 0,0,20,30,6,RGB(blue)
Sprite read 2,0,0,20,30
CLS RGB(green)
Sprite show 1,50,50,0,4
Sprite hide 1
Sprite show 2,50,50,0,4
Do
Pause 1000
Sprite swap 2,1,4
Pause 1000
Sprite swap 1,2,4
Loop

Edited 2023-05-18 01:33 by matherp
 
Hawk

Senior Member

Joined: 15/07/2021
Location: Australia
Posts: 141
Posted: 12:01am 18 May 2023
Copy link to clipboard 
Print this post

The example you've given is not quite demonstrating what I am trying to achieve.  Your example continually swaps between two sprites.

I'm trying to change the graphics of a sprite.  I swap from a temperary sprite to the active sprite, and that seems to work, but when I delete the temperary sprite, the active sprite disappears.

Once I've done the swap from the temperary sprite, I want to load new graphics into it to swap into the next active sprite, but that causes an error.

Fundamentally, all I want to do is change the graphics of an active sprite.  I have 24 active sprites.  When I flip a card, I want it's graphics to change from the back of the card to it's face value.  If cards weren't being moved and overlayed, I may be able to create the sprite on the fly from the background image, but I'm trying to make the visuals more animated.

I'm not sure that I really understand what SPRITE SWAP is doing.  Is it just swapping the graphics of a sprite, or is it changing everything about them, so that the new sprite (number included) takes the place and all the attributes of the old sprite.  If the later is the case, then this won't work for my scenario as written, as the sprite number is related to the face value of the card.

What I'm after may not be possible within the current framework, but I'll give it a good try to make it work if I can.

Hawk
 
Hawk

Senior Member

Joined: 15/07/2021
Location: Australia
Posts: 141
Posted: 12:08am 18 May 2023
Copy link to clipboard 
Print this post

Thinking of another possible solution:

SPRITE LoadBMP 1 ' Card back
SPRITE Show
SPRITE LoadBmp tmp ' Card back
SPRITE Swap 1, tmp
SPRITE Close 1
SPRITE LoadBmp 1 ' Card face value
SPRITE Swap tmp,1
SPRITE Close tmp


It's long winded, but this may work, if SPRITE Swap behaves how I think it does.

Hawk
Edited 2023-05-18 10:09 by Hawk
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6798
Posted: 06:22am 18 May 2023
Copy link to clipboard 
Print this post

Dp you need a sprite for the card backs? Couldn't you just disable the sprite and BLIT a back pattern? You may need to keep the card value for that location in an array because it will be gone when the sprite goes.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Hawk

Senior Member

Joined: 15/07/2021
Location: Australia
Posts: 141
Posted: 06:50am 18 May 2023
Copy link to clipboard 
Print this post

  Mixtel90 said  Do you need a sprite for the card backs? Couldn't you just disable the sprite and BLIT a back pattern? You may need to keep the card value for that location in an array because it will be gone when the sprite goes.

If I don't use a sprite for the cards when face down, I would need to manually store the background where I am blitting the "back" image, re-store the background and repeat.  Also, when I 'flip' a card or 'play' a card, I would also need to replace the background and then blit the new card image.

It's possible, but that is the reason you usually have sprites, to avoid having to do all that manually.  Even platforms like the Vic20, which had no hardware sprites, had the ability to implement software sprites using those methods.  I was hoping to be able to use the sprites supported within MMBasic.

However, it is certainly a good backup plan if I find that the implemented sprites just won't do what I'm aiming for.

I though I would be able to implement a simple solution where each card is a sprite, and I change it's image to face it up or down, and it's position to move it around the table.  My plan was working, right up to the point where I wanted to change the sprite's image.

Hawk
Edited 2023-05-18 16:52 by Hawk
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2140
Posted: 08:26am 18 May 2023
Copy link to clipboard 
Print this post

  Quote  Also, when I 'flip' a card or 'play' a card, I would also need to replace the background and then blit the new card image.

Confused, is the card being 'flipped' to a new location?
If it is the same location is the background needed?
 
Hawk

Senior Member

Joined: 15/07/2021
Location: Australia
Posts: 141
Posted: 08:35am 18 May 2023
Copy link to clipboard 
Print this post

Yay,    this solution worked...well sort of.  

SPRITE LoadBMP 1 ' Card back
SPRITE Show
SPRITE LoadBmp tmp ' Card back
SPRITE Swap 1, tmp
SPRITE Close 1
SPRITE LoadBmp 1 ' Card face value
SPRITE Swap tmp,1
SPRITE Close tmp

To try and speed it up a bit, and not read from the SD card twice, I decided to SPRITE Copy tmp from my existing card back sprite, as I do when creating and dealing all the other cards.
So it actually looks like this:
SPRITE Copy back,tmp ' Copy card back to tmp sprite
SPRITE Swap card,tmp,4
SPRITE Close card
SPRITE LoadBmp card ' Card face value
SPRITE Swap tmp,card,4
SPRITE Close tmp


Tweet showing sprite error.

As you can see, the speed has not decreased noticeably, and the black is no longer transparent.  (Thanks Peter) But the sprite image data is being corrupted as I move it across the screen, but always after it has worked successfully four times.

I know that I must be doing something wrong somewhere, as when I go to edit the program after it has run, I get a brief message flashed up on the screen that says "<something, something something>: Resetting", and the the Pico resets.

Help...please  

Hawk

[Update]
The error reported when I try and edit the program after running it is:
"Error: Invalid Address: Resetting"
Edited 2023-05-18 18:54 by Hawk
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9129
Posted: 09:16am 18 May 2023
Copy link to clipboard 
Print this post

The program should give an error but you are so far outside of the design concept that it is not surprising I haven't trapped it. Copy works by creating sprites that reference the master. In normal use if you try and close the master you will get an error if copies are still open. By using swap you are circumventing this check leading to corruption.
For your application I would use framebuffers and blit with framebuffer copy after each move
Edited 2023-05-18 19:18 by matherp
 
Hawk

Senior Member

Joined: 15/07/2021
Location: Australia
Posts: 141
Posted: 09:59am 18 May 2023
Copy link to clipboard 
Print this post

If what you are saying is true then I shouldn't be getting an error, as the master sprite for the card back, from which all others are copied, is never closed.  I only close the copies that I have made.  Admittedly, after a sprite swap has been made.

I tried using framebuffers in the early stages, but I figured that I was running out of memory, as after I had created the frame buffer, the card sprites, which previously all loaded correctly, stopped loading part way through.

Sounds like I'm going to have to re-think my whole approach.

Hawk
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9129
Posted: 07:39am 19 May 2023
Copy link to clipboard 
Print this post

Try this version. I've found and (maybe) fixed a problem when swapping masters and/or copies


PicoMiteVGA.zip
Edited 2023-05-19 18:27 by matherp
 
Hawk

Senior Member

Joined: 15/07/2021
Location: Australia
Posts: 141
Posted: 11:57am 21 May 2023
Copy link to clipboard 
Print this post

I finally found some time to do some testing.

This new version certainly gave a new set of error messages, that I presume were added to avoid getting into unstable states.  It took me a while to find a sequence of commands that didn't give an error.  When I finally did, I got similar screen corruption to the last video I posted, and no error message.  So there may be a scenario that's not being detected yet.

Unfortunately, I am still unable to find a way of loading a new image into a sprite without it disappearing and then reappearing.  My thoughts of animating the flip have totally gone out the window, and it looks like the current solution that I have will be the compromise I live with on this platform.

Thanks for all your efforts Peter.

I can post the code that causes the corruption if you're interested in tracking it down.

Hawk
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9129
Posted: 12:21pm 21 May 2023
Copy link to clipboard 
Print this post

  Quote  I can post the code that causes the corruption if you're interested in tracking it down.


If you can post something simple that would be appreciated
 
Hawk

Senior Member

Joined: 15/07/2021
Location: Australia
Posts: 141
Posted: 01:09pm 21 May 2023
Copy link to clipboard 
Print this post

Sprite Copy card_back,tmp_card
Sprite Show tmp_card
Sprite Hide card
Sprite Swap tmp_card,card
Sprite Close card
Sprite LoadBMP card
Sprite Show card
Sprite Swap card,tmp_card
Sprite Close tmp_card


To achieve this code I had to rearrange the order of things to eliminate each error that occurred in turn.







Hawk
Edited 2023-05-21 23:19 by Hawk
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9129
Posted: 05:53pm 21 May 2023
Copy link to clipboard 
Print this post

I need some real code and any supporting files in order to try and understand/diagnose. But, please, the minimum necessary to demonstrate the issue
Edited 2023-05-22 03:54 by matherp
 
     Page 2 of 2    
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024