Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Drawing only a part of a sprite into a screen area

Author
Message
Alduce
23
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 10th Apr 2010 13:36 Edited at: 10th Apr 2010 13:37
Hello all again. Maybe in my previous post i was not too clear.

I would to have an area in witch i can see my sprite but this area is little than my sprites so i will can watch only a part of my sprite.

Is possible?

Example:
My sprite is 1500x500 pixels, i would this sprite is visible ONLY in a little area on the screen, for example an area of 300x200 pixels.
So when my sprites is in the area you can see only the part of the sprite in the area! (SEE PIC)

It's possible?
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 10th Apr 2010 14:00
Yup, it's actually very easy and very powerful.

SET SPRITE TEXTURE COORD Spr,v,uvx#,uvy#

With v being 0 to 3 for each corner vertex. Best to just experiment to figure out which corner is which. I use this technique all the time, for tile sheets, bitmap fonts, scrolling etc.


Health, Ammo, and bacon and eggs!
Alduce
23
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 10th Apr 2010 14:09 Edited at: 10th Apr 2010 14:10
AH ok! but..
the uvx# and uvy# are float values from 0.0 to 1.0.. i don't understand that! I think that i need some coords to set my DRAW AREA!
(Left, Top, Right, Bottom)

And in add, i need to use this command for each corner vertex? or just to put 0?

Thanx!!
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 10th Apr 2010 14:24
Yeah, if you were showing the whole image, the values would be like 0.0,0.0 - 1.0,0.0 - 0.0,1.0 - 1.0,1.0

The thing is that the values have to be 0.0-1.0 floats, because that way you can change the resolution of the image and not have to change anything. So what I do is divide the X coordinate by the image width, and the Y by the image height, and that returns the UV coordinates to use.


Health, Ammo, and bacon and eggs!
Alduce
23
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 10th Apr 2010 14:34 Edited at: 10th Apr 2010 14:35
mmm ok, then, for obtain the coords in which i can see my sprite i have to obtain the UV coordinates (using the matematical operations you providing).

Ok but one time i had obtained my UV coords so i need to use this command for every corner vertex? or just using 0?
(i ask all that 'cause i can't use DBpro now )

EXAMPLE1:
SET SPRITE TEXTURE COORD Spr,0,uvx#,uvy#
SET SPRITE TEXTURE COORD Spr,1,uvx#,uvy#
SET SPRITE TEXTURE COORD Spr,2,uvx#,uvy#
SET SPRITE TEXTURE COORD Spr,3,uvx#,uvy#

OR EXAMPLE2 :
SET SPRITE TEXTURE COORD Spr,0,uvx#,uvy#

??
And if i have to use the command for each vertex corners (EXAMPLE1) so i have to change my UV matematical operation for each times i use the command?
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 10th Apr 2010 16:07
Your right with example 1. What I tend to do is work out 2 sets of UV coords, then set them for each vertex.

One sec, I'll make a little example for you...


Health, Ammo, and bacon and eggs!
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 10th Apr 2010 16:20
Ok, so once you make your sprite, pass the pixel coordinates to this function:



So if you make sprite 1 with your image 1:



This would make the sprite start at 100,100 for a 300x200 area.


Health, Ammo, and bacon and eggs!
Alduce
23
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 10th Apr 2010 17:53 Edited at: 10th Apr 2010 17:55
Very thanks for your exemples VanB! later I will be able to try it on my pc and I will make to know you the result! For now again thank you for the help!
Alduce
23
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 10th Apr 2010 22:22 Edited at: 10th Apr 2010 22:26
Ok VanB, i tested your code and it work!
But i have a little collateral problem..

My objective is that i can move my sprite left and right as you can see in the attached pic and to mantain the DRAW AREA in the original position (static position, like a window in my screen and i can see the panorama (my sprite)moving outside).

I try to change the call of your function like in these examples :




But nothing!! the effects of both examples are ilarius with the DRAW AREA moving with the sprites or just moving the DRAW AREA without sprite....

I just would to have my sprite moving to left and right and the DRAW AREA static on the screen.. HELP!
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 10th Apr 2010 23:30


That should let you scroll the sprite UV.


Health, Ammo, and bacon and eggs!
Alduce
23
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 10th Apr 2010 23:43
Great!! Thank you very much for your help VanB! Now i can continue in my code!!

Login to post a reply

Server time is: 2026-07-26 17:37:14
Your offset time is: 2026-07-26 17:37:14