Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 07:38 27 Apr 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 1 of 2    
Author Message
Hawk

Senior Member

Joined: 15/07/2021
Location: Australia
Posts: 140
Posted: 12:53pm 09 May 2023
Copy link to clipboard 
Print this post

Page 27:
The manual lists the available commands as:
   SPRITE READ
   SPRITE WRITE
   SPRITE LOAD
   SPRITE LOADBMP
   SPRITE CLOSE

From the Commands Section on Page 93, the SPRITE commands missing from this description are:
   SPRITE COPY
   SPRITE HIDE
   SPRITE RESTORE
   SPRITE INTERRUPT
   SPRITE LOADARRAY
   SPRITE MOVE
   SPRITE NEXT
   SPRITE SCROLL
   SPRITE SHOW
   SPRITE SWAP

Not sure if you want to expand the Graphics Commands and Function section to include examples of these additional SPRITE commands, or reword the statement on Page 27 to;

"Some of the available SPRITE commands are:"  and then leave the list as it is.

I would really like to see an example that uses SPRITES and eliminate tearing.

I understand if you don't want lots of fingers in the pie, but if you would like help maintaining the manuals (and there are now quite a few) you just need to ask.  Github has a great ability for changes to be reviewed before they get included in the main line.

Cheers,
Hawk.

Cheers,
Hawk
 
Hawk

Senior Member

Joined: 15/07/2021
Location: Australia
Posts: 140
Posted: 12:57pm 09 May 2023
Copy link to clipboard 
Print this post

BTW, the following sections of this manual still refer to 64 sprites:

Page 112: SPRITE(T.[#]n)
Page 134: Appendix G, "Sprites are load to a specific number (1 to 64)."

Hawk
PicoMiteVGA User Manual MMBasic Ver 5.07.07
Edited 2023-05-09 22:58 by Hawk
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 1643
Posted: 01:41pm 09 May 2023
Copy link to clipboard 
Print this post

How much of vga sprite is the same as non vga picomite blit?
I got blit scrolling horizontal by blit copy and move but not very smooth.
The ili9341 blit commands are a big feature for me. Surprising what can be done on glcd with mmbasic.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8579
Posted: 02:03pm 09 May 2023
Copy link to clipboard 
Print this post

  Quote  I would really like to see an example that uses SPRITES and eliminate tearing.


Like this

Best run at 378MHz

Option explicit
Option default none
MODE 2
FRAMEBUFFER create
FRAMEBUFFER write f
CLS
'brownian motion demo using sprites
Dim integer x(32),y(32),c(32)
Dim float direction(32)
Dim integer i,j,k, collision=0
Dim string q$
For i=1 To 32
direction(i)=Rnd*360 'establish the starting direction for each atom
c(i)=RGB(Rnd*255,Rnd*255,Rnd*255) 'give each atom a colour
Circle 10,10,8,1,,RGB(white),c(i) 'draw the atom
Sprite read i,2,2,17,17 'read it in as a sprite
Next i
CLS
Load jpg "img320" 'any picture or just use CLS anycolour
Box 0,0,MM.HRes,MM.VRes
k=1
For i=MM.HRes\9 To MM.HRes\9*8 Step MM.HRes\4
For j=MM.VRes\9 To MM.VRes\9*8 Step MM.VRes\9
  Sprite show k,i,j,1
  x(k)=i
  y(k)=j
  vector k,direction(k), 0, x(k), y(k) 'load up the vector move
  k=k+1
Next j
Next i
'
Do
For i=1 To 32
  vector i, direction(i), 1, x(i), y(i)
  Sprite show i,x(i),y(i),1
  If sprite(S,i)<>-1 Then
    break_collision i
  EndIf
Next i
FRAMEBUFFER copy f,n
Loop
'
Sub vector(myobj As integer, angle As float, distance As float, x_new As integer, y_new As integer)
Static float y_move(32), x_move(32)
Static float x_last(32), y_last(32)
Static float last_angle(32)
If distance=0 Then
  x_last(myobj)=x_new
  y_last(myobj)=y_new
EndIf
If angle<>last_angle(myobj) Then
  y_move(myobj)=-Cos(Rad(angle))
  x_move(myobj)=Sin(Rad(angle))
  last_angle(myobj)=angle
EndIf
x_last(myobj) = x_last(myobj) + distance * x_move(myobj)
y_last(myobj) = y_last(myobj) + distance * y_move(myobj)
x_new=Cint(x_last(myobj))
y_new=Cint(y_last(myobj))
Return

' keep doing stuff until we break the collisions
Sub break_collision(atom As integer)
Local integer j=1
Local float current_angle=direction(atom)
'start by a simple bounce to break the collision
If sprite(e,atom)=1 Then
  'collision with left of screen
  current_angle=360-current_angle
ElseIf sprite(e,atom)=2 Then
  'collision with top of screen
    current_angle=((540-current_angle) Mod 360)
ElseIf sprite(e,atom)=4 Then
  'collision with right of screen
  current_angle=360-current_angle
ElseIf sprite(e,atom)=8 Then
  'collision with bottom of screen
  current_angle=((540-current_angle) Mod 360)
Else
  'collision with another sprite or with a corner
  current_angle = current_angle+180
EndIf
direction(atom)=current_angle
vector atom,direction(atom),j,x(atom),y(atom) 'break the collision
Sprite show atom,x(atom),y(atom),1
'if the simple bounce didn't work try a random bounce
Do While (sprite(t,atom) Or sprite(e,atom)) And j<10
  Do
    direction(atom)= Rnd*360
    vector atom,direction(atom),j,x(atom),y(atom) 'break the collision
    j=j+1
  Loop Until x(atom)>=0 And x(atom)<=MM.HRes-sprite(w,atom) And y(atom)>=0 And y(atom)<=MM.VRes-sprite(h,atom)
  Sprite show atom,x(atom),y(atom),1
Loop
' if that didn't work then place the atom randomly
Do While (sprite(t,atom) Or sprite(e,atom))
  direction(atom)= Rnd*360
  x(atom)=Rnd*(MM.HRes-sprite(w,atom))
  y(atom)=Rnd*(MM.VRes-sprite(h,atom))
  vector atom,direction(atom),0,x(atom),y(atom) 'break the collision
  Sprite show atom,x(atom),y(atom),1
Loop
End Sub

Edited 2023-05-10 00:06 by matherp
 
Hawk

Senior Member

Joined: 15/07/2021
Location: Australia
Posts: 140
Posted: 11:25pm 09 May 2023
Copy link to clipboard 
Print this post

Thanks matherp.

I’ve been looking through your code, but I can’t see anything specific that you’re doing to avoid tearing.  Without referring to the manual, I’m assuming that you’re using the FRAMEBUFFER as a hidden location to construct the sprites that are then displayed using the SPRITE SHOW command.

Does this avoid tearing purely because of the higher clock speed?  I have not run the code on my PicoMiteVGA yet, and have only watched the video.

Or is it the FRAMEBUFFER Copy that is providing the double buffering?

<Time passes>

OK, I had to RTFM and now I understand.  The SPRITE Show commands are writing to the FRAMEBUFFER, and then the FRAMEBUFFER Copy command is copying all the updated sprites at one time.

I will give this a try.  I am only moving one sprite, so effectively I will need to do a FRAMEBUFFER Copy after each SPRITE Show command.

Hawk
 
Hawk

Senior Member

Joined: 15/07/2021
Location: Australia
Posts: 140
Posted: 10:26am 10 May 2023
Copy link to clipboard 
Print this post

I tried using FRAMEBUFFER to eliminate the tearing, but I suspect that I ran out of memory part way through loading the sprites.  I Tdidn't get an error message (well not that I could see, anyway), but my program stopped before all the sprites were loaded.

Time to try a new theory.

Hawk
 
Hawk

Senior Member

Joined: 15/07/2021
Location: Australia
Posts: 140
Posted: 11:44pm 13 May 2023
Copy link to clipboard 
Print this post

<Accidental double post>
Edited 2023-05-14 09:47 by Hawk
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5904
Posted: 02:37am 14 May 2023
Copy link to clipboard 
Print this post

  Quote  
Sub vector(myobj As integer, angle As float, distance As float, x_new As integer, y_new As integer)
...
Return


Any particular reason for the resurrection of RETURN instead of END SUB?

Jim
VK7JH
MMedit   MMBasic Help
 
Hawk

Senior Member

Joined: 15/07/2021
Location: Australia
Posts: 140
Posted: 10:48am 17 May 2023
Copy link to clipboard 
Print this post

I have been making progress with my SPRITE learning.

The solution to stopping the sprites from tearing as I moved them across the screen was to wait for the scan line to be at the bottom of the screen.

My current problem is that I am trying to load a new image from a BMP file, using SPRITE LOADBMP, into an existing sprite (trying to change what it looks like  - turn a card over).  That works, but does not update the image on the display, so I added a SPRITE SHOW command to update the sprite on the display.  The sprite gets updated with the new image on the display and then I get:

Error: sprite internal error

Is anyone able to shed some light on what I'm doing wrong?

Hawk
Edited 2023-05-17 20:52 by Hawk
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8579
Posted: 10:51am 17 May 2023
Copy link to clipboard 
Print this post

  Quote  using SPRITE LOADBMP, into an existing sprite (trying to change what it looks like  - turn a card over).  That works,


This isn't allowed should give an error
 
Hawk

Senior Member

Joined: 15/07/2021
Location: Australia
Posts: 140
Posted: 10:56am 17 May 2023
Copy link to clipboard 
Print this post

  matherp said  
  Quote  using SPRITE LOADBMP, into an existing sprite (trying to change what it looks like  - turn a card over).  That works,


This isn't allowed should give an error

Thanks for the prompt response Peter.

So the SPRITE LOADBMP command creates a new sprite at the same time as loading the image?

So my work around would be to:

SPRITE LOADBMP Temp
SPRITE Copy Temp to Dest
SPRITE CLOSE Temp

Should this work?

Oops...that won't work either, as SPRITE COPY also creates new sprites.

I should

SPRITE CLOSE Dest
SPRITE LOADBMP Dest
SPRITE Show

Hawk
Edited 2023-05-17 20:58 by Hawk
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8579
Posted: 11:02am 17 May 2023
Copy link to clipboard 
Print this post

Look at SPRITE SWAP
 
Hawk

Senior Member

Joined: 15/07/2021
Location: Australia
Posts: 140
Posted: 11:02am 17 May 2023
Copy link to clipboard 
Print this post

OK, so

SPRITE Close
SPRITE LoadBMP
SPRITE Show

worked, but the sprite disappeared before re-appearing with the new bitmap.

Hawk
 
Hawk

Senior Member

Joined: 15/07/2021
Location: Australia
Posts: 140
Posted: 11:06am 17 May 2023
Copy link to clipboard 
Print this post

  matherp said  Look at SPRITE SWAP


I'm not sure that will achieve the goal.  Only one of the sprites is visible at a time.  SPRITE SWAP requires them both to be displayed.

What method would you use if you were trying to animate a walk cycle of a sprite?

What I'm trying to do is a bit like that.

Hawk
 
Hawk

Senior Member

Joined: 15/07/2021
Location: Australia
Posts: 140
Posted: 11:22am 17 May 2023
Copy link to clipboard 
Print this post

Ahhhh...

OK, so I need to appologise. I misread SPRITE SWAP, and it should do what I want:

SPRITE LoadBMP Temp
SPRITE SWAP Dest, Temp
<Edit>
Can't close Temp or the Dest sprite disappears.
SPRITE Close Temp
</edit>

The problem occurred that SPRITE SWAP hasn't had bit 2 of the "orientation" parameter implemented, so the black came out transparent, and when I set "orientation" to 4 (bit 2 set) I got an error, as "orientation" only has valid values of 0 to 3.



Hawk
Edited 2023-05-17 21:30 by Hawk
 
Hawk

Senior Member

Joined: 15/07/2021
Location: Australia
Posts: 140
Posted: 11:45am 17 May 2023
Copy link to clipboard 
Print this post

I thought I'd post a link to my progress.

Tweet about MMBasic and PicoMiteVGA

You can see at the end the transparent cards.

Hawk
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8579
Posted: 11:48am 17 May 2023
Copy link to clipboard 
Print this post

Try this for swap with bit 2 - untested


PicoMiteVGA (2).zip
 
Hawk

Senior Member

Joined: 15/07/2021
Location: Australia
Posts: 140
Posted: 12:12pm 17 May 2023
Copy link to clipboard 
Print this post

  matherp said  Try this for swap with bit 2 - untested


PicoMiteVGA (2).zip


Wow...that was responsive.  Unfortunately I can't be as responsive in my testing right now, but will soon.

Hawk.
 
Hawk

Senior Member

Joined: 15/07/2021
Location: Australia
Posts: 140
Posted: 12:51pm 17 May 2023
Copy link to clipboard 
Print this post

[UPDATE]
I hadn't noticed that the non-transparency actually worked for the first card, it's just that when I went to load the second card I got the error detailed below.

So the question remains "How do we change the graphics of an existing sprite?"

---
So this new version now has an error report "Buffer in use" when I try and load a new image over the last one using SPRITE LoadBMP.  I'll try the SPRITE Close again after the Swap to see if the destination sprite disappears.

...

Nope...sorry, when I Closed the temporary sprite, the destination sprite disappeared from the display.

I'm open to ideas.  Hopefully you can see what I am trying to achieve.

For those playing along at home, this is the inspiration for my project.

Creative Computing, May, 1977

Until then, I'll be back to try again tomorrow.  Thanks for your help Peter.

Hawk
Edited 2023-05-17 23:19 by Hawk
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5726
Posted: 03:03pm 17 May 2023
Copy link to clipboard 
Print this post

Oh, that magazine brought back a couple of memories! My daughter was just 3 months old and we were living in a lovely little 2-up-2-down terraced house. I was still to get my first computer (of any sort) but I was just starting to take an interest in them. They were all much, much too expensive though - the sort of things dreams are made of.

I suspect that once you have a sprite on screen and you want to change it you'll have to create the new one off screen, then swap it with the on-screen one, then close the old one as it's not needed anymore. Wouldn't the off-screen area be a frame buffer? I've never used sprites.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
     Page 1 of 2    
Print this page
© JAQ Software 2024