I am able to create a map using Tiled map editor (http://www.mapeditor.org/) and Load it in corona using this library (http://developer.coronalabs.com/code/gridmap). I created a maze map in tiled map editor, but I don't know how to set the wall to be non walkable. Any help, ideas, links would be much appreciated. Thank you guys.
I have done what you are trying to do with gridmap and tiled.
In Tiled, create the non-walkable parts in a separate layer, then right click that layer in the layers palette. Select 'Layer Properties'. Under the name heading, type Physics:existent. Under the value heading, type true. Save and export as a lua file and include in your project and your done!
I'm not sure how Tiled works or how large your map is.. or if your even still having trouble with this. However, recently I was working on an app where I needed an object to collide with walls (in a room/building). What I did was created the image on the entire room (walls and all) in Photoshop. Then I set it as the background and just used rectangles (display.newRect) to create invisible walls that were displayed beneath my room image. You could try something similar if you are still looking for ideas.
for example:
wall1 = display.newRect(x, y, w, h)
wall2 = display.newRect(x, y, w, h)
wall3 = display.newRect(x, y, w, h)
wall4 = display.newRect(x, y, w, h)
background = display.newImage("", x, y)
physics.addBody(wall1, "static")
...
...
...
In this fasion I was able to map out the walls in the image with actual rectangles and add them to physics so I could collide with them, all the while the user thinks they are colliding with the walls in my image.
Related
So i made simple drawing script
This is what u can draw with it :D
So anyway my question is i wan't to make Erase Tool i already made one but it only removes 1 pixel at time instead i want to make hexagon thing and able to scale it up i just need formula to do that or simple explanation no script required
I want to be look like here I can just fill up pixels but i am not sure about how to deal with scaling part.
Looks like I'm extremely late, but if anybody else needs this help in the future, here's the solution.
You can simply loop for every pixels (a for loop for each y coordinates [as j] embedded in a for loop for each x coordinates [as i]).
Then for each of those loops, check the distance from the cursor's current position to the pixel located at (i, j), and if it's smaller than the chosen radius, change the pixel for a blank one.
The recommended way of checking the distance between two pixels in Roblox would be something like so:
(Vector2.new(x1, y1) - Vector2.new(x2, y2)).magnitude
I have attached 2 photos below. Currently I'm working on simple 2d platformer game; the idea is the player starts from left corner of the screen and if player captures the flag on the right corner of screen player wins and will take the player to the next level.
So I have my player and the ground set up and I applied the gravity and collision bounds to them (picture 1 reflects the situation). Anyways, here's the tricky part, how do I add the collision system to platform1, 2, and 3? I didn't want to use "Tiled Map Editor" or such. Goal is to create the levels using Photoshop & Illustrator and bring those to the game world.
Any thoughts and ideas? Or any advise?
You may want to create a file for each level specifying the location and sizes of the platforms and anything else like background image start location etc. Then work on coding the logic to load that data file and create the physics bodies etc. for the level from there.
an example data file might look like
return {platforms={
{x=200, y=200, width=10, height=20},
{x=200, y=200, width=10, height=20},
{x=200, y=200, width=10, height=20, type="brick"},
},
size={width=300,height=200},
start={x=100,y=200},
goal={x=200,y=100, nextlevel="desert"},
background={image="bluelevel.png"}
}
And then process these files to create the levels in a generic way:
function load_level(filename)
data = dofile(filename)
platforms = {}
for i, p in ipairs(data.platforms) do
body=love.physics.newBody(world, p.x, p.y, "static")
shape=love.physics.newRectangle(p.width, p.height)
fix=love.physics.newFixture(body, shape)
platforms[i] = {body=body, shape=shape, fix=fix}
end
-- .... finish loading data
end
I'm working on an iOS game that uses a Cocos2d TMXTiledMap to read isometric maps produced in the Tiled Application.
In Tiled you can add properties to each image in a tileset (ie. the images displayed in the lower right corner of the screen)
It makes sense to me to use these properties to help determine whether or not this tile type is traversable by the game character.
For instance, if tile 3,5 is using an image of grass then land-based characters can walk there.
Conversely, if tile 4,8 is using an image of water then land-based characters cannot walk there.
I had hoped to accomplish this by creating a property on the grass and water tiles called terrain_type that would be 0 for land and 1 for water. Then (I had hoped) I could access tile 3,5 at runtime and somehow know that tile 3,5 used the grass image with the property of terrain_type=0
Now, I realize that there are other techniques available to accomplish the same thing (Object Layers come to mind) but this seems like the best way to go about it. Especially when you add multiple tile layers and you want to know that say tile 3,5 has both grass AND a wall on it.
My questions: Is this possible? And how would I go about it. Or, am I misunderstanding something about how Tiled and TMXTiledMap are supposed to work?
Much appreciated...
Amazing. I spent a lot of time trying to get this to work before I posted the question and, of course, I figured it out a few hours later. The key is to use the CCTMXMapInfo class.
Anyway, here's the solution since I think this could be useful to others:
In the Tiled application create a map that has a tile layer named
"bottom"
Add a property to each tile image in the section called
"Tilesets" (bottom right corner) by right clicking on each image and
selecting "Tile Properties"
Name the property "terrain_type" and set the value to whatever you like (e.g. terrain_type = 0 for land or terrain_type = 1 for water)
Use these images to paint your tilemap and save
Use this code to read the properties for a single tile at location 3,5:
//read the tile map
TMXTiledMap *tileMap = [CCTMXTiledMap tiledMapWithTMXFile:#"sample_map.tmx"];
//get the bottom layer from the tileMap
CCTMXLayer *bottomLayer = [tileMap layerNamed:#"bottom"];
//get CCTMXMapInfo object -- TMXTiledMap DOES NOT Contain the tile image properties
CCTMXMapInfo * mapInfo = [CCTMXMapInfo formatWithTMXFile: #"sample_map.tmx"];
//get tile id of the tile image used at this coordinate (3, 5) in this layer
int tileID = [bottomLayer tileGIDAt: ccp(3, 5)];
//get the properties for that tile image
NSDictionary *properties = [mapInfo.tileProperties objectForKey:[NSNumber numberWithInt:tileID] ];
//get the terrain_type property
NSString *terrainType = [properties objectForKey:#"terrain_type"];
Okay im working on making a tic tac toe game for one of my game development courses using XNA 4.0 I need to place sprites or some other objects so the game can check if the mouse is being clicked in the correct spots. I am going to use transparent sprites as a kind of button. How do I code them to go to these specific x,y coordinates. The game board is drawn on the background, I have all the coordinates to where to place these sprites. I am just stuck on putting the sprites in the correct positions.
SpriteBatch.Draw has a position parameter. Pass in an appropriately-valued Vector2.
Well if you check the Draw method you will find a parameter for the position.
Check this code sample
spriteBatch.Begin();
Vector2 pos = new Vector2(10, 10);
spriteBatch.Draw(SpriteTexture, pos, Color.White);
spriteBatch.End();
This is how you draw a sprite, with SpriteTexture as the image, on the position x10, y10 with the color White to modulate the texture.
You can also find more informations here.
Keep in mind that there are many overloaded methods to the Draw method. One you can even pass in rotation information and the like. So .Draw(...) has a lot of functionality you can use beyond just placing a sprite.
I'm lost and in need of direction.
We're trying to render a bunch of small images (X) onto a single, unified canvas using imagemagick.
The different X's can be one of five different sizes: 20x20, 40x40, 60x60, 80x80 or 100x100 each. The large image's width is always set to 600, but the height can be regulated as needed.
We can be using as few as 10 or as many as 10,000 X's at any given moment.
Currently, the bare-bones proof of concept we're working with goes something like:
images.each do |image|
image = Magick::Image.read("#{RAILS_ROOT}/public/images/#{image}").first
w = image.columns
h = image.rows
pixels = image.export_pixels(0, 0, w, h, "RGB")
img.import_pixels(x, y, w, h, "RGB", pixels)
x += w
end
...it's simple and stupid, but it does output a series of images merged into one. Almost there ;-)
Does anyone know of an effective algorithm with which we can iterate many X's and place them side-by-side, spanning multiple lines and still optimizing the space? The goal here is to create a single image without white space, constructed by all small images.
As stated, I would love any feedback you guys might have on this. Pointers? Ideas? Examples?
Thanks.
It seems like right now the images are noise. You want to solve a tiles problem. The tiles have some fixed size and you want to put them on a surface of a fixed width and minimum height. This can be done globally with DFS, BFS, A*, etc. You can also look at some local method like simulated annealing or hill climbing, depending if you need to global optimum or just a good, reasonable solution. You can find implementations of these methods in the online source repository for AIMA.
Once you have solved the tile problem you can overlay the images, with as piece of code similar to the one you're showing.