|
Viewing 1 to (9 Total) CSS "background-repeat"-like behaviour |
Total Posts: 25
Joined: May 10, 2012
|
Hi!
I am trying to accomplish a CSS background-repeat like behaviour for a simple child matching game. I've got a 600x600px image that I want to use as a background, but it should repeat over the whole screen.
What I've done so far is:
_source = Assets.getBitmapData ("images/Background.png");
graphics.clear();
graphics.beginBitmapFill(l_source);
graphics.drawRect(0,0,_screenW,_screenH);
But that doesn't seem to do the trick. It seems that after placing the image for the first time, the rest is filled with a 1px-column of the image, that is being stretched.
I could place the bitmaps by myself, calculating the width and height of the stage and so on, but I thought maybe there is another way to do this?
Thanks for your help!
Tags:
Posted on June 14, 2012 at 3:15 AM
|
|
|
Total Posts: 261
Joined: September 08, 2011
|
Re: CSS "background-repeat"-like behaviour
beginBitmapFill has a "repeat" option.
Make sure the images size is a power of two.
Posted on June 14, 2012 at 5:10 AM
|
Total Posts: 25
Joined: May 10, 2012
|
Re: CSS "background-repeat"-like behaviour
Thank you! Didn't find that.
Posted on June 14, 2012 at 6:17 AM
|
Total Posts: 25
Joined: May 10, 2012
|
Re: CSS "background-repeat"-like behaviour
Sorry, to bother again.
I'm still having some problems using this drawRect method.
In my .nmml-file I defined a width and height of 1024x600px (for Playbook actually). But I want it to be resizable and everything adjusts fine, except the "wood board" on the right (you can see in the 2 attached files).
For 1024px width it's fine. When I widen it a little bit it's getting somehow funny until 1280px width, then it's fine again. I know the difference is my image width, but why is it so split-up when between 1024 and 1280?
I am doing this on resize to reposition the gameboard:
graphics.clear();
graphics.beginBitmapFill(image, null, true);
var x:Int = Lib.current.stage.stageWidth-256;
graphics.drawRect(x, 0, 256, Lib.current.stage.stageHeight);
Sorry I didn't develop using flash before, so maybe my understanding of this sprite/graphics thing is a bit wrong.
Posted on June 14, 2012 at 8:06 AM
|
Total Posts: 25
Joined: May 10, 2012
|
Re: CSS "background-repeat"-like behaviour
I think I got it now.
beginBitmapFill fills the entire Screen with these images, as the Sprite is taking the fullscreen space, is that right?
graphics.drawRect then makes a certain part of that Sprite "visible", right?
Thats why it's OK at 1024 and 1280px, but not between.
Posted on June 14, 2012 at 8:17 AM
|
Total Posts: 261
Joined: September 08, 2011
|
Re: CSS "background-repeat"-like behaviour
That's because the patterns origin is always the Display Object's origin and not to the shape you're drawing.
If you container is in (0x0) of the screen, in exact 1024 or 1280 you're lucky because 1024-256 = 256x3 and 1280-256=256x4, so your pattern starts at the right point. But it won't be correct for any other (non multiple of 256) dimensions.
Solution is to move the container to stageWidth-256 and draw at (0,0), or to add a Matrix parameter to translate the drawing.
Posted on June 14, 2012 at 8:23 AM
|
Total Posts: 25
Joined: May 10, 2012
|
Re: CSS "background-repeat"-like behaviour
Thanks, that's what I thought now.
I have another problem, it doesn't relate to the topic, but I don't think it's worth a new one.
Still my matching game for my son.
I have attached a screenshot. Funny thing that happens is when I click the upper left card, the lower right card opens.
I've tried to trace the MouseEvent:
I get this for a click on the upper left card:
GameBoard.hx:103: [MouseEvent type=mouseDown bubbles=true cancelable=false localX=-452 localY=-283 relatedObject=null ctrlKey=false altKey=false shiftKey=false buttonDown=true delta=0] Card 40
and "Card 40" is the card in the lower right place of the GameBoard.
For the other cards the localX and localY are always starting from 0 (from upper left of the card). But the first card is not?
I've got this display list:
Game
|
GameBoard
|
Card, Card, Card and so on
I've positioned the Cards inside the GameBoard, then added the GameBoard to the Game class and reposition this to resize to different screen sizes. I've now just set it to x=0,y=0 for the GameBoard.
What I've thought already is that maybe the clickable area for the cards is not only on the Card-image itself, but also always at the top left of the Game-Sprite? And because the Card in the lower right is the last card added it gets the event? Funny, all other cards are working nicely.
The MouseDown Eventlistener is added on the GameBoard-Sprite, or is that the problem?
It in the GameBoard class checks :
if (Std.is (event.target, Card)) {
...
}
Hope anybody understands and can help me with my problem.
Posted on June 15, 2012 at 10:49 AM
|
Total Posts: 25
Joined: May 10, 2012
|
Re: CSS "background-repeat"-like behaviour
I've just seen, that this doesn't happen with "flash" target. There a click in the upper left of the game board does open the upper left card and also localX and localY are positive numbers.
So maybe it's some mac related problem?
I am currently trying to run this on the iPhone simulator, but can't build the sources in XCode. It seems even though I ran "nme test ... ios -simulator" the compiled output is still for armv6 instead of x86. I.E.
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/g++ -I. -D_CRT_SECURE_NO_DEPRECATE -DHX_UNDEFINE_H -c -O2 -arch armv6 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk -miphoneos-version-min=3.0 -fvisibility=hidden -fno-stack-protector -DIPHONE -DIPHONEOS -DSTATIC_LINK -I/Users/tr/tmp/hxcpp-read-only//include -x c++ -fvisibility-inlines-hidden -frtti /Users/tr/tmp/hxcpp-read-only//src/hx/Hash.cpp -oobj/iphoneos//src/hx/Hash.o
Is that a bug? Shouldn't it be -arch x86?
Posted on June 15, 2012 at 11:35 AM
|
Total Posts: 25
Joined: May 10, 2012
|
Re: CSS "background-repeat"-like behaviour
Not being able to test on iOS, I tested on my Blackberry Playbook, same behaviour as "mac"-target.
Seems only the "flash" target seems to be working right.
By the way I am on latest HXCPP and NME from svn trunk.
Posted on June 15, 2012 at 12:11 PM
|