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.

Dark GDK / How to move a sprite left/right?

Author
Message
Bran flakes91093
16
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 19th Sep 2008 04:45
Uhh this may be a noob question but I am really stuck with this. How do I move the sprite left and right in 2d? I used dbMoveSprite to get it to move up and down, but i cannot figure out how to get the sprite to move left/right! Also, i have another problem besides this. I have a 480x480 bitmap for a backdrop. I loaded it and put in on the screen, but there was that little gap on the right side of the screen. So i tried to resize the window to 480x480 and it scaled the picture down! That gap is still there and the picture is just smaller width-wise. Any way to fix that? Thanks for your time.
Wikaman1
16
Years of Service
User Offline
Joined: 17th Aug 2008
Location: Scotland
Posted: 19th Sep 2008 10:00
You need to rotate it if the user presses the right or left arrow using



then you put in the movement code.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 19th Sep 2008 18:43
Or just use dbSprite() to position it where you want. But you'll need to keep track of it's co-ordinates.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Mista Wilson
16
Years of Service
User Offline
Joined: 27th Aug 2008
Location: Brisbane, Australia
Posted: 19th Sep 2008 18:59
RE: Sprite moving left or right....
there are 2 ways that I think i would try this first.. if using the dbMoveSprite commands... you would need to detect for the input, then once its detected, rotate the sprite 90deg left or right(provided its facing towards the top of the screen, dbMoveSprite will move a sprite FORWARD.. in the direction its facing, so if u want it to move left, rotate it to face left before moving), call dbMoveSprite with whatever params you like, then rotate the sprite back the way it should face... then draw the screen.... essentially you can do whatever you like to the sprites during the game loop, as long as they are where they should be before you draw the screen.... The second way of moving sprites around i would consider would be to simply dbPasteSprite or even use dbSprite() at the X,Y co-ords that i wanted it at in relation to the user input.

RE: The window sizing thing is because the area inside the window is whatever area you specify it to be.. ie 1024x768...1280x1024.. anything you load into that screen is scaled to whatever scale/resolution the screen is using in relation to its actual size... so loading the pic in with a screen at size X,Y and noticing it has a gap... then resizing the screen wont make the gap go away, as anything that is done to the screen, is done to anything that is inside the screen aswell... ie, when you resize the screen, you resize the pics inside it aswell....

If it ain't broke.... DONT FIX IT !!!
Clbembry
17
Years of Service
User Offline
Joined: 10th Dec 2006
Location: Minnesota
Posted: 24th Sep 2008 00:03
Here you go:

yerrel
21
Years of Service
User Offline
Joined: 9th Sep 2003
Location: Planet Earth.. :-)
Posted: 24th Sep 2008 04:22 Edited at: 24th Sep 2008 04:25
The code from Clbembry, is alright too.. but i will give another example that also move down/up, which also checks for screen boundaries.



// Move sprite Left/Right and Up/Down

// Author: Yerrel
// Web-site: www.binary-coder.com

#include "DarkGDK.h"

void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 0 );

// Declare the Start positions for X and Y, position it @ the center of the screen
int pos_x = dbScreenWidth() / 2;
int pos_y = dbScreenHeight() / 2;
int speed = 4;

// Creat a Cube to use as a sprite
dbInk(dbRgb(255, 255, 0),0); // Use yellow color for the cube
dbBox(0, 0, 16, 16); // Draw a cube with size: 16 x 16 pixels
dbGetImage(1, 0, 0, 16, 16); // Grab the box as Image
dbCLS(); // Clear the screen

// our main loop
while ( LoopGDK ( ) )
{
// Move right/left and check screen boundaries
if( dbRightKey() && pos_x < dbScreenWidth()-16)
{
pos_x = pos_x + speed;
}
if( dbLeftKey() && pos_x > 0)
{
pos_x = pos_x - speed;
}

// Move Up/Down and check screen boundaries
if( dbUpKey() && pos_y > 0)
{
pos_y = pos_y - speed;
}
if( dbDownKey() && pos_y < dbScreenHeight()-16)
{
pos_y = pos_y + speed;
}

dbSprite( 1, pos_x, pos_y, 1 );

// update the screen
dbSync ( );
}

// return back to windows
return;
}

MSI K8T NEO-2 F2.0, 8XAGP, 2x512Mb Dual Channel... Dark GDK..... http://www.binary-coder.com

Login to post a reply

Server time is: 2024-09-30 07:11:01
Your offset time is: 2024-09-30 07:11:01