#How to add background to this code using canvas

23 messages · Page 1 of 1 (latest)

remote narwhal
#

I have to make this game for a school project and i can't for the life of me figure out how to add a background to this code.

#

just for clarity, the background is supposed to be an image, which is already in my VSCode

limpid zodiac
#

does background not work on canvases?

remote narwhal
#

how and where should i add it?

#

speak to me like i'm 5

limpid zodiac
remote narwhal
#

I may be dumb, but this seems to be CSS?

limpid zodiac
#

yes

#

css is generally how you do styling, which includes background colors/images

remote narwhal
#

yeeees, but we're supposed to use a canvas

#

like the canvas API

limpid zodiac
#

you have to do everything on the canvas?

remote narwhal
#

everything is a big word, but inserting an image like that, ye? I've tried something with the constructor but that did not work

limpid zodiac
#

have you checked out this article? i found it from searching "canvas image"

#

mdn is a very good resource for web stuff, including js
it's the de-facto standard

remote narwhal
limpid zodiac
#

you would put style="background: url('...')" in the canvas element in html, or you would assign canvas.styles.background = "url('...')"; in js

remote narwhal
#

Ah, so they're not actually html, it's all done with .TS scenes

#

The only html is in the index

limpid zodiac
#

so you're doing document.createElement("canvas")?

#

you can do setAttribute as a kind of direct equivalent to the html