SpriteEngine: Atlas,View,Layer,HotSpot,Flip,Animation,FX

Share your advanced PureBasic knowledge/code with the community.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: SpriteEngine: Atlas,View,Layer,HotSpot,Flip,Animation,FX

Post by jassing »

Running the example; I got an IMA on
\Texture=CreateTexture(#PB_Any, Width, Height)
Poshu
Enthusiast
Enthusiast
Posts: 459
Joined: Tue Jan 25, 2005 7:01 pm
Location: Canada

Re: SpriteEngine: Atlas,View,Layer,HotSpot,Flip,Animation,FX

Post by Poshu »

Mythros wrote:Still, I want to stick with what I know. I don't like upgrading alot.
More reason to go 5.20 then, it's LTS :D
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: SpriteEngine: Atlas,View,Layer,HotSpot,Flip,Animation,FX

Post by luis »

Mythros wrote:Can you PLEASE make this work with version 5.1?
IMHO asking someone to make his T&T work with past versions of the compiler is going too far.
Install the beta, try the code, decide if you like it, if the answer is yes try to understand how it works (it's one thing programmers do) and convert it for PB 5.11 if it's possible.
You will get the benefit of knowing the code and you will acquire the ability to modify and enhance it. All this in exchange for some time well spent.
Time eddy should probably spend on something else instead.

On a side note: one nice thing about PB being not well known is that when you find code in another language elsewhere you need to understand it at least a little and then convert it.
It's full of copy/paste programmers in C/C+ forums, and I think this is very unhealthy for them and for the programming world in general.
"Have you tried turning it off and on again ?"
A little PureBasic review
Mythros
Enthusiast
Enthusiast
Posts: 306
Joined: Mon Aug 19, 2013 3:28 pm

Re: SpriteEngine: Atlas,View,Layer,HotSpot,Flip,Animation,FX

Post by Mythros »

I'm not downloading 5.20. I am learning how to use what I am comfortable with tyvm.. -.-
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Re: SpriteEngine: Atlas,View,Layer,HotSpot,Flip,Animation,FX

Post by eddy »

Updated
- updated: Example 1
- updated: SetSpriteFrame with new "turned frame" parameter
- added: Skew & Deform Sprite
- fixed: FlipSprite updates hotspot position now
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Sprite3D: Atlas,View,Layer,HotSpot

Post by Danilo »

eddy wrote:Image
Some problems on Mac OS X, for example the text "Atlas" is not displayed.
Sometimes I get weird stuff displayed. Not at every start, maybe every 3rd or 4th run.

Image Image

Find the differences in the images. ;)
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Re: SpriteEngine: Atlas,View,Layer,HotSpot,Flip,Animation,FX

Post by eddy »

Calculation of Sprite Quad position is correct
but 2DDrawing on TextureOutput seems to be buggy on MacOSX:
  • RGB or RGBA color is reverse :?
  • DrawText does not work :?
I'll post a tiny sample code to confirm this issue.
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
Thorium
Addict
Addict
Posts: 1305
Joined: Sat Aug 15, 2009 6:59 pm

Re: SpriteEngine: Atlas,View,Layer,HotSpot,Flip,Animation,FX

Post by Thorium »

eddy wrote: but 2DDrawing on TextureOutput seems to be buggy on MacOSX:
RGB or RGBA color is reverse :?
Thats nor realy a bug. On MacOSX the channel order is different. On Windows ist BGR on MacOSX it's RGB.
I havent looked at you code, it's only a bug if you use the RGB command, that should allways work correctly.
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: SpriteEngine: Atlas,View,Layer,HotSpot,Flip,Animation,FX

Post by Danilo »

Thorium wrote:
eddy wrote: but 2DDrawing on TextureOutput seems to be buggy on MacOSX:
RGB or RGBA color is reverse :?
Thats nor realy a bug. On MacOSX the channel order is different. On Windows ist BGR on MacOSX it's RGB.
I havent looked at you code, it's only a bug if you use the RGB command, that should allways work correctly.
He is using RGB()/RGBA() for all colors. Maybe channel order is different from desktop GUI with 3D Engine (OpenGL).
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Re: SpriteEngine: Atlas,View,Layer,HotSpot,Flip,Animation,FX

Post by eddy »

preview
- layer shadow casting
- reorder layers and shadows
Image
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Re: SpriteEngine: Atlas,View,Layer,HotSpot,Flip,Animation,FX

Post by eddy »

updated
- SetLayerOrder
- SetLayerShadow
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
zxtunes.com
Enthusiast
Enthusiast
Posts: 375
Joined: Wed Apr 23, 2008 7:51 am
Location: Saint-Petersburg, Russia
Contact:

Re: SpriteEngine: Atlas,View,Layer,HotSpot,Flip,Animation,FX

Post by zxtunes.com »

Thank you Eddy. Very interesting engine.

But I have to say - you have it too complicated. You made layers and animation - and I suddenly did not know how I upload a regular single sprite. The fact that PB makes a team, you're doing with a 10. And it spawns a bunch of dependencies.

For example, I asked a Hot Spot for a sprite, and it affected the other instances.

It's very unusual.

Your example is very complicated. I recommend to do something more simple and real-time traffic - otherwise spectacular work.

Ideally, you need one powerful example that shows all the features. And as a few simple examples.

And now I'm going to ask the most important question for me.
Is it possible to draw sprites in other sprites?

Let's say I have a polygon. I can change its shape (distortion), that would set up an even rectangle for the image of the projector. And I want to display this polygon rotating about its axis in the sprite.
User avatar
zxtunes.com
Enthusiast
Enthusiast
Posts: 375
Joined: Wed Apr 23, 2008 7:51 am
Location: Saint-Petersburg, Russia
Contact:

Re: SpriteEngine: Atlas,View,Layer,HotSpot,Flip,Animation,FX

Post by zxtunes.com »

I noticed a bug. Skew mix sprite from the center. It turns out that the Skew + Rotate = useless.
At the same time, Scale + Rotate working properly.
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: SpriteEngine: Atlas,View,Layer,HotSpot,Flip,Animation,FX

Post by idle »

I had a look on linux x64 with Pb5.22 LTS

it had an IMA on line 866 with GetMeshData
changing line 864 to

Code: Select all

   Dim vertices.PB_MeshVertex(MeshVertexCount(\Mesh))
made the problem go away

although the colors in the test aren't the same as your example
Image
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Re: SpriteEngine: Atlas,View,Layer,HotSpot,Flip,Animation,FX

Post by eddy »

zxtunes.com wrote:I noticed a bug. Skew mix sprite from the center. It turns out that the Skew + Rotate = useless.
At the same time, Scale + Rotate working properly.
There's no bug

Code: Select all

; ******************************************
; EXAMPLE1 - ROTATING SKEW SPRITE
; ******************************************
CompilerIf #PB_Compiler_IsMainFile
   DisableExplicit
   If InitEngine3D()=0 Or InitSpriteEngine()=0
      MessageRequester("Init", "Failed!")
      End
   EndIf
   
   AntialiasingMode(#PB_AntialiasingMode_None)
   
   win=OpenWindow(#PB_Any, 0, 0, 800, 600, "Sprite Engine FX", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
   OpenWindowedScreen(WindowID(win), 0, 0, WindowWidth(win), WindowHeight(win))
   
   ;draw sprite image atlas 
   fontID=LoadFont(0, "Arial", 22, #PB_Font_Bold|#PB_Font_HighQuality|#PB_Font_Italic)
   spriteAtlas=CreateAtlas(#PB_Any, 128, 128)
   If StartDrawing(AtlasOutput(spriteAtlas))     
      DrawingMode(#PB_2DDrawing_AlphaBlend)
      FrontColor(RGBA(200, 110, 20, 255))
      Box(0, 0, 128, 128)     
      StopDrawing()
   EndIf
   ;define sprite frames (with centered hotspot)
   squareFrame=SetAtlasFrame(spriteAtlas, #PB_Any, 5, 5, 16, 64,8,32)
   dotFrame=SetAtlasFrame(spriteAtlas, #PB_Any, 5, 5, 2,2 ,1 ,1)
   
   ;create front view
   frontView=CreateView(#PB_Any, RGB(62, 62, 62), #False, 0, 0, 64.0, 85.34)
   Debug "View Camera="+ViewCameraY(frontView)+","+ViewCameraX(frontView)+","+ViewCameraWidth(frontView)+","+ViewCameraHeight(frontView)
   If frontView
      ;add layer
      newLayer=CreateLayer(#PB_Any, frontView, AtlasID(spriteAtlas))
      
      ;dot sprites
      dot=CreateAnimatedSprite(#PB_Any, newLayer, 224, 153, dotFrame)
      SetSpriteColor(dot,RGBA(10, 156, 63, 255))
      
      ;skew sprites
      rotatingSprite=CreateAnimatedSprite(#PB_Any, newLayer, 224, 153, squareFrame)
      SkewSprite(rotatingSprite, 32, -32)
   EndIf
   
   
   Repeat
      RenderSprites()
      RenderWorld()
      RotateSprite(rotatingSprite,1)
      FlipBuffers()
   Until WaitWindowEvent(1)=#PB_Event_CloseWindow
   End
CompilerEndIf
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
Post Reply