Adding color to my rubik's cube

0 favourites
  • 15 posts
From the Asset Store
HSV RGB Color Picker and Converter for Construct 3
  • Hi again,

    I've been hard at work on my Rubik's Cube program (capx here:, and now that i've got the cube all constructed and rotating/flipping, i've run into another snag.

    Basically, i'm trying to add color to the squares. Each cube square is a text box object. Right now, they're numbered for debugging purposes. I'd rather not just have the text say "Green" or "Red" or whatever, so i was thinking of using a sprite object.

    The question i have is this: is there a way to search all the text boxes on the current layout for a value? I was thinking that i could perform that search, then somehow pin the colored sprite objects to text boxes containing certain numbers. For example, the number "1" would have a red sprite attached to it- and that sprite would position itself on top of whatever textbox had the "1" in it.

    Anyone know of any way to do this? Also, am I thinking about this completely wrong? Is there an easier way to do it? I thought of using arrays, but i'm not sure how that would work exactly

  • wow, that's a lot of arrays, i doubt why it's lagging, i was thinking we should to use other workaround...

  • There's something missing in your rubik's cube: when you rotate the top row the top face should rotate as well (:

    Also, I'm pretty sure the whole thing is doable with one 3D array (maybe another one for swapping values, but it should be doable in one array using unused offseted indexes). Also it's pretty challenging. Don't have time to try though.

  • wow, that's a lot of arrays, i doubt why it's lagging, i was thinking we should to use other workaround...

    Does it lag for you? On my comp it's been fine so far, but i don't doubt that all those arrays are taxing.

    and Yann- thanks for that. I'll look into it. I'm not an expert with the cube, so there's probably some issues with it still lol

  • How adorable. I thought about making this very program. I've only learned to solve the damn cube in the past couple months. Bought one even.

    Trouble with Construct2/making this (the set of all-of-that-combined) is that it's not really 3d. 2D cube pic, background panels showing the "unseen" side/arrangement, color swaps for an unmoving cube? Easy enough. But you get no joyful motions of turning the cube, no free rotations of the cube where it just spins around and you marvel at it, blah. Not saying the 2d just-color-moving notion couldn't make a lovely tutorial to teach others to solve cubes, or whatever... But as to solving one? If the one newly on my desk were in use, I still have a touch based 3d fully movable/rotatable ipod cube.

    Plus, can we get function-writing in construct? Seems a pain reuse the same notions of code. But, reusing it for EVERY button by rewriting it for EVERY button, why not an array that swaps values? Yeah, won't be super-intuitive to code, wouldn't be for me at least, swap this with that with the other type stuff. 6 colors on each of 6 sides, 36 things to know. 3x3x3 array, wow, that's 9x3, 27, so hopefully you won't make the array badly. 3x3x3 *cubes*, but the cubes have more than one side/blah. The model I've pulled out my -- mind -- in a few secs of thought? I'm thinking 3x3 faces, 6 of them, so why not have a 3x3x6 array? But then you'll have to make very-specific and very-seemingly-non-intuitive calls -- (0,2,0), (1,2,0), (2,2,0) rotate to the right, which if that's face one those prior locations get moved to (0,2,1), (1,2,1), (2, 2, 1) or such. Assuming that in your mind is face one, or even that "turning right" meant clockwise, blah.

    A working cube is very possible. 3x3x6 array seems best tho, not 3x3x3, to me at least. Swapping some locations with others is gonna get tedious/require lots of checking. And once it works? The cube still doesn't move. Or you could add animations -- but even at perfect(ly bland) angles where the rotation animation worked (looked right) for all tiers -- You have any of 6 colors, next to any of 6, next to any of 6 rotating *on one side* -- and what about the side you're moving away? We're already at 150+ animations. I dig photoshop, actions, automated scripts, blah. I'm not gonna make that many animations. Hell, adding a few different-angle asteroids to my asteroid game, 30ish frames each, the game quit loading 100% of the time. I'd click preview and screw around rerereclicking -- 2 mins later I might see my preview. Nah, ripped all that out. I'll add it in at the end maybe. When I don't wanna preview more basic stuff. Point -- too many frames bogs construct, it's seemed. And that 150? Was how many combinations. My bad. But if 10 frames per animation? Now we're at 1500...

    Basically Rubik didn't seem like it was the "right" thing for this environment. Last night I made a random number generator gamer-friends could use -- 6 rolls of 2d6+6 for AD&D type stats, or whatever. Got my first real taste of arrays. Kept wondering where the hell the "sum of array row/column" feature was. Wondered why I can do foreach style loops on X, XY, or XYZ -- but why not *just Y*? -- it does what it does. Show me ONE damn spreadsheet table where you can't *super-easily* get the value of Y axis data... Suffice, no, I *did* get it working -- but I also noticed if I just closed construct 2 and went into full-bore PHP writing on notepad I'd have gotten a lot more done, faster. Yeah, the layout moves quicker in construct, etc, but I can write and reuse functions, do the math with lots more built-in functions via PHP, etc... Point, some things just lend themselves better to certain environments. Rubik seemed tedious and unrewarding. That said, prove it wrong/good luck.

  • Wight

    To get the values the nth row in a 2D array

    It's just simply :

    global number n=3 //check the third row
    + foreach X element
      Set current_value to Array.At(Array.CurX,n)

    For the fact that we can't get a 3D cube, I think Yanen was well aware of that. There are however some solutions to fake 3D in construct2 (check r0j0hound's raycasting example). I think for a rubik's cube there's some solution using non-uniform scaling to fake the rotation.

    As for writing function, rex made a function plugin that works super well, I'm using it on a level editor I'm making. Ashley will probably make an official one at some point but for now it's good enough.

    Anyway, for now it looks more like you're better in php than in construct2.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Maybe your algorithm does the whole cube, I don't see it. I merely said it would be tedious and cumbersome, you respond with a line that -- doesn't seem to prove to me it does the whole cube. And it seems like altering/reusing that line over and over -- would get tedious. And if we model it how *I* would model it, each side facing me would have the horizontal side be X, 0-2, or 1-3, or whatever. Height would be Y, same ranges. And the cube on the table, I solve white first (just over my nickname, nothing deeper), at the bottom. But I'd call the front face 1, go clockwise up to 4, top's 5, bottom 6, all as Z-axis arrays. But if I turn the cube to the bottom, and base this all off 1-3 integer counts? I'm moving the middle Y row on the bottom face away from me to the back face -- (2,1,6), (2,2,6), (2,3,6) -- those would all swap with (2,1,3), (2,2,3), (2,3,3). That seems easy. That grid 6 swaps with grid 3, 3 swaps with 5, and 5 swaps with 1 -- that's NOT entirely first-thought obvious. Gotta think thru each motion/make each button carefully. Bet me guy makes at least one bungle over which side is up/etc. But I do think I said "tedious, not impossible" or something. It's just that it's a chore. Hell, I'm happy my first thoughts were to use one array *and* to avoid making a 3x3x3 array -- how many people did that the first time?

    What a sweet thing to say. I think more people should make comments about strangers' abilities with limited personal experience, saying exactly what they already said. Years of PHP/web design, now going into HTML games, however could I possibly have more proficiency with that? I know, I'll get over it, at some point PHP will lose the zillion built in functions it has and the 8-10 notions present in construct2 for array manipulation will be all that's left.

    But since that sounds like a really sad day, I'd still rather my text allow PHP breaks. No lie, I was trying "<BR>" before I'd heard of "newline". I had to drop what I was doing and go hunt-down that (seemingly overly-long) expression, even. And I get why web designers will turn off text's ability to be interpreted, it's a security risk, etc. Being on the server/development side, being able to make tweaks to user input to guard against misuse, One can only figure scirra's not letting me put PHP in over...

    Nevermind. I can't think of a good reason. Even geniuses have limitations sometimes. I figure saying that what doesn't make sense actually does? That must be event 101.

    I stopped at r95 for now, always leery higher versions will change/break things. But on the note of "reason" -- in r97 am I still having to put my global variables in an otherwise-unused (or totally used/never destroyed) sprite called "global" so that they don't cost 1% each of my 100 events? And is it still too costly to have a remotely organized program that doesn't look like crap (ie, are groups still events?)? The PHP authors never did this. But how lovely they were kindly folk wanting an improved world and released their stuff so that the world could use it freely to create joyous derivative works... Like that 80$ game editor program.

    Nope. New to game design. Only met one unsupportive *** so far, even. And the tools are limited with odd workarounds. Unlike PHP, where you could always throw in more pre-written functions, or write your own even. Addons? I admit, haven't bothered, but maybe this function addon would be one I'd never work without once I try it. When I try it. While I see the joy in a program supporting addons, never quite figured why so many people don't expect more from the program, we don't all have whatever addon, and traversing/summing *just Y* has no array function, really? Damn, Construct 2... But yeah, I've only fiddled with Construct 2 for now. Addons take forever to dig thru, sort out, demo, trying is quick, grokking isn't. Hearing of one in particular over others? That lets me target it quicker. Having never installed an addon? I'm not super eager for the headache. Even if once I learn a path it's probably as simple as unzipping there. Feh, I'll look into it, no need to teach. It's just not today's priority, girlfriend over 'n such. Plus she just woke up... So I'm done ranting for now.

    I am curious what you meant by faking rotation thru non uniform scaling. The words are pretty, and offer hope, but I've gotten no vibe of exactly what algorithm you mean. 3 blocks on a row, the right one's 2x the size of the left? -- But it's still not moving. Eh, fine, we're faking it/not moving it. But I'm not sure how that fakes it even. My point, didn't "get" that part of your posting.

  • Wight: what a complex post to go through, I must admit it's a struggle for me. (I'm not a native english-speaker/reader, and so is a fair share of our community)

    For the sake of comprehension and efficiency may I please ask you to shorten your future posts and stick to the subject of the topics.

    From what I grasped, it seemed to me that you went from seeking technical assistance on a precise point through rants about various subjects displaying quite a few misconceptions about the usage of C2 and even perhaps programming in general.

    At some point you ask why you can't put PHP into C2, it's because PHP is a server-side type of script and that C2 produces HTML5 (so JavaScript) games/scripts to be executed in a browser on client's side.

    Those are informations that you can find in the technology entry of C2's manual.

    You can find more informations about JavaScript in the overview entry of C2's SDK.

    May I also advise you to have a good read at this tutorial, especially the part concerning C2.

    It should provide all the good leads and basics for a usage of C2 as it is intended to be used.

    Also, once again I'd like to stress the fact that it would be really nicer if you focused your posts on the subject of the topic.

    It helps keep the forums friendly.

    When one look for technical help on the forums, it makes it more efficient to have only concise and precise posts about the subject.

    Also, beware on the language you use too. We have teenagers (and even younger children) that browse through those topics. Please be nice enough to edit your previous posts and remove any rude language.

    If you want to elaborate on commercial products vs open source products or other topics about life, please consider keeping those posts in the "Open topics" forum.

    Thank you in advance and welcome in the community.

  • Any way, That's my take in the rubik's cube idea


    Need rex's function plugin


    Press SPACE to display face's IDYann2012-07-09 04:58:06

  • Good lord that's an elegant implementation, lol

    Makes me ashamed, because it shows how bad mine really was <img src="smileys/smiley36.gif" border="0" align="middle" />

    Thank you very much for that Yann. It's going to take me a while to go through it, but i'm sure I can glean some knowledge from your events that will help me

  • Yann

    Those rotate functions are intense.

    For a visual effect I was testing an idea to do fake 3d rotation like Fez and this is the result. ... .capx?dl=1


  • R0J0hound

    Hehe! That's what I call an elegant implementation.

    I thought about representing cubes in 3 dimensions but I thought it would be over complicated to handle grouped rotation and local orientation.

    Looks like I was wrong.

  • For a visual effect I was testing an idea to do fake 3d rotation like Fez and this is the result. ... cube2.capx


    A-M-A-Z-I-N-G <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

  • R0J0hound can you please reupload the capx thank!

  • Link updated

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)