Android - V10 release candidate

Previous topic - Next topic

Xaron

Quote from: MrTAToad on 2011-May-02
GETDESKTOPSIZE seems to work (although I dont know yet whether the values change depending on orientation) - you would then be able to centre using that as long as you know how big your play area is.

Maybe I'm too stupid but do you have some lines of code how to translate a screen in x and y direction? Is there a way to change the transformation matrices in GLBasic?

Ian Price

Something like this -

Code (glbasic) Select

FUNCTION centre:

LOCAL actual_width, actual_height
LOCAL screen_width, screen_height

screen_width=100
screen_height=200

GETSCREENSIZE actual_width, actual_height

LOCAL xpos, ypos

xpos=(actual_width-screen_width)/2
ypos=(actual_height-screen_height)/2

WHILE TRUE

DRAWRECT xpos,ypos,screen_width, screen_height,RGB(255,0,0)

SHOWSCREEN

WEND

ENDFUNCTION


Obviously this is a simple function to draw a square at the centre of any sized screen (that's bigger than the square). But the same principal would apply to a drawn screen.
I came. I saw. I played.

MrTAToad

Although it might be best to use GETDESKTOPSIZE  :)

Slydog

I haven't read all 8 pages of this thread, so I may be missing the point here.
If you want a game ALWAYS centered and don't want to draw the game in the top-left corner and then move it later, why not program all your routines to have a center of (0,0) for the middle of the screen, then adjust the actual offset later.

Something like:
Code (glbasic) Select
TYPE TVector
  x
  y
ENDTYPE

GLOBAL _center AS TVector  // 'Center' of screen
GLOBAL _screen AS TVector // Screen dimensions

// Do once at program start, or screen resize or orientation change
GETDESKTOPSIZE _screen.x, _screen.y
_center.x = _screen.x / 2.0
_center.y = _screen.y / 2.0

...

LOCAL object_pos AS TVector

// centered sprite
object_pos.x = 0
object_pos.y = 0
DrawSpriteCentered(1, object_pos)

// sprite 100 pixels left of center, 50 pixels below center
object_pos.x = -100
object_pos.y = 50
DrawSpriteCentered(1, object_pos)

...

FUNCTION DrawSpriteCentered%: sprite_id%, pos AS TVector
  LOCAL vc AS TVector
  vc = ConvertCenter(pos)
  DRAWSPRITE sprite_id, vc.x, vc.y
ENDFUNCTION

FUNCTION ConvertCenter AS TVector: xy AS TVector
  LOCAL v AS TVector
  v.x = _center.x + xy.x
  v.y = _center.y + xy.y
  RETURN v
ENDFUNCTION


Then no matter what screen size you have, the game will always be centered, with blank borders depending on the difference.
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Ian Price

Quote from: MrTAToad on 2011-May-02
Although it might be best to use GETDESKTOPSIZE  :)

That's what I meant. D'oh. The code should still be the same though.
I came. I saw. I played.

ampos

Quote from: Xaron on 2011-May-02
Quote from: MrTAToad on 2011-May-02
There isn't a way of centring the screen automatically - of course, if you knew the screen resolution, you could do it yourself.

Getting the screen resolution is not the problem but how do I shift the whole screen using GLBasic?

If you create a viewport, all the draw will be shifted. The 0,0 coord is the 0,0 of the viewport not the screen. I don't know it was intended that way by Gernot, but this is how it works.
check my web and/or my blog :D
http://diniplay.blogspot.com (devblog)
http://www.ampostata.org
http://ampostata.blogspot.com
I own PC-Win, MacBook 13", iPhone 3G/3GS/4G and iPAC-WinCE

Kitty Hello

Yes, that's how Viewport is designed to be.
Also, you could render into an offscreen (CREATESCREEN) and paste that centered. With the offscreen surface you might even get better compatibility of the GRAB... commands.

Xaron

Thanks for your help guys, will dig deeper into this! :)

Does this has an effect on LOADBMP as well?

Kitty Hello

Yes. When you render offscreen, you should use loadsprite/drawsprite instead of loadbmp.

matchy

Quote from: Xaron on 2011-May-02
LOL... Alright, why not.  :whistle:

Thanks! :)

Now how does that explain the why there's no colour on the emulator?  :zzz:

Kitty Hello

The emulator has just the very very basic features emulated I think.

If you want coloured lines, use a 1 pixel polyvector with a coloured texture. That's also a lot faster.

Dabz

Quote
Now how does that explain the why there's no colour on the emulator

As far as I know, anything the emulator spits out shouldnt be taken as gospel, also, GLBasic isnt the only software I've used for Android that goes a little wobbly in the emulator, Libgdx suffers from quiffiness too, but, as far as I can see, both work fine (Within reason for GLBasic as its in beta) on an actual device.

Dabz

MrTAToad

Its pretty stable really - which is good!

Kitty Hello

OK, new beta SDK is online.
http://wwww.glbasic.com/beta/glbasic_sdk.exe

Fixes:
Code (glbasic) Select

// New command:
//    SOCK_GETREMOTEIP, SOCK_GETREMOTEPORT
//    SOCK_SETBLOCKING
//    X_GETMATRIX
//
// Editor:
//    New function File/Project/Clean up
//    that cleans out build files.
//    User keywords must be 2 characters long at least now.
//    Icons must be transparent PNG for transparency now.
//    Icons are scaled using bicubic filter -> excellent quality.
//    gbas/gbap files have different icons now.
//    Mac-Icons are generates from the icon.png file.
//
//    Project options -> Version number is available.
//    You can query it with PLATFORMINFO$("VERSION").
//
//    All platforms except iPhone built into the .app directory.
//
// Core:
//    INKEY$ works much better and buffers multiple
//    key presses druing one showscreen cycle (up to 16).
//    INKEY$/INPUT$ returned \r instead of \n. Bug is fixed.
//
//    URLENCODE$/URLDECODE$ caused wrong output with
//    codes>127. It will be converted ISO 8859-1 to UTF-8 first
//    so php can properly interact with GLBasic now.
//
//    Shoebox leaked memory.
//
//    CONSTANT yielded compiler errors (assign to const object).
//
//    GRABSPRITE id,0,0,0,0 frees the memory. Was a bad leak.
//
// Compiler:
//    Nested ?IFDEF might have caused trouble.
//    ?DEFINE always was triggered.
//    2-pass-compiler implemented. GLOBAL declarations
//    from other files are known in stage 2 now.
//    This allows:
//    INC foo.bar; TYPE Tfoo; bar; ENDTYPE; GLOBAL foo AS Tfoo
//
// iPhone:
//    SLEEP is working properly now.
//
// Pandora:
//    GLBasic builds a full featured .pnd package for you.
//    The screen size is not fixed anymore, allowing it to run
//    on OMAP-3 devices as well.
//
// WebOS:
//    appinfo.json is filled with version number and proper strings.
//
// Android:
//    possible crash at startup fixed.
//    Fix with spaces in path (GLBasic installation or project path)


Dabz

Wow, nice update... Good work Kitty! :D

Dabz