PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

PocketFrog: How to get X and Y position of surfase or rect??

help =)
Surface has no x or y, it's not a complex sprite class.
The only place where you will use x and y - it's when you blit your surface:

Surface * pSurface;
Display * pDisplay = GetDisplay();
pDisplay->Blit(x, y, pSurface, &Rect(xPosOnSurf, yPosOnSurf, SurfWitdth, SurfHeight));

x, y - positions of left top corner of your Surface on screen.
xPosOnSurf, yPosOnSurf - position of left top corner point, so you can "crop" desired rect from current Surface.
SurfWitdth, SurfHeight - dimensions of this rect.

some useful info you can find in rect.h and surface.h
thanks!!!
If you want real sprite animation, you can look this Conan's tutorial:
http://www.sundialsoft.freeserve.co.uk/pocket_frog_Ch4.htm :wink:

P.S. If you want to get answer for some absolutely stupid and simple questions, that you don't want to ask, you can make a search for earlier threads using BIGBEN as an author keyword :lol:
:lol: ok thanks, i've got a lot of stupid questions =))

here is one of them:
------------GAME LOOP--------------
HDC hDC = m_background->GetDC();
RECT rcString1;
rcString1.top = 80;
rcString1.left = 4;
rcString1.right = 260;
rcString1.bottom = 180;
TCHAR* ch;
ch =(unsigned short *) malloc(1);
_itow(stylus_p.x, ch, 10);
DrawText(hDC, ch, 20, &rcString1;, DT_LEFT);
free ch;
-----------------------------------
why this code works only one time - it shows stylus_p.x value which was registred after first click
ch =(unsigned short *) malloc(1);

that only allocs 1 character. So if you write a few characters, you may be overwriting something else.
If you use TCHAR, then use only macro names for functions and _T("") macro for known text.
_itot instead of _itow
This way you can use one code for PC and PPC

------------GAME LOOP--------------
***
TCHAR* ch = new TCHAR[7];;
_itot(stylus_p.x, ch, 10);
DrawText(hDC, ch, 20, &rcString1;, DT_LEFT);
delete[] ch;
-----------------------------------

If you want to copy some text don't forget about + 1 character for null termination:
TCHAR* ch = new TCHAR[_tcslen(SomeCharText) + 1];;

Again you can search in this forum, just use TCHAR as a keyword. :wink: