Main Menu

Images, Sprites, Bank, Memory & co

Started by ale870, September 12, 2006, 03:32:38 AM

Previous topic - Next topic

ale870

Hi, I'm a new PlayBasic user.
I discover, day-by-day, new exciting possibilites  ;D

I found many examples, but not much documentation about some basic concepts.

Can someone explain me (clarify my ideas!   ::)) about the difference between Images, Sprites, Banks, Memory FX, etc...
I know the basic concepts: I know the difference between an Image and a sprite, but I cannot understand how PlayBasic manages them.

For example:

Dim animaz(1)

Load_Anim(animaz(), "EXPLOSION02", 25, 64, 64, $000000)

currentFrame = 0

setFps(30)

Do
Cls $ffffff

DrawImage animaz(currentFrame), 30, 30, 1

currentFrame = currentFrame + 1
If currentFrame>=animaz(0)-1 Then currentFrame = 0

Text 10, 10, FPS()

DrawAllSprites

Sync
Loop



////////////////////////////////////////////////////////////////////////////////////////////////////

Psub Load_Anim(AnimFrames(),File$,Frames,FrameWidth,FrameHeight,TransparentColour)
index = LoadNewImage(file$ + ".png")

Dim AnimFrames(Frames)
AnimFrames(0) = Frames

RenderToImage index

For lp=1 To frames
freeImage = GetFreeImage()

AnimFrames(lp) = freeImage
GetImage freeImage, Xpos, Ypos, Xpos+Framewidth, Ypos+FrameHeight
ImageMaskColour freeImage,TransparentColour

Xpos=Xpos+Framewidth
If Xpos=>width Then Xpos=0: Ypos=Ypos+FRameHeight
Next
RenderToScreen
DeleteImage index
EndPsub



I wrote this code using some code taken here and there in the examples.

The funny thing for me is image management: is it the correct way to manage sprites? I need to create an explosion, but I think I created an animated image, not animated sprite  ???

More, I tried to use Alpha-channel in PNG and I found I could create two images (a file for sprite and a file for alpha) but I found some examples about SpriteFX. How can I convert/modify previous code to accept FX sprites?

And when I red about FX I red about memory: is it the same "object" of "banks", or not?

My mind is confused...  ??? ??? ???


--Alessandro

kevin

   In your example, your not using sprites.  Just images as sprites.  Which is perfectly viable.

   You should think of an image as a picture.  It has no position or orientation.

   A sprite is the 'character'.  It has position, orientation and an associated image that creates each sprites visual representation.  Each sprite can render it's associate image with it's own custom draw mode preferences.   Which allows many sprites to use the same image.

Sprites
     |
    \/
  Images
     |
    \/
Screen




ale870

Thank you!

Just to fix my ideas:
1) when I use a FXImage, am I using a "bank"?
2) Banks access functions are the same (and same concept) as direct memory access? Same speed? Or not?

Thank you again  :)!

--Alessandro

kevin

#3
Quote1) when I use a FXImage, am I using a "bank"?

  Yes, It's conceptually a bank you can draw to and from.   Preparing an  FX image converts the image buffer from it's video memory state to a system memory state.

Quote2) Banks access functions are the same (and same concept) as direct memory access? Same speed? Or not?

   Yes the concept is the same.  The main difference is that banks, protect the form user addressing memory outside of the allocated memory block.    Direct memory accesses don't.   Speed wise, there's probably not much difference ATM, it's more about convenience.     

ale870

--Alessandro

ale870

Another question about collisions: do I need to create a shape to manage sprite collisions? is it obbliged? or I can manage sprite collision only using the sprite-self?

Thank you!
--Alessandro

kevin


There are 7 collision modes. You pick what mode you want to use


ale870

Where can I find a brief overview of such modes? (in the help menu I cannot find a brief list, just to help me to speed-up the first approach).

Thank you!
--Alessandro

kevin


ale870

--Alessandro