Page 1 of 1

Draw images onto sprites

Posted: Sun Feb 12, 2017 3:43 pm
by MrTAToad
At the moment it appears that images cant be drawn into sprites, due to some incompatibility. Would be nice if it was possible though.

Re: Draw images onto sprites

Posted: Sun Feb 12, 2017 7:55 pm
by Peter
MrTAToad wrote:At the moment it appears that images cant be drawn into sprites, due to some incompatibility.
mh, works for me. Could you post a small snippet to reproduce?

Greetings ... PEter

Re: Draw images onto sprites

Posted: Sun Feb 12, 2017 10:31 pm
by MrTAToad
Here we go :

Code: Select all

Global.i spr1,spr2,img

Procedure RenderFrame()
  DisplaySprite(spr1,0,0)
  DisplaySprite(spr2,128,0)
  FlipBuffers()
EndProcedure
  
InitSprite()

If OpenWindow(0,0,0,640,480,"Pseudo 3D")
  If OpenWindowedScreen(WindowID(0),0,0,640,480,0,0,#PB_Screen_NoSynchronization )
    spr1=CreateSprite(#PB_Any,32,32,#PB_Sprite_AlphaBlending)
    spr2=CreateSprite(#PB_Any,32,32,#PB_Sprite_AlphaBlending)
    img=CreateImage(#PB_Any,32,32,32,RGB(0,0,0))

    If StartDrawing(ImageOutput(img))
      Box(0,0,32,32,RGB(255,0,0))
      StopDrawing()
    EndIf
    
    If StartDrawing(SpriteOutput(spr1))
      Debug "In"
      DrawImage(img,0,0)
      Debug "Out"
      StopDrawing()
    Else
    EndIf
    
    If StartDrawing(SpriteOutput(spr2))
      Box(0,0,32,32,RGB(255,255,0))
      StopDrawing()
    EndIf
    
    BindEvent(#PB_Event_RenderFrame,@RenderFrame())
    FlipBuffers()
  EndIf
EndIf
The "Out" text never gets displays as Chrome states :
TypeError: Argument 1 of CanvasRenderingContext2D.drawImage could not be converted to any of: HTMLImageElement, HTMLCanvasElement, HTMLVideoElement, ImageBitmap.
The reason for wanting this is as there are no polygon commands yet, I might use Vector Drawing. But that can only be onto a canvas or image. A canvas is out of the question, so it has to be an image which would then be displayed by a sprite.

Re: Draw images onto sprites

Posted: Sun Feb 12, 2017 11:08 pm
by Peter
use ImageID(img):

Code: Select all

[...]
DrawImage(ImageID(img),0,0)
[...]
Greetings ... Peter

Re: Draw images onto sprites

Posted: Mon Feb 13, 2017 12:18 am
by MrTAToad
Ah yes - it needs one of those!