Sprite draw to Sprite?

Just starting out? Need help? Post your questions and find answers here.
User avatar
zxtunes.com
Enthusiast
Enthusiast
Posts: 375
Joined: Wed Apr 23, 2008 7:51 am
Location: Saint-Petersburg, Russia
Contact:

Sprite draw to Sprite?

Post by zxtunes.com »

possible to draw sprites in other sprites?

I have a polygon. I can change its shape (distortion and size), 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.

Image
User avatar
zxtunes.com
Enthusiast
Enthusiast
Posts: 375
Joined: Wed Apr 23, 2008 7:51 am
Location: Saint-Petersburg, Russia
Contact:

Re: Sprite draw to Sprite?

Post by zxtunes.com »

Example:

Code: Select all

   ClearScreen(#black)
   StartDrawing ( SpriteOutput( polygon ) )

             DisplayTransparentSprite( texture, 0, 0 ... )

   StopDrawing()

   TransformSprite ( Polygon, .... )
    DisplayTransparentSprite( Polygon, .... )
as a result Sprite "texture" not drawn in the sprite "Polygon", but is drawn on the main screen.
void
Enthusiast
Enthusiast
Posts: 116
Joined: Sat Aug 27, 2011 9:50 pm
Location: Washington, USA

Re: Sprite draw to Sprite?

Post by void »

Unfortunately, startdrawing() is only for the 2d drawing library, so spriteoutput() is only relevant for things like line(), box(), etc.

I've requested in the past for a mechanism to render sprites onto a sprite as the target buffer, but it isn't currently possible with the PB libraries.
citystate
Enthusiast
Enthusiast
Posts: 638
Joined: Sun Feb 12, 2006 10:06 pm

Re: Sprite draw to Sprite?

Post by citystate »

there used to be a command UseBuffer() that would substitute a sprite for the screen, but it's been depreciated - you might get more bang for your buck using an image rather than a sprite, and then draw it onto a sprite as required
there is no sig, only zuul (and the following disclaimer)

WARNING: may be talking out of his hat
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Sprite draw to Sprite?

Post by netmaestro »

GrabDrawingImage, a relatively new command (v4.4 iirc) is what you want:

Code: Select all

InitSprite():InitKeyboard()

OpenWindow(0,0,0,640,640,"Press ESC to exit...",#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),0,0,640,640)

CreateSprite(0, 256,256)
CreateSprite(1, 512,512)

StartDrawing(SpriteOutput(0))
  DrawingMode(#PB_2DDrawing_Gradient)
  BackColor($000099)
  FrontColor($dd0000)
  LinearGradient(0, 0, 0, 256) 
  Box(0,0,256,256)
StopDrawing()

; We want sprite 0 drawn on sprite 1, so step 1: Grab the drawing image
StartDrawing(SpriteOutput(0))
  this = GrabDrawingImage(#PB_Any,0,0,256,256)
StopDrawing()

; Step 2: Draw the grabbed image to sprite 1:
StartDrawing(SpriteOutput(1))
  Box(0,0,512,512,RGB(255,255,223))
  DrawImage(ImageID(this),128,128)
StopDrawing()

Repeat
  While WindowEvent():Wend
  ClearScreen(0)
  DisplaySprite(1, 60,60)
  FlipBuffers()
  ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
BERESHEIT
void
Enthusiast
Enthusiast
Posts: 116
Joined: Sat Aug 27, 2011 9:50 pm
Location: Washington, USA

Re: Sprite draw to Sprite?

Post by void »

netmaestro wrote:GrabDrawingImage, a relatively new command (v4.4 iirc) is what you want:
That approach doesn't look like it lets you make use of any of the features available to sprites, such as rotation, scaling, blending modes, etc.
Pot Noodle
Enthusiast
Enthusiast
Posts: 202
Joined: Sat Feb 18, 2012 10:21 pm
Location: Leicestershire

Re: Sprite draw to Sprite?

Post by Pot Noodle »

That approach doesn't look like it lets you make use of any of the features available to sprites, such as rotation, scaling, blending modes, etc.
It would if you then converted it to a 3D sprite!
P.N.
Post Reply