## News:

*NEW* Current Version on STEAM16.793

Webchat:
Visit the chat

## Sprite positioning relative to screen size

#### random

Hi all,

I just started learning GLBasic.
I'm probably jumping ahead, but I have this question that is really nagging me.

Is there a way to drawsprite relative to the position of the screen and not by the position of pixel?

The way I'm doing it right now is to use GETSCREENSIZE,
and according to the screensize, the sprite would be adjusted by +x, +y, but this is not very effective...

Help appreciated

#### Kitty Hello

I think he means relative is from 0.0 to 1.0 in screen sizes.
No, there's no such thing. You should introduce a factor:

GETSCREENSIZE sx, sy
GLOBAL scale = 1.0 / sx

DRAWSPRITE num, x*scale, y*scale

#### Hemlos

#2
Welcome to GLBasic, random.
Most excellent question.

I have just came up with an algorithm(yesterday) to move sprites relative to the screensize:
This will handle movement on any speed graphics card, the same velocity/sec.

UnitSizePerFrame = (ScreenSizeY / 2) * 0.001 * GETTIMER()
VelocityX = 1.0
VectorX = VectorX + UnitSizePerFrame * VelocityX

UnitSizePerFrame is the movement size of the sprite, per frame, relative to 1.0 being a movment rate of half the screen height per second. So, if the Velocity were to be 2.0 it would move the full height of the screen in one second. Of course, you can incorporate COS() and SIN() to direct the angle of velocity X and Y.

I choose half the screen height, but you can pick any relative size to factor in....
This method of movement is needed(not limited to) for bullet movment.
Its great for ensure your game will have objects moving the same speed on any computer.
HOWEVER....for MMO Online games, The movment must be relative to some prefixed size.
For instance; you must preset the ScreenY to be a fixed number regardless of screensize, or people with large screens will move faster relative to the world coordinates.

I spent a week coming up with this algorithm, now i can get some sleep!

Bing ChatGpt is pretty smart