Skip to content

How to Spawn Cards in a Room

DuncanSzabaga edited this page Nov 17, 2025 · 1 revision

There are two ways to spawn a card:

This implementation includes exported variables that is very useful for templating.

  1. Spawn it directly from the Room Editor (manual placement) (drag and drop)
  2. Spawn it through GML code (runtime creation)

Which should I use where?

  • Use drag & drop when:

    • You want a specific card permanently in a specific room.

    • You are designing static UI / scenes.

    • You want a quick visual setup and minimal code.

  • Use GML spawning when:

    • Cards change often (drawing, discarding, shuffling, effects).

    • You need scaling/positioning to adapt to screen size or layout.

    • You’re using IDs from JSON and building everything from data.

    • You want reusable UI elements that show “whatever card is selected right now.”

  • Use a mix when:

    • You drop a “container” object in the room (like a hand area or card slot),

    • Then have that object spawn displayCard instances in Create/Step event.

  • Both methods use the same displayCard object with additional steps. (located in ./CardPage_obj/displayCard/)

  • Spawning a card requires filling out exported variables.

1. Spawn with drag and drop

Just drag and drop Image

  • When you run the game, it will always show a back of a card by default since we haven't specified which one we want it to show.
  • In order to make it show a specific card:

Double click on it and then to go Variables

Image
  • You will see that there are a couple exported variables:
  • Edit 1 to change the card to a specific one using the id of that card. See IDs in ./datafiles/sample.json
  • Edit 2 if you want the card's details to be drawn
  • Edit 3 if you need to show it in a specific size (default at 100% or 1)
    • remember you won't see it changing the size in the editor, in the editor you will still see it as the default size (100% or 1), so you will need to change the size in the editor as well so it will be matched what you see in the editor and what it's actually rendered.

example of changing the size (Editing 3):

  • all of these need to match
Image

If you change the id properly, you should see the card you want when you run the game

Image Image

2. Spawn through GML code (runtime creation)

Image
  • you need to adjust where it will be spawned by editing x and y.
  • again 1, 2, and 3 are just the same as the drag and drop, since the object is still the same.
  • just need to be careful with 4, make sure that this name of an instances layer in the room existing.
Image

After the code is executed the card will appear in the room.

Clone this wiki locally