Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Bikonja

Member Since 02 Sep 2007
Offline Last Active Mar 02 2013 06:36 AM

Posts I've Made

In Topic: 2D isometric picking problem

04 December 2012 - 01:13 AM

Thanks for the math!
However it's not working. It selectes only the tile that would be 0,0 in the original system (the non rotated, top view) and it does so for about width/2 to the left and height/2 above. This made me realize though that I failed to mention my coordinate system (XNA) has it's (0,0) at the top left, not the bottom left of the window.

Yesterday I've tried thinking up some formulas, but to no avail. I was sure this would be correct, but it doesn't work for some reason... I'll have to try again after work..

x = mX / TileWidth + (mY / TileHeight / 2 - maxX / 2) * TileWidth
y = mY / TileHeight + (mX / TileWidth / 2 - maxY / 2) * TileHeight

where
mX is the mouse X position, offsetted by the X drawing offset
mX is the mouse Y position, offsetted by the Y drawing offset
maxX is the number of virtual tiles on X axis
maxY is the number of virtual tiles on Y axis

what virtual tiles means is, the bounding rectangle of a drawn tile, divided by 2, by an axis is in the non-rotated top view, not the isometric view.

Ofcourse, it should work only for that virtual tile and then I could use a color map to determine which exact tile is selected, but even without a color map, I can see this does not work.

In Topic: [SDL] Help with keyboard input and sprite movement

03 December 2012 - 01:38 PM

You need to draw your scene every frame, not just draw it once in it's first state and then update state, but not drawing.
Place your drawing code inside the while loop (don't have experience with SDL so can't really say if within SDL_PollEvent while or (!done) while but I would say you should put your drawing code inside the !done while.

In Topic: 2D isometric picking problem

03 December 2012 - 04:26 AM

@MachinaX
What do you mean by "there shouldn't be any maths happening between the x and y mouse coordinates"?
What you're saying is this?
public Point? ScreenToIso(int screenX, int screenY, int tileHeight, int offsetX, int offsetY)
{
	    Point? newPoint = null;
	    int nX = -1;
	    int nY = -1;
	    int tX = screenX - offsetX;
	    int tY = screenY - offsetY;
	    nX = Math.Round((double)tX / (double)tileHeight / (double)tileWidth);
	    nX = Math.Round((double)tY / (double)tileHeight / (double)tileWidth);
	    newPoint = new Point(nX, nY);
	    return newPoint;
}

If this code is what you're saying, then it doesn't work (I mean, after fixing small, insignificant for this, errors like nX being in while Math.Round returns decimal). It selects something way further than under mouse cursor (out of screen). But the code doesn't make sense to me either - why would I divide with tileHeight/tileWidth?
I'm also not sure what you mean by the sentence "If the tiles have moved,...", do you mean the -offset I have in tX and tY variables?
As for the transparent parts, I'll implement a color map for that, but first I want to get to a stage where the rest actually works.

@AticAtac
I couldn't get your code to draw properly so I didn't try your picking code. I'm probably missing something, again... But I'm at work now so not much time to play with this. When I get home I'll play around more a bit.

Thank you to you both for your contributions.

In Topic: Get pixel color with GetBitmapBits

05 September 2007 - 10:18 PM

Does noone know this? Please, if someone does know this, please try explaining it to me so I understand and therefore can make this code work

In Topic: Get pixel color with GetBitmapBits

03 September 2007 - 09:18 AM

I am refreshing this topic since it has already fallen to the second page and no replies yet...

Please, if someone knows this stuff, help me understand it!

PARTNERS