Gameboy Development Forum

Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)

You are not logged in.

Ads

#1 2021-08-31 12:41:09

freshdeus
New member
Registered: 2021-08-31
Posts: 4

ZGB Engine: Tile swapping

Hi,

I´m kinda depressed (and annoyed), because every piece of information I found  wasn´t  very helpful.

My question: How can I change background tiles (with the ZGB Engine) of a level permanently? I looked at several examples / tutorials and the GBDK documentation, but nothing worked quite right.

I know there is the ReplaceTile function, but the function is setup to work with sprites. How can I use it for swapping tiles of the same background tileset?

My idea: I have a tileset, which has items as tiles. When the player sprite stands over such a tile and a button is pressed, the tile switches to another tile of the same tileset (an empty one) as if the item was picked up. I want to try this idea, because the sprite limit is giving me headaches. Ton of games use this trick (Tetris, Chessmaster, Castle Quest), but I am not skilled enough (learning C at the same time) to get it working myself. The important part is swapping the tiles. I got tile checking already working (for example: stairs).  So I hope to find some advice here. Thank you very much!

Offline

 

#2 2021-08-31 16:15:35

toxa
Member
Registered: 2020-02-13
Posts: 305

Re: ZGB Engine: Tile swapping

It is hard to replace tile id in the tile map in ZGB, because it is in ROM and you don't control the painting. BUT. you may put some unique tile onto the tile map (it may look as any other) and then reload tile data for that tile with set_bkg_data(). all tiles with that id will change their appearance. if it is a unique tile, then only one tile will change.

Offline

 

#3 2021-09-05 03:12:35

bbbbbr
Member
Registered: 2019-03-04
Posts: 124

Re: ZGB Engine: Tile swapping

If your level is large enough to scroll and the player may return to the area at a later time, then (if you have enough free RAM) you could try copying the level into RAM so that you're able to modify it as it's being played. Keeping the level size smaller might make this easier to do.


If the tiles you want to change either won't go off-screen or they player can't/won't return to them, you could try replacing them "on-screen" only.

Using direct gbdk functions: set_bkg_tiles() and set_bkg_tile_xy()
https://gbdk-2020.github.io/gbdk-2020/d … e28f16e976
https://gbdk-2020.github.io/gbdk-2020/d … bdcf532659

Or, using ZGB functions:
https://github.com/bbbbbr/plutoscorner/ … r_3.c#L103
https://github.com/bbbbbr/plutoscorner/ … tils.c#L27

Last edited by bbbbbr (2021-09-05 18:00:36)

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson