Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Drawing a sprite with an origin outside the screen

This thread is locked; no one can reply to it. rss feed Print
Drawing a sprite with an origin outside the screen
Ionising
Member #14,522
August 2012

I was wondering what the best way to draw an image part way outside the screen is? I'd like to do this in order to display only a section of the image to fill in gaps in my isometric engine. I notice when I call al_draw_bitmap with a dx/dy less than zero nothing is displayed even if part of the image should still be visible.

Example of what I am trying to achieve:

http://imgur.com/hUyUk

Elias
Member #358
May 2000

Can you show the code?

--
"Either help out or stop whining" - Evert

Ionising
Member #14,522
August 2012

Screenshots of my test app showing the problem:

http://imgur.com/9rodW

I've wrapped up Allegro into a game library, but drawing the image boils down to one call:

al_draw_bitmap( pImage, nXPositionPx, nYPx, nFlags );

Malinus
Member #11,332
September 2009

I would do something like this (lets say you don't know the size of the bitmap, but it get the -150;-150 coordinate (and the bitmap is bigger then 150x150 of course)):

#SelectExpand
1 2int x = -150; 3int y = -150; 4 5al_draw_bitmap_region(bitmap, fabs(x), fabs(y), al_get_bitmap_width(bitmap)-fabs(x), al_get_bitmap_height(bitmap)-fabs(y), 0, 0, NULL)

I haven't tried it, but it should work ;)

Neil Walker
Member #210
April 2000
avatar

Not exactly related, but seeing as you're playing with isometric stuff here's something you might find interesting...

http://www.servo7.co.uk/iso/masking.aspx

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

Dizzy Egg
Member #10,824
March 2009
avatar

You shouldn't need to chop the image at all, it should display as you would expect. Are you sure you're not using unsigned int for X and Y ???

----------------------------------------------------
Please check out my songs:
https://soundcloud.com/dont-rob-the-machina

weapon_S
Member #7,859
October 2006
avatar

<obvious>Are you really calling al_draw_bitmap directly? I.e. you don't have a condition somewhere that prevents bitmaps with negative values to be drawn? Apply palm to face, if applicable.</obvious>

Go to: