Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:05 01 Aug 2025 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 : Newbie Sprite Questions

Author Message
fiziwig
Newbie

Joined: 09/07/2020
Location: United States
Posts: 22
Posted: 04:55pm 06 Aug 2020
Copy link to clipboard 
Print this post

I tried to find this in the various manuals and graphics posts, but haven't had any luck. When a sprite goes partially off the screen (in my case, submarines entering from  and leaving the screen from the sides) is the sprite properly clipped, or do I run the danger of writing sprite image data into RAM someplace where it could damage other data?

Right now I'm clipping and blitting "manually" in my code, but I'm considering changing my submarines to sprites instead of blitted bitmaps, and I need to know if I should be concerned with doing the clipping "manually" in my code.

Should I perhaps use a FRAMEBUFFER larger than the screen to avoid having to clip the bitmaps or sprites?

Also, I've found conflicting information on this: What is the maximum width of a sprite? My submarines are 98 x 43. Is that too big for a sprite? One reference says 16 x 16, another says MM.HRES x MM.VRES.

My falling depth charges are already sprites and collision detection with the submarines would be so much easier if the subs were also sprites.

Also, when animating a depth charge sprite, I have each animation state set up as a separate sprite. Is there a way to SPRITE READ for each animation update (every 4th frame right now) other than swapping the sprite bitmap to the visable screen display? In other words, do I have to only do SPRITE READ from the visible screen? Is there any other way to quickly change the sprite image on the fly without having to flash the sprite images page on the visible screen?  The reason is if I can change the sprite image on the fly the game can be done with 11 sprites total, but if not, it would require 114 sprites which exceeds the max of 64.
 
berighteous
Senior Member

Joined: 18/07/2020
Location: United States
Posts: 110
Posted: 07:48pm 06 Aug 2020
Copy link to clipboard 
Print this post

I would use a framebuffer the size of your screen area + the width of your biggest sprite and then just blit in the screen region if it's fast enough.
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1132
Posted: 08:43pm 06 Aug 2020
Copy link to clipboard 
Print this post

(Assuming you have a later version of the firmware)

The SPRITE READ command has an optional parameter specifying from which page to read. This page doesn't have to be visible.

On the CMM2, sprites can be huge. The original CMM only supported 16x16 sprites.

So far, I have never had a problem with sprites drawn off screen, even thousands of pixels away. Indeed, for some tasks, I have used sprites with a black (hence transparent) boarder and parked them at the edge of the screen, with just the black border 'showing', when not needed.

=============
Look through the SPRITE commands in the manual. There are some amazing gems there. For example, you should be able to animate your sinking depth charges just by using SPRITE SHOW with changing orientation: mirrored left/right, up/down, both and none. If you choose your starting image right (hint: 22.5 degrees ;-), you can get 4 step rotation from a single sprite.
Visit Vegipete's *Mite Library for cool programs.
 
fiziwig
Newbie

Joined: 09/07/2020
Location: United States
Posts: 22
Posted: 12:40am 07 Aug 2020
Copy link to clipboard 
Print this post

  vegipete said  (Assuming you have a later version of the firmware)

The SPRITE READ command has an optional parameter specifying from which page to read. This page doesn't have to be visible.

On the CMM2, sprites can be huge. The original CMM only supported 16x16 sprites.

So far, I have never had a problem with sprites drawn off screen, even thousands of pixels away. Indeed, for some tasks, I have used sprites with a black (hence transparent) boarder and parked them at the edge of the screen, with just the black border 'showing', when not needed.

=============
Look through the SPRITE commands in the manual. There are some amazing gems there. For example, you should be able to animate your sinking depth charges just by using SPRITE SHOW with changing orientation: mirrored left/right, up/down, both and none. If you choose your starting image right (hint: 22.5 degrees ;-), you can get 4 step rotation from a single sprite.


Thanks for that great information. The manual can be a little intimidating, especially in places where it assumes you already know earlier incarnations of the MaxiMite. I've been using pre-rotated images with the assumption that it would be faster than rotating the sprite on the fly. Also, I'm animating 45-degree turns every 4th frame which looks plenty smooth for my tumbling depth charge. With orientation I can get by with 3 sprites instead of 4. Extra logic to save 1 sprite is all. I just don't want to overload any particular frame with processing. That's why I am interleaving/multiplexing the various tasks among different frames.

