New marked map area functions
-
The latest patch (0.2.14) introduced some new map functionality. It is now possible to have named areas on the map. I have done an example of this which is shown below. You will need the map as well. You can download the program using code: EVY73MNDNN
loadMap("demo") image = loadImage( "Untied Games/Knight", false ) sprite = createSprite() setSpriteImage( sprite, image ) setSpriteAnimation( sprite, 8, 11, 10 ) setSpriteLocation( sprite, 25, 30 ) scale = 3 setSpriteCamera( 0, 0, scale ) centreSpriteCamera( 0, 0 ) direction = 1 loop clear() c = controls( 0 ) printAt( 0, 0, "Press A to show collision areas" ) sprite.x_speed = direction * 100 sprite.xscale = direction updateSprites() updateMap() drawMap() drawSprites() checkCollisions( c.a ) update() repeat function checkCollisions( showAreas ) areaNames = getMapAreaNames() for i = 0 to len(areaNames) loop areaName = areaNames[i] area = getMapArea( areaName ) if detectMapAreaCollision( areaName, sprite ) then if areaName == "Wall1" then direction = 1 endif if areaName == "Wall2" then direction = -1 endif endif if showAreas then showArea( area, areaName ) endif repeat return void function showArea( area, areaName ) for i = 0 to len( area ) loop area[i].x = area[i].x * scale + gWidth() / 2 area[i].y = area[i].y * scale + gHeight() / 2 repeat line( area[0], area[1], red ) line( area[1], area[2], red ) line( area[2], area[3], red ) line( area[3], area[0], red ) midy = abs( area[0].y - area[2].y ) / 2 + min( area[0].y, area[2].y ) midx = abs( area[0].x - area[2].x ) / 2 + min( area[0].x, area[2].x ) drawtext( midx, midy, 50, red, areaName ) return void
-
how would i limit a button press unless i'm in a specified map area e.g c.y = false c.y= true if ....
-
@waldron Sorry I don't understand the question
-
@pianofire sorry, say if i only want a characters state to action in certain areas.
so in my case i have a ladder so i press up to climb it but i dont want to be able to press up and enter the state anywhere only in those areas? -
So if you mark your ladder collision boxes as Ladder1, Ladder2 etc you could do something like this:
if detectMapAreaCollision( areaName, sprite ) then canClimb = strBeginsWith(areaName, "Ladder")
and then:
if (canClimb and c.y) then // move sprite up
-
wonderful thank you i presume i can access a lot of actions with this including getting text and sounds to play in certain areas this should keep me busy for a while
-
@pianofire That is awesome.
-
This post is deleted! -
@pianofire i must be doing something wrong am i missing anything? variable?
-
@waldron said in New marked map area functions:
@pianofire i must be doing something wrong am i missing anything? variable?
OK I was missing the area name variable but still not working.
-
@waldron sorry it was only a code snippet. Have a look at the checkCollisions function in the post at the top
areaNames = getMapAreaNames() for i = 0 to len(areaNames) loop areaName = areaNames[i] area = getMapArea( areaName ) if detectMapAreaCollision( areaName, sprite ) then
-
@pianofire I added that part still no joy il wait till iv got a bit more time on my hands maybe missing something silly