Scrolling Game Development Kit Forum
SGDK Version 2 => Help, Errors, FAQ => Topic started by: Tanja on 2008-01-16, 03:52:44 PM
-
i am so sorry! there was once a thread but i don't find it anymore. there is a tut but i ask you because time is running out for me....
how to define this tileshape??
(lower half solid, upper half not)
-
oh, and this.
please don't say: split your tileset into smaller tiles. this tileset has actually 35 tiles. at the moment i use it in four different versions. makes 140 tiles. soon it will be some more versions.
i really don't want them to quadruple.
-
Either create a new code object under TileShapes.cs called BottomHalf.cs (and delete the default code it puts in) or edit TileShapes.cs itself.
In it (at the bottom, if you edit TileShapes.cs), put this code:
public class BottomHalf : TileShape
{
private static BottomHalf m_Value = new BottomHalf();
public static BottomHalf Value
{
get
{
return m_Value;
}
}
public BottomHalf()
{
}
public override short GetTopSolidPixel(short width, short height, short min, short max)
{
return (short)(height / 2);
}
public override short GetBottomSolidPixel(short width, short height, short min, short max)
{
return (short)(height-1);
}
public override short GetLeftSolidPixel(short width, short height, short min, short max)
{
return (max > height / 2 ? 0 : short.MaxValue);
}
public override short GetRightSolidPixel(short width, short height, short min, short max)
{
return (max > height / 2 ? (short)(width-1) : short.MaxValue);
}
}
The advantage of editing TileShapes.cs is you don't have extra files. However, if you ever needed to reset the code in the project, this would disappear unless it were in a separate file.
-
I think the "max > height / 2" should be "max >= height / 2" in both cases.
-
IDEA!
A little editor thing, where you have a brush, and you colour an invisible mask over tiles, (u can see them in the editor but not in game) with the painted pixels being solid and the pixels u didnt paint normal, non solid pixels. this would allow some awesome tile shapes...
-
yeah, as i said in the other thread about importing these custom tileshapes.
but i guess this function would use much more computer power than defining the shape through script.
-
IDEA!
A little editor thing, where you have a brush, and you colour an invisible mask over tiles, (u can see them in the editor but not in game) with the painted pixels being solid and the pixels u didnt paint normal, non solid pixels. this would allow some awesome tile shapes...
Tile shapes are supposed to be simple and quick, not awesome ;). It seems a shame to put so much work into a shape, which the player usually doesn't notice anyway. Usually an approximate shape is good enough, don't you think? I have to laugh thinking about it... can you imagine someone saying, "Woah! did you see that!? My player moved up 4 pixels instead of 2 when I moved to the right 5 pixels on this tile... awesome shape!" :D (I don't mean to make fun, but I think you could see the humor in that, and humor is a good thing.) Anyway, I can see the value in it, but there's a significant cost to implement such an idea, so there would have to be some really important benefits to do something like this. (As I said in the other thread, I had this for a while and I took it out.)
-
Tile shapes are supposed to be simple and quick, not awesome Wink. It seems a shame to put so much work into a shape, which the player usually doesn't notice anyway. Usually an approximate shape is good enough, don't you think? I have to laugh thinking about it... can you imagine someone saying, "Woah! did you see that!? My player moved up 4 pixels instead of 2 when I moved to the right 5 pixels on this tile... awesome shape!" Cheesy (I don't mean to make fun, but I think you could see the humor in that, and humor is a good thing.) Anyway, I can see the value in it, but there's a significant cost to implement such an idea, so there would have to be some really important benefits to do something like this. (As I said in the other thread, I had this for a while and I took it out.)
roflmao yeh that's pretty funny. :p
Was playing the game "N" when I thought of it, and it has like quarter-pipe tiles, and all different angles of slopes and stuff, and it has some cool maneuvers that I wanna try and put into a game... for example you can jump from walls, the longer you hold the jump button the higher you jump... (there is eventually a limit, its not like flying lol, but it allows for more control over the sprite in-game) when you jump, you don't jump up, you jump perpendicular to the ground, so you can be running up a quarter pipe and jump when it's almost vertical and you can reach places you can't normally get to... it's actually a really cool game. :D
yeah, as i said in the other thread about importing these custom tileshapes.
lmao, sorry I didn't read that thread yet. :p
-
You can write functions that create solidity as angles and curves etc. using SIN and COS functions, etc. All the other things you talked about are also easy (relatively) with so many possible rules and coding available. Jumping higher with longer button presses is something I implemented in a test program when I was ripping Mario graphics awhile ago (Mario has that same effect).
-
You can write functions that create solidity as angles and curves etc. using SIN and COS functions, etc.
cool, i need to remember that. i might have guessed.
-
when i insert the code from durnurd, this error message occurs:
Type of conditional expression can't be determined because 'int' and 'short' both implicitly convert to each other
public class BottomHalf : TileShape
{
private static BottomHalf m_Value = new BottomHalf();
public static BottomHalf Value
{
get
{
return m_Value;
}
}
public BottomHalf()
{
}
public override short GetTopSolidPixel(short width, short height, short min, short max)
{
return (short)(height / 2);
}
public override short GetBottomSolidPixel(short width, short height, short min, short max)
{
return (short)(height-1);
}
public override short GetLeftSolidPixel(short width, short height, short min, short max)
{
return (max > height / 2 ? 0 : short.MaxValue);
}
public override short GetRightSolidPixel(short width, short height, short min, short max)
{
return (max > height / 2 ? (short)(width-1) : short.MaxValue);
}
}
-
I'm actually interested in creating tile shapes that have the corners clipped off. That is to say, they would have diagonal values where the corners would be. This is so that there could be a bit of easing whenever the player runs into a corner. Right now, when the player attempts to go through a passage that is the same size as them, they have to hit it dead on. (or they bump into the edges around it) If I was able to bevel the corners near passages like this, it would be possible for me to "ease" or "guide" the player into these tight spaces.
-
I'm actually interested in creating tile shapes that have the corners clipped off. That is to say, they would have diagonal values where the corners would be. This is so that there could be a bit of easing whenever the player runs into a corner. Right now, when the player attempts to go through a passage that is the same size as them, they have to hit it dead on. (or they bump into the edges around it) If I was able to bevel the corners near passages like this, it would be possible for me to "ease" or "guide" the player into these tight spaces.
I imagine it might also be easier to get into a passage if the tiles are slightly larger than the player, which would make the gap also slightly larger.when i insert the code from durnurd, this error message occurs:
Type of conditional expression can't be determined because 'int' and 'short' both implicitly convert to each other
Alright, time to actually test...
Change this line:
return (max >= height / 2 ? 0 : short.MaxValue);
to this:
return (max >= height / 2 ? (short)0 : short.MaxValue);
It apparently has to know what type of value '0' is and it can't tell between an int or a short, and implicit conversions confuse it because they both mean the same thing.
-
after changing this line the game compiles. but when i use this definition, the game crashes either when i hit the tile (first try), or a while after i've hit it (second try).
-
after changing this line the game compiles. but when i use this definition, the game crashes either when i hit the tile (first try), or a while after i've hit it (second try).
I tried it on the sample project and for awhile it worked fine, then it randomly shot off to the opposite side of the screen. I'm not sure why you got the error, though. I am not sure if the sample was just lucky for it to work properly such that it didn't shoot off the end of the screen or what, but the problem is that GetRightSolidPixel expects short.MinValue instead of short.MaxValue if there is no right solid pixel. So change this:
return (max >= height / 2 ? (short)(width-1) : short.MaxValue);
to this
return (max >= height / 2 ? (short)(width-1) : short.MinValue);
(in GetRightSolidPixel)
-
this tile works now fine. i tried to make TopHalf, RightHalf and LeftHalf. but it seems i do just not understand enough. now i've realized that when there is no 0; there is a function. but i don't know what the "?" means and how it is with MinValue and MaxValue. writing functions is not easy when you don't know what you do.
if you don't mind, could you please give me an example for TopHalf? :hurt:
-
Yes, the ternary operator confuses a lot of people who are new to coding. It's like "Where the heck did that come from?"
Basically the '?' is the first half of the ternary operator and the ':' is the second half. It works something like this:
boolean ? expression_1 : expression_2
Which evaluates to expression_1 if boolean is true, or expression_2 if boolean is false. It's really just shorthand in most cases. For example,
return (max >= height / 2 ? (short)(width-1) : short.MinValue);
either returns (short)(width-1) if max is greater than or equal to half of height, or returns short.MinValue otherwise. It could be written as
if (max >= height / 2)
return (short)(width-1);
else
return short.MinValue;
but it's sometimes simpler to write things like this on one line without needing to write unnecessary code.
Here's a sample for TopHalf (not tested).
public class TopHalf : TileShape
{
private static TopHalf m_Value = new TopHalf();
public static TopHalf Value
{
get
{
return m_Value;
}
}
public TopHalf()
{
}
public override short GetTopSolidPixel(short width, short height, short min, short max)
{
return (short)0;
}
public override short GetBottomSolidPixel(short width, short height, short min, short max)
{
return (short)(height/2);
}
public override short GetLeftSolidPixel(short width, short height, short min, short max)
{
return (max < height / 2 ? (short)0 : short.MaxValue);
}
public override short GetRightSolidPixel(short width, short height, short min, short max)
{
return (max < height / 2 ? (short)(width-1) : short.MaxValue);
}
}