As for SPRITE READ, the manual gives 5 parameters, sprite #, x, y, w, and h. There is no mention in the manual of an optional page to read from. (Page 82 CMM2 User Manual)

ON EDIT: I tried just giving SPRITE READ an extra parameter and that did work to take it from a different page. So thanks again.
Edited 2020-08-07 11:20 by fiziwig
 
capsikin
Guru

Joined: 30/06/2020
Location: Australia
Posts: 341
Posted: 01:30am 07 Aug 2020
Copy link to clipboard 
Print this post

  fiziwig said  
As for SPRITE READ, the manual gives 5 parameters, sprite #, x, y, w, and h. There is no mention in the manual of an optional page to read from. (Page 82 CMM2 User Manual)

ON EDIT: I tried just giving SPRITE READ an extra parameter and that did work to take it from a different page. So thanks again.


I can confirm it's present in version 5.05.04 page 85 of the manual and was missing in version 5.05.03 page 82 of the manual (which may correspond to when the option was added to the firmware, although I got a 5.05.04 release candidate firmware with my CMM2, it was before 5.05.04 was complete)
Edited 2020-08-07 11:32 by capsikin
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1132
Posted: 05:35am 07 Aug 2020
Copy link to clipboard 
Print this post

OK, never mind my 22.5 degree hint. I was sloppy and mistaken.

I made the attached to test some things and learned some more in the process. The most useful is to use SPRITE READ to change the bitmap of a given sprite. In this example, the depth charge tumbles down the screen using only sprite number 1. Based on the timer, sprite #1 is changed to next suitable image in the animation cycle and automatically appears next time the sprite is drawn. The neat part is you never have to hide a sprite to show the next one.

I went with an 8 step rotation, using 5 distinct sprites. The 3 extra steps are accomplished with mirroring.

mode 1,8

page write 0
cls &h000040  ' darkish blue

' load onto page 0 just so we can see what's there
load png "depth225.png"

' table of sprite numbers to use for each animation step
' negative means mirror left/right
dim sptab(7) = (0,1,2,3,4,-3,-2,-1)

sprite read 1,0,0,14,14,0  ' read from correct page: 0 in this case

astep = 0
mirror = 0
depth = 10

do
 ' time to sink deeper?
 if timer - TY > 50 then
   TY = timer
   depth = depth + 1
   if depth > 580 then depth = 10
   sprite show 1,200,depth,1,mirror
 endif

 ' time to rotate some more?
 if timer - TR > 100 then
   TR = timer
   astep = astep + 1  ' advance to next animation step
   if astep > 7 then astep = 0
   sprnum = sptab(astep)
   if sprnum < 0 then
     mirror = 1
     sprnum = -sprnum
   else
     mirror = 0
   endif
   sprite read 1,sprnum*15,0,14,14
 endif
loop

Visit Vegipete's *Mite Library for cool programs.
 
fiziwig
Newbie

Joined: 09/07/2020
Location: United States
Posts: 22
Posted: 02:14pm 07 Aug 2020
Copy link to clipboard 
Print this post

  vegipete said  OK, never mind my 22.5 degree hint. I was sloppy and mistaken.

I made the attached to test some things and learned some more in the process. The most useful is to use SPRITE READ to change the bitmap of a given sprite. In this example, the depth charge tumbles down the screen using only sprite number 1. Based on the timer, sprite #1 is changed to next suitable image in the animation cycle and automatically appears next time the sprite is drawn. The neat part is you never have to hide a sprite to show the next one.

I went with an 8 step rotation, using 5 distinct sprites. The 3 extra steps are accomplished with mirroring.

..snip..


Very nice piece of code. I didn't realize that a sprite could be shown without first hiding it. Well, it looks like it's time to tear apart my sprite code for about the fourth time. I guess that's what learning a new system is all about.  
 
Print this page


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

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025