Draw images onto sprites

Got an idea for enhancing SpiderBasic? New command(s) you'd like to see?
User avatar
MrTAToad
Posts: 291
Joined: Sun Apr 20, 2014 11:43 am
Location: Chichester, England
Contact:

Draw images onto sprites

Post 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.
User avatar
Peter
Posts: 1197
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Draw images onto sprites

Post 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
User avatar
MrTAToad
Posts: 291
Joined: Sun Apr 20, 2014 11:43 am
Location: Chichester, England
Contact:

Re: Draw images onto sprites

Post 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.
User avatar
Peter
Posts: 1197
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Draw images onto sprites

Post by Peter »

use ImageID(img):

Code: Select all

[...]
DrawImage(ImageID(img),0,0)
[...]
Greetings ... Peter
User avatar
MrTAToad
Posts: 291
Joined: Sun Apr 20, 2014 11:43 am
Location: Chichester, England
Contact:

Re: Draw images onto sprites

Post by MrTAToad »

Ah yes - it needs one of those!
Post Reply