Game engine, C++,SDL (I'm new.)
Moderator: Coders of Rage
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: Game engine, C++,SDL (I'm new.)
...moving to programming discussion for the 999th time.
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: Game engine, C++,SDL (I'm new.)
Sorry Falco,
I wasn't quite sure where to put it. I'm new to the forum.
Anyhow, I did figure out a way to make tiles.
Thank you,
-Benjamin
I wasn't quite sure where to put it. I'm new to the forum.
Anyhow, I did figure out a way to make tiles.
Thank you,
-Benjamin
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: Game engine, C++,SDL (I'm new.)
Is Game Development more for general creative issues?
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: Game engine, C++,SDL (I'm new.)
Exactly. It's about a game as a whole or the process as a whole. It's more about a product. If you make a topic talking specifically about art/music, it gets moved there. If you make a topic talking specifically about programming, it gets moved here.Benjamin100 wrote:Is Game Development more for general creative issues?
It's cool. It's not like 50 other people don't do it too. I'm just feeling more anal about enforcing it lately. And honestly, you'll get way more feedback about things like this in programming discussion.
edit: Oh wow, and the OP's first sentence was "I don't know where to put this." I didn't mean to come off as a dick about it. My bad.
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: Game engine, C++,SDL (I'm new.)
Lol. It's fine Falco. I bet you have a lot of work on your hands.
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: Game engine, C++,SDL (I'm new.)
Okay. This time I don't think I'm at all able to figure out the answer by myself...
I have a sprite for a selected tile...
And sprites with transparent backgrounds...
all sprites on same sheet, just changing source.
But when I select a tile and apply an image tile from the side of the screen, in its transparent background I see the selected tile image.
Any idea why this is?
Should I show you some of the code?
It basically changes the type of tile of the selected tile, which when I run an updating function through a loop, changes the source x,y to the source of the tile type's image.
Does that make sense? Does it seem like that is a bad way of doing things? It all seemed to work fine until I put a transparent background for the tile image in, and now I ee the old selected tile image around it.(Selected being a type of tile.)
Is there anything in that that stands out as possibly causing a problem?
Thanks,
-Benjamin
I have a sprite for a selected tile...
And sprites with transparent backgrounds...
all sprites on same sheet, just changing source.
But when I select a tile and apply an image tile from the side of the screen, in its transparent background I see the selected tile image.
Any idea why this is?
Should I show you some of the code?
It basically changes the type of tile of the selected tile, which when I run an updating function through a loop, changes the source x,y to the source of the tile type's image.
Does that make sense? Does it seem like that is a bad way of doing things? It all seemed to work fine until I put a transparent background for the tile image in, and now I ee the old selected tile image around it.(Selected being a type of tile.)
Is there anything in that that stands out as possibly causing a problem?
Thanks,
-Benjamin
-
- Chaos Rift Junior
- Posts: 345
- Joined: Tue Jan 12, 2010 7:23 pm
- Favorite Gaming Platforms: PC - Windows 7
- Programming Language of Choice: c++;haxe
- Contact:
Re: Game engine, C++,SDL (I'm new.)
I've read through this four times and still can't understand what you're trying to say. Help us help you, show some code, show a screenshot of whats going on, even show the sprite sheet.
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: Game engine, C++,SDL (I'm new.)
Well there is a LOT of code, and I think it would take you quite a while to read it all.
tile class;(of which there are a couple arrays, one being tiles types to choose from, the other being tiles on the screen to select and change with the previously mentioned array of tiles.)
the function in tile class that changes the "version" of the tile(or tile's type.);
"version" is for each tile "on the board", if you will, and when the update function is run, it is supposed to give them the image source of that version's image.
I seem unable to get the image up, but it is 50x50 for each tile,
So my problem is that when it changes version to the tree top, which has transparency, in the transparent region I see the "selected tile" image.
It is as if it keeps drawing the selected tile image below the tree top image. (Please note this is not dealing with layers yet. I plan to move the trees to another layer, but I am currently testing things out with just one layer.)
This is in my loop;
If there is something here that you think is problematic, please show it to me. If you think you would need to see more, please let me know.
Thank you,
-Benjamin
tile class;(of which there are a couple arrays, one being tiles types to choose from, the other being tiles on the screen to select and change with the previously mentioned array of tiles.)
the function in tile class that changes the "version" of the tile(or tile's type.);
Code: Select all
int update_version()
{
if(version==0) //blank tile.
{
source.x=0;
source.y=0;
source.w=50;
source.h=50;
}
if(version==1) //selected tile
{
source.x=50;
source.y=0;
source.w=50;
source.h=50;
}
if(version==2) //tree top.
{
set_source(0,50);
}
if(version==3) //tree bottom.
{
set_source(0,100);
}
if(version==4) //grass.
{
set_source(50,50);
}
}
I seem unable to get the image up, but it is 50x50 for each tile,
So my problem is that when it changes version to the tree top, which has transparency, in the transparent region I see the "selected tile" image.
It is as if it keeps drawing the selected tile image below the tree top image. (Please note this is not dealing with layers yet. I plan to move the trees to another layer, but I am currently testing things out with just one layer.)
This is in my loop;
Code: Select all
for(int l=0;l<140;l++) //loop for each tile.
{
total_tiles[l].update_version();
draw_it(screen,total_tiles[l].sprite,total_tiles[l].source,total_tiles[l].location); //Draw_it only draws one at a time.
SDL_Flip(screen); //Draws each tile.
}
Thank you,
-Benjamin
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: Game engine, C++,SDL (I'm new.)
It appears some of my comments in my code are out of place, but I'm sure you could tell if/where they are.
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: Game engine, C++,SDL (I'm new.)
Oh, and "set_source" is just for x and y, since I realized the others were staying 50x50, as that is to be the size of every tile.
-
- Chaos Rift Junior
- Posts: 345
- Joined: Tue Jan 12, 2010 7:23 pm
- Favorite Gaming Platforms: PC - Windows 7
- Programming Language of Choice: c++;haxe
- Contact:
Re: Game engine, C++,SDL (I'm new.)
Just a few tips that will (probably) provide cleaner code and faster too. You can safely ignore what I'm doing here for now if you want, but it is something you'll want to learn one day.
It's also really odd to have tiles that are 50x50. Almost always, sprites are a power of 2, and have the same dimensions, ie, 32x32, 64x64, 128x128. The reason for this has to do with binary and that it's simply alot faster to process these figures when it comes to hardware acceleration. I'm not so sure if this applies to software CPU blitting however. I won't go into why this is the case, just that when it comes to using DX/OGL, its faster by a long shot. Older graphics cards won't even render textures if they aren't a power of 2.
SDL_Flip(screen); //Draws each tile.
um..... what? You're flipping the buffers each time you draw a single tile? Maybe that should be outside the for loop. It should (usually) be the last thing the graphics engine does per frame, or atleast, the last drawing call. I don't know what the exact code you should be using as I don't use SDL, but that's just wrong. We all make mistakes like this from time to time.
Code: Select all
//Don't forget, you can always wrap this in a namespace as to not pollute this scope!
enum tileType {
Blank,
Selected,
TreeTop,
TreeBottom,
Grass
};
int update_version()
{
//this is just a guess, but i assume that all tiles are 50x50. If so, you can safely put this somewhere else
source.w=50;
source.h=50;
switch(version)
{
case Blank:
{
source.x=0;
source.y=0;
}
case Selected:
{
source.x=50;
source.y=0;
}
case TreeTop:
set_source(0,50);
case TreeBottom:
set_source(0,100);
case Grass:
set_source(50,50);
}
}
Code: Select all
for(int l=0;l<140;l++) //loop for each tile.
{
total_tiles[l].update_version();
draw_it(screen,total_tiles[l].sprite,total_tiles[l].source,total_tiles[l].location); //Draw_it only draws one at a time.
SDL_Flip(screen); //Draws each tile.
}
um..... what? You're flipping the buffers each time you draw a single tile? Maybe that should be outside the for loop. It should (usually) be the last thing the graphics engine does per frame, or atleast, the last drawing call. I don't know what the exact code you should be using as I don't use SDL, but that's just wrong. We all make mistakes like this from time to time.
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: Game engine, C++,SDL (I'm new.)
Okay.
Well I put the SDL_Flip outside the loop now.
It does seem to be running a lot faster.
(I was wondering why it was so slow.) Thanks. I should have thought to try that myself.
Any idea why I still see the selected tile type image behind the transparent part of the tree image when it is applied?
Thank you,
-Benjamin
Well I put the SDL_Flip outside the loop now.
It does seem to be running a lot faster.
(I was wondering why it was so slow.) Thanks. I should have thought to try that myself.
Any idea why I still see the selected tile type image behind the transparent part of the tree image when it is applied?
Thank you,
-Benjamin
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: Game engine, C++,SDL (I'm new.)
LOL!
Fill Rect!
I JUST thought of it!
LOL. I feel stupid. I hope I'm not the only one who makes such obvious mistakes.
-Benjamin
Fill Rect!
I JUST thought of it!
LOL. I feel stupid. I hope I'm not the only one who makes such obvious mistakes.
-Benjamin
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: Game engine, C++,SDL (I'm new.)
Yup. You need to clear the screen before you start drawing transparent images, or it will simply draw over what is already there. This isn't necessary if you are always drawing enough to replace every pixel with a new one.Benjamin100 wrote:LOL!
Fill Rect!
I JUST thought of it!
LOL. I feel stupid. I hope I'm not the only one who makes such obvious mistakes.
-Benjamin
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: Game engine, C++,SDL (I'm new.)
I think I didn't notice before because all the tiles were the same width and height, and hadn't been made transparent yet.