Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8782649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:37:13+00:00 2026-06-13T20:37:13+00:00

I’m building what will be a very information-heavy game screen, and, with even just

  • 0

I’m building what will be a very information-heavy game screen, and, with even just the first bit of code, which displays a number of planets on the screen, my code is starting to look a bit messy/complicated.

I’d also like to hide some of it from the uses looking at “view source”, if posible, but that’s a secondary concern.

Basically, the code below draws X planets at various Absolute positions on the screen, and provides a mouseover tooltip for each planet.

There simply must be a “nicer” and/or more efficient way to do this? I’d appreciate any tips, basically.

My main reason for being concerned is that the Qtip2 tooltips are going to become a lot more complex, and there’ll be all sorts of player info added to the page, and a couple of chat/news/info boxes. I don’t want to start with spaghetti code, when I’ve still got the main course to deliver to the page!

I think my main concern is the masses of script tags I’ll be generating. At the rate of one per tooltip that I add to the page. The “echo”s for the planet images (and their labels) are surely unavoidable….I don’t really know, I’;m a bit new to this.

<!-- File: /app/View/Games/main.ctp -->
<?php

    echo $this->Html->script('jquery-1.8.2.min');
    echo $this->Html->script('jquery.qtip');

    $game = $this->Session->read('Game');
?>
<?php
    foreach ($game['Planet'] as $planet) {
        echo $this->Html->image('../img/planet/' . $planet['planet_image_file'] .'.png', array('class' => 'planet_img planet_' . $planet['id'], 'id' => 'planet_' . $planet['id'], 'alt' => $planet['planet_name'], 'style' => 'position:absolute;top:' . $planet['y_position'] . 'px;left:' . $planet['x_position'] . 'px;'));
        echo '<script>$(\'.planet_' . $planet['id'] . '\').qtip({content: \'' . $planet['planet_name'] . '\'});</script>';
        echo '<label for="' . $planet['planet_name'] . $planet['id'] . '" style="position:absolute;top:' . ($planet['y_position'] - 20) . 'px;left:' . $planet['x_position'] . 'px;">' . $planet['planet_name'] . '</label>';
    }
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:37:15+00:00Added an answer on June 13, 2026 at 8:37 pm
    1. Use stylesheets instead of all those inline styles. If you add styles dynamically, you could always have a <style> element in the header, to which you dynamically append css definitions as needed.

    2. Use image sprites to help with optimisation. This is more appropriate for manipulating background images, rather than inline images, but for the performance gains it offers, it may be worth it.

      You would need elements using css image backgrounds, not inline images, but the DOM can be just as simple.

    3. Instead of calling a bunch of scripts to add the qtip thingy, have the information qtip needs as a data attribute for each of these elements, and have one function, in an external js file, which loops through the elements and does the qtip stuff based on the data attribute.

      foreach ($game[‘Planet’] as $planet) {
      echo $this->Html->image(‘../img/planet/’ . $planet[‘planet_image_file’] .’.png’, array(‘class’ => ‘planet_img planet_’ . $planet[‘id’], ‘id’ => ‘planet_’ . $planet[‘id’], ‘alt’ => $planet[‘planet_name’], ‘data-planet-name’ => $planet[‘planet_name’]));
      echo ” . $planet[‘planet_name’] . ”;
      }

    jQuery

    $('.planet_img').each(function(){
      $(this).qtip({content: $(this).data('planet-name')});
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have this code to decode numeric html entities to the UTF8 equivalent character.
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.