Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

ok so apparently it was because i didnt set map as a variable but now it just doesnt do anything

here is the new one

var character = {

    x: 60,
    y: 60
};

var oldpos = {
oldx: 60,
oldy: 60
};

var background = getMap("map");
paper(4);

exports.update = function () {
if (background.get(character.x, character.y) ==! null) character.x = oldpos.oldx;
if (background.get(character.x, character.y) ==! null) character.y = oldpos.oldy;
oldpos.oldx = character.x;
oldpos.oldy = character.y;
    if (btn.right) character.x += 1;
    if (btn.left)  character.x -= 1;
    if (btn.up)    character.y -= 1;
    if (btn.down)  character.y += 1;

    cls();
    draw(background, 0, 0);
    sprite(206, character.x, character.y);
};

I think you are mixing pixel position (sprite and draw) and tile position (background.get). You need to convert pixel to tile by dividing the pixel coordinates by the tile sizes (available from settings.tileSize). Or, inversely, if you want your character to move in tile increments, modify the last line as follow:|

sprite(206, character.x * settings.tileSize.width, character.y * settings.tileSize.height);