I ask again, how do I reach PositionToTileX / Y in scripting?

0 favourites
  • 4 posts
  • I posted this in How Do I, yet they told me to post it in scripting. I think i'm missing a import function? Because asking the TileMap to use function PositionToTileX is giving me a function not found: The tempTileMap is filled... I can use other functions such as GetTileAt()... Anyway the original post:

    So everywhere I read that you can use PositionToTileX function... yet this function is not accessible in my code... it says:

    Error: tempTileMap.PositionToTileX is not found
    

    tempPlayer is found, tempTileMap is found, if I use static numbers on the getTileAt it works...

    var tempPlayer = runtime.objects.Player.getFirstInstance();
    	var tempTileMap = runtime.objects.TilemapLevel.getFirstInstance();
    	var tempTileId = tempTileMap.getTileAt(tempTileMap.PositionToTileX(tempPlayer.x), tempTileMap.PositionToTileY(tempPlayer.y));
    

    So where do I get PositionToTileX? I'm using Construct 3 since yesterday :)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • There is no PositionToTileX in the Tilemap API in scripting. But you have all necessary to make your own.

    You have to look at the manual:

    https://www.construct.net/en/make-games/manuals/construct-3/scripting/scripting-reference/plugin-interfaces/tilemap

  • Absolutely do use the manual. Sometimes certain APIs are not (yet) available, which is a bit of a bummer, and you have to make your own functions for certain things.

    let tilemap = runtime.objects.Tilemap.getFirstPickedInstance();
    let mouse = runtime.mouse.getMousePosition();
    
    let tile = positionToTile(tilemap, mouse[0], mouse[1]);
    
    tilemap.setTileAt(tile.x, tile.y, 0);
    
    	function positionToTile(tilemap,x,y) {
    	let gridX = tilemap.tileWidth;
    	let gridY = tilemap.tileHeight;
    	
    	let resultX = Math.floor((x - tilemap.x)/gridX);
    	let resultY = Math.floor((y - tilemap.y)/gridY);
    	
    	if (resultX < 0 || resultY < 0 || resultX > tilemap.width/gridX || resultY > tilemap.height/gridY) {
    		return "outside Tilemap";
    	} else {
    		return {"x": resultX, "y": resultY};
    	}
    	
    }
    
  • There is no PositionToTileX in the Tilemap API in scripting. But you have all necessary to make your own.

    You have to look at the manual:

    https://www.construct.net/en/make-games/manuals/construct-3/scripting/scripting-reference/plugin-interfaces/tilemap

    Yeah I looked through the manual but could not find it in there.. yet i found this PositionToTileX function in some construct post...

    Absolutely do use the manual. Sometimes certain APIs are not (yet) available, which is a bit of a bummer, and you have to make your own functions for certain things.

    Thanks for the function setup. I already had something similar going on... But I thought I just did not had a main part of the scripting understood... So reason enough to ask what I was doing wrong...

    Thanks champs!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)