Using AGS graphics functions to paste in tiles

Started by bx83, Thu 23/12/2021 22:57:27

Previous topic - Next topic

bx83

I'm thinking of creating a map, visually represented with static tiles, and programmatically with a 2 dimensional array with a bunch of integers representing different tile types.
How might I put graphics on the screen with the following loop:
1. find the next tile on the map from a level description - it's a tile type 55
2. find the type 55 tile graphic in your tile sheet
3. copy+paste the tile from your tile map to the screen
4. move cursor; get the next tile description from the level file (now it's type 120)
?

And ps, anyone know of any pre-done tile-sets, or tile engines?

Khris

If the tile map sprite is imported as regular sprite, you can create a DynamicSprite from it, then crop it down to the individual tile.
I'd use a global array of dynamic sprites and prepare them at the start of the game (by doing the above in a loop).

When you want to draw a tile to the screen, you get the room's drawing surface, then simply call something like  ds.DrawImage(x * 16, y * 16, tiles[55].Graphic);

Crimson Wizard

#2
Quote from: Khris on Fri 24/12/2021 10:53:38
If the tile map sprite is imported as regular sprite, you can create a DynamicSprite from it, then crop it down to the individual tile.
I'd use a global array of dynamic sprites and prepare them at the start of the game (by doing the above in a loop).

I wanted to mention, as a future alternative, 3.6.0 adds extended DrawImage variant that lets you pass source rectangle coordinates, thus allowing to copy a tile from the source sprite.
The new function looks like
Code: ags

import void DrawImage(int x, int y, int spriteSlot, int transparency=0, int width=SCR_NO_VALUE, int height=SCR_NO_VALUE,
						int cut_x=0, int cut_y=0, int cut_width=SCR_NO_VALUE, int cut_height=SCR_NO_VALUE);

Thus you may save on creating separate tile images.

Retro Wolf

I have an old tile based RPG test project from 5 or so years ago. I'll make it available for you to look at if you want. HOWEVER, I am so rusty with game development and I was never really any good at it, I do not fully remember how it works and looking through the code I don't fully understand it anymore. Should I make it available I will not be able to answer any questions that you have. It has a few interesting features such as pulling the map from a compact png and auto-tiling using bitmasking. There's unfinished stuff on there which only adds to the confusion. I would not envy someone trying to figure it all out. Do you want me to make it available?

bx83



bx83

Got the file okay, but it says the acsprset.spr is corrupt, so I can't open the project.



What version of ags are you running?

Crimson Wizard

#7
Quote from: bx83 on Sat 25/12/2021 03:06:34
Got the file okay, but it says the acsprset.spr is corrupt, so I can't open the project.

What version of ags are you running?

You may check the version if you open Game.agf in any text editor. At the top there will be a line like:
Code: ags
<AGSEditorDocument Version="3.0.3.2" VersionIndex="27" EditorVersion="3.5.1.11">



Checked the project now, it opens fine in the latest stable version.

bx83

Got the latest version of AGS (3.5.1.11) and set it up; didn't work for tilerpg. Tried downloading again, and this time opening with winRAR; didn't work for tilerpg.
Anyone had a similar story or am I, as usual, the only one? :/

Crimson Wizard

#9
Strictly speaking the acsprset.spr itself is not from 3.5.1, as it was saved in 2016 last time, but current version is supposed to open older spritefile too.

EDIT: the error message "Failed to open spriteset file nnn" means that the file could not be opened at all (so it's not because of the bad contents).

Is the file actually in the folder after you unpacked it? What it's size?
Do you open other projects normally?

bx83

#10
acsprset.spr is in the same folder as the Game.agf, and is 434kb.
All games work except this one.

bx83

Fixed - it was to do with the VM path issue.

SMF spam blocked by CleanTalk